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.
Deploy the coredns
cluster add-on:
(Get-Content deployments/coredns.yaml -Raw) -replace '<CLUSTER_IP>',"${K8sPodCidrPrefix}.0.10" | kubectl apply -f -
output
serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created
List the pods created by the core-dns
deployment:
kubectl get pods -l k8s-app=kube-dns -n kube-system
output
NAME READY STATUS RESTARTS AGE
coredns-8494f9c688-hh7r2 1/1 Running 0 10s
coredns-8494f9c688-zqrj2 1/1 Running 0 10s
Create a busybox
deployment:
kubectl run busybox --image=busybox:1.28 --command -- sleep 3600
List the pod created by the busybox
deployment:
kubectl get pods -l run=busybox
output
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 0 3s
Execute a DNS lookup for the kubernetes
service inside the busybox
pod:
kubectl exec -ti $(kubectl get pods -l run=busybox -o jsonpath='{.items[0].metadata.name}') -- nslookup kubernetes
output
Server: 172.22.0.10
Address 1: 172.22.0.10 kube-dns.kube-system.svc.cluster.local
Name: kubernetes
Address 1: 172.22.0.1 kubernetes.default.svc.cluster.local
Next: Smoke Test