Deploying kube-dns in a Kubernetes Cluster

1 hour
  • 2 Learning Objectives

About this Hands-on Lab

Pods can communicate with each other and with services via their IP addresses, once networking has been set up in a Kubernetes cluster. But it is easier to locate other pods and services by hostname, since IP addresses can change. In order to do this, the cluster requires a DNS service. In this learning activity, you will learn how to deploy *kube-dns* to a cluster in order to provide DNS service to pods.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Deploy kube-dns to the cluster.

You can deploy kube-dns to the cluster like so:

kubectl create -f https://storage.googleapis.com/kubernetes-the-hard-way/kube-dns.yaml

Verify that the kube-dns pod starts up correctly:

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

You should get output showing the kube-dns pod. It should look something like this:

NAME                        READY     STATUS    RESTARTS   AGE
kube-dns-598d7bf7d4-spbmj   3/3       Running   0          36s

Make sure that 3/3 containers are ready and that the pod has a status of Running. It may take a moment for the pod to be fully up and running, so if READY is not 3/3 at first, check again after a few moments.

Test the DNS by creating a service, and perform a DNS lookup for service from another pod using the service name

Test the DNS by creating a service, and access the service from another pod using the service name.

Create a simple service like so:

kubectl run nginx --image=nginx
kubectl expose deployment nginx --port 80

Get a list of services:

kubectl get svc

You should see the nginx service listed.

Spin up a busybox pod for testing and get the pod name:

kubectl run busybox --image=busybox:1.28 --command -- sleep 3600
POD_NAME=$(kubectl get pods -l run=busybox -o jsonpath="{.items[0].metadata.name}")

Perform a DNS lookup of the nginx service from within the busybox pod to verify that DNS is working:

kubectl exec $POD_NAME -- nslookup nginx

You should get output that looks like this:

Server:    10.32.0.10
Address 1: 10.32.0.10 kube-dns.kube-system.svc.cluster.local

Name:      nginx
Address 1: 10.32.0.248 nginx.default.svc.cluster.local

Additional Resources

Your team has set up a new Kubernetes cluster. However, they want to provide a simple web service as a backend microservice in the cluster. In order to do so, they need a DNS set up within the Kubernetes cluster. Your task is to provide DNS service within the Kubernetes cluster using kube-dns.

You can access a pre-configured kubectl by logging in to the controller server.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!