1 1 00:00:02,650 --> 00:00:04,959 I want to take a quick minute to talk about DNS and 2 2 00:00:04,970 --> 00:00:07,392 Kubernetes. Sometimes we take it for granted in Docker, 3 3 00:00:08,170 --> 00:00:10,689 and Swarm, and Kubernetes, DNS just kind of works. 4 4 00:00:10,990 --> 00:00:13,569 I want to give you some details real quick on what's going 5 5 00:00:13,570 --> 00:00:15,619 on in the background before we keep moving forward. 6 6 00:00:15,780 --> 00:00:18,610 What you've experienced so far is if you're in a container, 7 7 00:00:18,970 --> 00:00:21,999 and you cURL or ping a service name, 8 8 00:00:22,030 --> 00:00:23,309 you get back the response. 9 9 00:00:23,320 --> 00:00:25,839 So, clearly there's a DNS server in there 10 10 00:00:26,290 --> 00:00:29,409 doing something to match services to 11 11 00:00:29,410 --> 00:00:32,590 DNS names. Believe it or not, DNS is optional 12 12 00:00:32,710 --> 00:00:35,409 as a service, or an add on, inside your Kubernetes cluster. 13 13 00:00:35,440 --> 00:00:37,029 But, everyone puts one in there. 14 14 00:00:37,030 --> 00:00:39,490 In fact, when you install it, whether it's kubeadm, or 15 15 00:00:39,730 --> 00:00:41,970 Docker Desktop, or whatever you're using, there's going to 16 16 00:00:42,100 --> 00:00:43,180 be a DNS server in there. 17 17 00:00:43,540 --> 00:00:45,606 Starting with 1.11 Release, CoreDNS 18 18 00:00:47,230 --> 00:00:49,180 is the default. It's sort of the standard. 19 19 00:00:49,390 --> 00:00:52,299 There's a prior one called KubeDNS, which is deprecated at 20 20 00:00:52,300 --> 00:00:55,050 this point, and we should all be using CoreDNS now. 21 21 00:00:55,450 --> 00:00:58,499 What this is known as is DNS-based service discovery. 22 22 00:00:58,540 --> 00:01:00,096 You had it in Docker. You had it in Swarm. 23 23 00:01:00,490 --> 00:01:03,283 Basically, it works the same way in Kubernetes where when 24 24 00:01:03,370 --> 00:01:06,579 you create a service, you get the hostname that matches 25 25 00:01:06,610 --> 00:01:09,109 the service. But, that hostname is part of a larger 26 26 00:01:10,000 --> 00:01:12,069 name, the fully qualified domain name. 27 27 00:01:12,400 --> 00:01:14,250 We didn't get that in Docker or Swarm. 28 28 00:01:14,700 --> 00:01:15,886 They were really just focused on hostnames. 29 29 00:01:16,630 --> 00:01:18,579 With Kubernetes, we get more options, right. 30 30 00:01:18,850 --> 00:01:21,349 So, out-of-the-box, you're just going to be talking 31 31 00:01:22,150 --> 00:01:24,107 from one service to another using the hostname. 32 32 00:01:24,108 --> 00:01:27,129 If you start using namespaces, and we 33 33 00:01:27,130 --> 00:01:28,510 will go through that a little bit later. 34 34 00:01:28,840 --> 00:01:31,599 Think of names spaces as a way to 35 35 00:01:31,840 --> 00:01:34,599 section off all the different parts of different apps 36 36 00:01:35,080 --> 00:01:38,049 into these areas inside the same cluster, that won't 37 37 00:01:38,050 --> 00:01:39,219 really clash with each other. 38 38 00:01:39,580 --> 00:01:42,640 You can't technically create the same pod, or the same 39 39 00:01:42,850 --> 00:01:45,939 service, or the same Deployment, with the same 40 40 00:01:45,940 --> 00:01:48,018 names, in the same namespace. 41 41 00:01:49,030 --> 00:01:51,039 If you create other namespaces, which you 42 42 00:01:52,000 --> 00:01:54,646 may do as you get more advanced, you can then have the 43 43 00:01:55,000 --> 00:01:57,744 same things named in different namespaces and they won't 44 44 00:01:57,790 --> 00:02:00,129 clash. That includes DNS. 45 45 00:02:00,460 --> 00:02:03,253 In fact, when you look at the fully qualified domain name 46 46 00:02:03,430 --> 00:02:07,150 standard here, you'll see that it has the hostname, 47 47 00:02:07,240 --> 00:02:08,439 which we've been using so far. 48 48 00:02:08,770 --> 00:02:10,280 Then the namespace name. 49 49 00:02:10,330 --> 00:02:13,119 If you were to type out this full name, you would have to 50 50 00:02:13,120 --> 00:02:14,229 specify the namespace. 51 51 00:02:14,530 --> 00:02:16,719 By default, you've been working in default. 52 52 00:02:16,900 --> 00:02:18,669 That's the default namespace for apps. 53 53 00:02:19,120 --> 00:02:21,759 If you do a quick command at the command line 54 54 00:02:22,270 --> 00:02:24,789 of kubectl get 55 55 00:02:25,280 --> 00:02:27,490 namespaces, you'll see a list here. 56 56 00:02:27,960 --> 00:02:31,029 I'm on Docker Desktop, so I get an extra one there 57 57 00:02:31,030 --> 00:02:33,280 that says Docker, so that'll be just a part of your 58 58 00:02:33,550 --> 00:02:36,392 Docker Desktop that runs some special Docker services that 59 59 00:02:36,610 --> 00:02:38,911 do some of the magic that Docker provides in a Kubernetes 60 60 00:02:39,360 --> 00:02:41,957 cluster. The default is the one you're dumped into on 61 61 00:02:42,430 --> 00:02:45,039 a basic cluster. Then the other ones are standard that come 62 62 00:02:45,250 --> 00:02:46,250 out-of-the-box with Kubernetes. 63 63 00:02:46,870 --> 00:02:49,029 The system one, obviously, is running the control plane. 64 64 00:02:49,030 --> 00:02:50,600 That's the system there. 65 65 00:02:50,680 --> 00:02:52,629 The public, we don't really use much. 66 66 00:02:52,660 --> 00:02:53,889 It's only got a couple of things in it. 67 67 00:02:54,250 --> 00:02:56,650 Then node-lease is a new one in newer Kubernetes 68 68 00:02:56,830 --> 00:02:57,830 environments. 69 69 00:02:58,420 --> 00:03:01,439 These are really advanced topics that you won't really need 70 70 00:03:01,450 --> 00:03:04,539 getting started. You could quite possibly run 71 71 00:03:04,540 --> 00:03:06,729 your clusters without ever really messing a lot with those 72 72 00:03:07,150 --> 00:03:09,339 namespaces. Usually, what you're going to be dealing with 73 73 00:03:09,340 --> 00:03:11,684 is the default namespace and as you get larger, you 74 74 00:03:12,580 --> 00:03:15,212 will possibly make multiple namespaces 75 75 00:03:15,850 --> 00:03:18,639 for different applications that possibly had the same name. 76 76 00:03:19,060 --> 00:03:22,419 Or maybe you want to deploy the same thing multiple times, 77 77 00:03:22,420 --> 00:03:25,330 with the same service names, pod names, 78 78 00:03:25,510 --> 00:03:27,999 deployment names, and you wouldn't want them to clash, so 79 79 00:03:28,000 --> 00:03:29,620 you would create different namespaces for those. 80 80 00:03:30,040 --> 00:03:33,189 It's a little bit similar to Swarm stacks, 81 81 00:03:33,220 --> 00:03:35,575 but there's so much difference between the way namespaces 82 82 00:03:36,070 --> 00:03:39,039 work and stacks work that I really don't want you 83 83 00:03:39,040 --> 00:03:41,080 to get thinking that they're the exact same. 84 84 00:03:41,470 --> 00:03:44,229 Namespaces is really just an organizational parameter, 85 85 00:03:44,500 --> 00:03:46,950 and it doesn't, out-of-the-box, control networking 86 86 00:03:47,050 --> 00:03:48,550 segmentation or anything like that. 87 87 00:03:48,910 --> 00:03:50,859 That gets more advanced. You can worry about that stuff 88 88 00:03:50,860 --> 00:03:53,499 later. Let's get back to this fully qualified domain name 89 89 00:03:53,500 --> 00:03:56,109 there. Now that you know the hostname and the namespace 90 90 00:03:56,110 --> 00:03:59,319 part, then it's .svc for service because 91 91 00:03:59,320 --> 00:04:01,150 that's what we're looking up here. 92 92 00:04:01,540 --> 00:04:04,750 That cluster.local you see on the end is the default 93 93 00:04:05,110 --> 00:04:08,469 service DNS name given to your cluster when 94 94 00:04:08,470 --> 00:04:10,000 you create it or spin it up. 95 95 00:04:10,420 --> 00:04:12,939 If you're using something like kubeadm to build your 96 96 00:04:12,940 --> 00:04:15,292 cluster out, you can change that name before you 97 97 00:04:16,000 --> 00:04:18,519 build your cluster. This is the one, by default. 98 98 00:04:18,970 --> 00:04:21,729 You'll know if you need to change it based on maybe 99 99 00:04:21,730 --> 00:04:23,886 creating multiple Kubernetes clusters, or if 100 100 00:04:24,820 --> 00:04:27,069 you've got some sort of external requirements for how your 101 101 00:04:27,070 --> 00:04:30,279 apps find each other. Again, all this DNS is 102 102 00:04:30,400 --> 00:04:31,929 inside your cluster only. 103 103 00:04:31,930 --> 00:04:34,723 It's not some DNS service that outside services are going 104 104 00:04:34,960 --> 00:04:37,508 to be able to see, or use, unless they're talking to 105 105 00:04:38,080 --> 00:04:39,699 the Kubernetes API remotely.