k8s 08: coreDNS

In this entry, I’m going to deploy DNS for kubernetes cluster. And for this purpose, I’m going to use CoreDNS, since this is the recommended DNS service over kube-dns.

I will deploy this a bit differently from other services, and this would be deployed as containers. Actually other kubernetes services(except kubelete, container runtime) can be deployed as containers rather than system services. And it would provide more resiliency to those services thanks to kubernetes self healing functionality. But in order to deploy those services, we need to know more about how kubernetes works(affinity, tolerance, static pods). I will cover this in a later article.

DNS in kubernetes works just the same as the usual DNS in open world. It resolves the human readable name to ip address. In real world, you need to add a record in DNS when you make a new service(web service and so on). In CoreDNS, it creates the dns entry once you create a service in kubernetes cluster.

Deploy CoreDNS

CoreDNS detail is in its official website.

1. Deploy CoreDNS containers in each node

In this setup, I use DaemonSet, which deploys one instance in each worker node. Sincethis DNS is meant to be used by containers, so I think it should be deployed as close as possible.

[ controller-1 ]

2. Confirm if CoreDNS is deployed

[ controller-1 ]

3. Confirm if CoreDNS is working correctly

[ controller-1 ]

[ worker-1 ]

So we confirmed CoreDNS seems working OK, but we need to change some config on kubelet so that it can propagate this new DNS services to be used for containers.


Modify Kubelet

1. Reconfigure Kubelet system service

kubelet takes numbers of flags so that it can be passed to the docker and eventually it’s used for containers.

[ each worker node ]


Test

So it should be working now. First I launch nginx pod with cluster ip service using the manifest file from the previous post.

[ controller-1 ]

And launch a busybox. Please note as of Sept. 2018, the latest busybox image has some issues with nslookup, hence I’m using ver 1.28 here.

[ controller-1 ]

Check the busybox container, and login to it.

And confirm it can resolves the name, and it can access the service

We have working CoreDNS now!

Before leaving, don’t forget to do the house keeping.

That’s all for today.