2017-08-29 00:19:25 +03:00
# Deploying the DNS Cluster Add-on
2023-08-01 16:48:20 +03:00
In this lab you will deploy the [DNS add-on ](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ ) which provides DNS based service discovery, backed by [CoreDNS ](https://github.com/coredns/coredns ), to applications running inside the Kubernetes cluster.
2017-08-29 00:19:25 +03:00
## The DNS Cluster Add-on
2018-09-30 22:35:05 +03:00
Deploy the `coredns` cluster add-on:
2017-08-29 00:19:25 +03:00
```
2024-02-12 10:25:04 +03:00
kubectl apply --filename ./manifests/coredns-1.11.1.yaml
2017-08-29 00:19:25 +03:00
```
> output
```
2018-09-30 22:35:05 +03:00
serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns created
service/kube-dns created
2023-08-01 16:48:20 +03:00
deployment.apps/coredns created
2017-08-29 00:19:25 +03:00
```
List the pods created by the `kube-dns` deployment:
```
2023-08-01 16:48:20 +03:00
kubectl get pods --namespace kube-system --selector k8s-app=kube-dns
2017-08-29 00:19:25 +03:00
```
> output
```
2018-09-30 22:35:05 +03:00
NAME READY STATUS RESTARTS AGE
2021-05-02 08:33:46 +03:00
coredns-8494f9c688-hh7r2 1/1 Running 0 10s
coredns-8494f9c688-zqrj2 1/1 Running 0 10s
2017-08-29 00:19:25 +03:00
```
## Verification
2023-08-01 16:48:20 +03:00
Create a `busybox` pod:
2017-08-29 00:19:25 +03:00
```
2023-08-01 16:48:20 +03:00
kubectl run busybox --image busybox:1.36.1 --command -- sleep infinity
2017-08-29 00:19:25 +03:00
```
2023-08-01 16:48:20 +03:00
List the pod created:
2017-08-29 00:19:25 +03:00
```
2023-08-01 16:48:20 +03:00
kubectl get pods --selector run=busybox
2017-08-29 00:19:25 +03:00
```
> output
```
2019-09-14 21:41:56 +03:00
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 0 3s
2017-08-29 00:19:25 +03:00
```
Retrieve the full name of the `busybox` pod:
```
2023-08-01 16:48:20 +03:00
POD_NAME=$(kubectl get pods --selector run=busybox \
--output jsonpath="{.items[0].metadata.name}")
2017-08-29 00:19:25 +03:00
```
Execute a DNS lookup for the `kubernetes` service inside the `busybox` pod:
```
2023-08-01 16:48:20 +03:00
kubectl exec --stdin --tty "${POD_NAME}" -- nslookup kubernetes
2017-08-29 00:19:25 +03:00
```
> output
```
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
```
2023-08-01 16:48:20 +03:00
Delete the `busybox` pod:
```
kubectl delete pod "${POD_NAME}"
```
Next: [Smoke Test ](./13-smoke-test.md )