I want to take a quick minute to talk about DNS and 2 2
Kubernetes. Sometimes we take it for granted in Docker, 3 3
and Swarm, and Kubernetes, DNS just kind of works. 4 4
I want to give you some details real quick on what's going 5 5
on in the background before we keep moving forward. 6 6
What you've experienced so far is if you're in a container, 7 7
and you cURL or ping a service name, 8 8
you get back the response. 9 9
So, clearly there's a DNS server in there 10 10
doing something to match services to 11 11
DNS names. Believe it or not, DNS is optional 12 12
as a service, or an add on, inside your Kubernetes cluster. 13 13
But, everyone puts one in there. 14 14
In fact, when you install it, whether it's kubeadm, or 15 15
Docker Desktop, or whatever you're using, there's going to 16 16
be a DNS server in there. 17 17
Starting with 1.11 Release, CoreDNS 18 18
is the default. It's sort of the standard. 19 19
There's a prior one called KubeDNS, which is deprecated at 20 20
this point, and we should all be using CoreDNS now. 21 21
What this is known as is DNS-based service discovery. 22 22
You had it in Docker. You had it in Swarm. 23 23
Basically, it works the same way in Kubernetes where when 24 24
you create a service, you get the hostname that matches 25 25
the service. But, that hostname is part of a larger 26 26
name, the fully qualified domain name. 27 27
We didn't get that in Docker or Swarm. 28 28
They were really just focused on hostnames. 29 29
With Kubernetes, we get more options, right. 30 30
So, out-of-the-box, you're just going to be talking 31 31
from one service to another using the hostname. 32 32
If you start using namespaces, and we 33 33
will go through that a little bit later. 34 34
Think of names spaces as a way to 35 35
section off all the different parts of different apps 36 36
into these areas inside the same cluster, that won't 37 37
really clash with each other. 38 38
You can't technically create the same pod, or the same 39 39
service, or the same Deployment, with the same 40 40
names, in the same namespace. 41 41
If you create other namespaces, which you 42 42
may do as you get more advanced, you can then have the 43 43
same things named in different namespaces and they won't 44 44
clash. That includes DNS. 45 45
In fact, when you look at the fully qualified domain name 46 46
standard here, you'll see that it has the hostname, 47 47
which we've been using so far. 48 48
Then the namespace name. 49 49
If you were to type out this full name, you would have to 50 50
specify the namespace. 51 51
By default, you've been working in default. 52 52
That's the default namespace for apps. 53 53
If you do a quick command at the command line 54 54
of kubectl get 55 55
namespaces, you'll see a list here. 56 56
I'm on Docker Desktop, so I get an extra one there 57 57
that says Docker, so that'll be just a part of your 58 58
Docker Desktop that runs some special Docker services that 59 59
do some of the magic that Docker provides in a Kubernetes 60 60
cluster. The default is the one you're dumped into on 61 61
a basic cluster. Then the other ones are standard that come 62 62
out-of-the-box with Kubernetes. 63 63
The system one, obviously, is running the control plane. 64 64
That's the system there. 65 65
The public, we don't really use much. 66 66
It's only got a couple of things in it. 67 67
Then node-lease is a new one in newer Kubernetes 68 68
environments. 69 69
These are really advanced topics that you won't really need 70 70
getting started. You could quite possibly run 71 71
your clusters without ever really messing a lot with those 72 72
namespaces. Usually, what you're going to be dealing with 73 73
is the default namespace and as you get larger, you 74 74
will possibly make multiple namespaces 75 75
for different applications that possibly had the same name. 76 76
Or maybe you want to deploy the same thing multiple times, 77 77
with the same service names, pod names, 78 78
deployment names, and you wouldn't want them to clash, so 79 79
you would create different namespaces for those. 80 80
It's a little bit similar to Swarm stacks, 81 81
but there's so much difference between the way namespaces 82 82
work and stacks work that I really don't want you 83 83
to get thinking that they're the exact same. 84 84
Namespaces is really just an organizational parameter, 85 85
and it doesn't, out-of-the-box, control networking 86 86
segmentation or anything like that. 87 87
That gets more advanced. You can worry about that stuff 88 88
later. Let's get back to this fully qualified domain name 89 89
there. Now that you know the hostname and the namespace 90 90
part, then it's .svc for service because 91 91
that's what we're looking up here. 92 92
That cluster.local you see on the end is the default 93 93
service DNS name given to your cluster when 94 94
you create it or spin it up. 95 95
If you're using something like kubeadm to build your 96 96
cluster out, you can change that name before you 97 97
build your cluster. This is the one, by default. 98 98
You'll know if you need to change it based on maybe 99 99
creating multiple Kubernetes clusters, or if 100 100
you've got some sort of external requirements for how your 101 101
apps find each other. Again, all this DNS is 102 102
inside your cluster only. 103 103
It's not some DNS service that outside services are going 104 104
to be able to see, or use, unless they're talking to 105 105
the Kubernetes API remotely.