2017-08-28 14:19:25 -07:00
# Deploying the DNS Cluster Add-on
2018-09-30 19:35:05 +00: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://coredns.io/ ), to applications running inside the Kubernetes cluster.
2017-08-28 14:19:25 -07:00
## The DNS Cluster Add-on
2018-09-30 19:35:05 +00:00
Deploy the `coredns` cluster add-on:
2017-08-28 14:19:25 -07:00
```
2019-03-20 17:28:07 +08:00
kubectl apply -f https://raw.githubusercontent.com/mmumshad/kubernetes-the-hard-way/master/deployments/coredns.yaml
2017-08-28 14:19:25 -07:00
```
> output
```
2018-09-30 19:35:05 +00:00
serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns created
deployment.extensions/coredns created
service/kube-dns created
2017-08-28 14:19:25 -07:00
```
List the pods created by the `kube-dns` deployment:
```
kubectl get pods -l k8s-app=kube-dns -n kube-system
```
> output
```
2018-09-30 19:35:05 +00:00
NAME READY STATUS RESTARTS AGE
coredns-699f8ddd77-94qv9 1/1 Running 0 20s
coredns-699f8ddd77-gtcgb 1/1 Running 0 20s
2017-08-28 14:19:25 -07:00
```
2019-11-19 10:19:29 +05:30
Reference: https://kubernetes.io/docs/tasks/administer-cluster/coredns/#installing -coredns
2017-08-28 14:19:25 -07:00
## Verification
Create a `busybox` deployment:
```
2019-03-20 17:42:40 +08:00
kubectl run --generator=run-pod/v1 busybox --image=busybox:1.28 --command -- sleep 3600
2017-08-28 14:19:25 -07:00
```
List the pod created by the `busybox` deployment:
```
kubectl get pods -l run=busybox
```
> output
```
2018-09-30 19:35:05 +00:00
NAME READY STATUS RESTARTS AGE
busybox-bd8fb7cbd-vflm9 1/1 Running 0 10s
2017-08-28 14:19:25 -07:00
```
Execute a DNS lookup for the `kubernetes` service inside the `busybox` pod:
```
2019-03-20 17:44:09 +08:00
kubectl exec -ti busybox -- nslookup kubernetes
2017-08-28 14:19:25 -07:00
```
> output
```
2019-03-20 12:34:49 +08:00
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
2017-08-28 14:19:25 -07:00
Name: kubernetes
2019-03-20 12:34:49 +08:00
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local
2017-08-28 14:19:25 -07:00
```
2019-03-20 18:12:49 +08:00
Next: [Smoke Test ](15-smoke-test.md )