Deploying the DNS Cluster Add-on

In this lab you will deploy the DNS add-on which provides DNS based service discovery, backed by CoreDNS, to applications running inside the Kubernetes cluster.

The DNS Cluster Add-on

Deploy the coredns cluster add-on:

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

output

  1. serviceaccount/coredns created
  2. clusterrole.rbac.authorization.k8s.io/system:coredns created
  3. clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
  4. configmap/coredns created
  5. deployment.apps/coredns created
  6. service/kube-dns created

List the pods created by the kube-dns deployment:

  1. kubectl get pods -l k8s-app=kube-dns -n kube-system

output

  1. NAME READY STATUS RESTARTS AGE
  2. coredns-5677dc4cdb-d8rtv 1/1 Running 0 30s
  3. coredns-5677dc4cdb-m8n69 1/1 Running 0 30s

Verification

Create a busybox deployment:

  1. kubectl run busybox --image=busybox:1.28 --command -- sleep 3600

List the pod created by the busybox deployment:

  1. kubectl get pods -l run=busybox

output

  1. NAME READY STATUS RESTARTS AGE
  2. busybox 1/1 Running 0 3s

Retrieve the full name of the busybox pod:

  1. POD_NAME=$(kubectl get pods -l run=busybox -o jsonpath="{.items[0].metadata.name}")

Execute a DNS lookup for the kubernetes service inside the busybox pod:

  1. kubectl exec -ti $POD_NAME -- nslookup kubernetes

output

  1. Server: 10.32.0.10
  2. Address 1: 10.32.0.10 kube-dns.kube-system.svc.cluster.local
  3. Name: kubernetes
  4. Address 1: 10.32.0.1 kubernetes.default.svc.cluster.local

Next: Smoke Test