Kubernetes the hard way on bare metal/VMs — Setting up DNS

Part of the Kubernetes the hard way on bare metal/VM

Drew Viles
2 min readDec 14, 2018
Kubernetes Logo

Introduction

This guide is part of the Kubernetes the hard way on bare metal/VMs series. On its own this may be useful to you however since it’s tailored for the series, it may not be completely suited to your needs.

Setting up DNS

In Kelsey’s guide, he creates the routing with GCE but you don’t have that luxury with bare metal unfortunately.

In your setup, you have a variety of options available.

As mentioned way back at the start, you’ll be using kube-router and by the way, we’re back on the lab machine.

Two approaches (decide before running):

Remove kube-proxy and let kube-router do everything:

CLUSTERCIDR=10.32.0.0/16
APISERVER=https://${INTERNAL_IP}:6443
sh -c 'curl https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/generic-kuberouter-all-features.yaml -o - | sed -e "s;%APISERVER%;$APISERVER;g" -e "s;%CLUSTERCIDR%;$CLUSTERCIDR;g"' | kubectl apply -f -kubectl -n kube-system delete ds kube-proxy

OR

Have kube-proxy do everything for service networking and let kube-router do everything else.
This is what you’re going to do.

kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/generic-kuberouter.yaml

NB: You must have “ --allocate-node-cidrs=true” in the service definition for kube-controller-manager for kube-router to work with this method — you set this earlier on when you defined the service. Remove this and reload the service if you choose the first method.

kubectl -n kube-system get po --watchNAME             READY STATUS  RESTARTS AGE
kube-router-qszq9 1/1 Running 0 110s

NB: You may need to run sudo ln -s /etc/resolv.conf /run/systemd/resolve/ on each node o get the pod to run if it fails.

DNS addon setup

You’ll be using CoreDNS from Kelsey’s guide

kubectl apply -f https://storage.googleapis.com/kubernetes-the-hard-way/coredns.yaml

Check it works

kubectl get pods -l k8s-app=kube-dns -n kube-system --watch#Results
NAME READY STATUS RESTARTS AGE
coredns-699f8ddd77-fmc67 1/1 Running 0 40s
coredns-699f8ddd77-zb7gw 1/1 Running 0 42

Tests

Of course, you should test everything to make sure your new DNS bits work as expected, so let’s do just that.

kubectl run busybox --image=busybox:1.28 --command -- sleep 3600
kubectl get pods -l run=busybox
POD_NAME=$(kubectl get pods -l run=busybox -o jsonpath="{.items[0].metadata.name}")kubectl exec -ti $POD_NAME -- nslookup kubernetes##Results
Server: 10.32.0.10
Address 1: 10.32.0.10 kube-dns.kube-system.svc.cluster.local
Name: kubernetes
Address 1: 10.32.0.1 kubernetes.default.svc.cluster.local

If you don’t see the results above, it’s likely the coredns pods have errors. use kubectl describe & logs to diagnose these.

Conclusion

You’ve configured the DNS for the cluster and without realising it, just finished setting up the entire cluster!

Next: Testing everything

--

--