- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Deploying kube-dns in a Kubernetes Cluster
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.

Lab Info
Table of Contents
-
Challenge
Deploy kube-dns to the cluster.
You can deploy kube-dns to the cluster like so:
kubectl create -f https://raw.githubusercontent.com/ACloudGuru-Resources/kthw-lab-scripts/master/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. -
Challenge
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
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.