> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lab Solution Explore DNS optional

> Lab guide to inspect Kubernetes DNS (CoreDNS), determine pod count, Service name and ClusterIP, and locate CoreDNS Corefile and its ConfigMap volume mount.

This guide inspects the DNS implementation running in a Kubernetes cluster (kube-system namespace) and answers the following:

* Which DNS solution is implemented?
* How many DNS server pods are deployed?
* What Service name exposes CoreDNS?
* What is the Service ClusterIP used by pods for DNS lookups?
* Where is the CoreDNS configuration stored and how is it mounted into the pods?

## 1. Set a kubectl alias and list kube-system pods

Use a short alias for kubectl to speed up commands:

```bash theme={null}
# set alias for convenience
alias k=kubectl

# list kube-system pods
k get pods -n kube-system
```

Example output:

```bash theme={null}
NAME                                  READY   STATUS    RESTARTS   AGE
coredns-74ff55c5b-9lcxv               1/1     Running   0          14m
coredns-74ff55c5b-kgtwz               1/1     Running   0          14m
etcd-controlplane                     1/1     Running   0          14m
kube-apiserver-controlplane           1/1     Running   0          14m
kube-controller-manager-controlplane  1/1     Running   0          14m
kube-flannel-ds-ztb5d                 1/1     Running   0          14m
kube-proxy-wq2p9                      1/1     Running   0          14m
kube-scheduler-controlplane           1/1     Running   0          14m
```

Interpretation:

* DNS implementation: CoreDNS (pods named `coredns-*`).
* Number of CoreDNS pods: 2.

## 2. Find the Kubernetes Service for DNS

List Services in the kube-system namespace to locate the DNS Service:

```bash theme={null}
k get svc -n kube-system
```

Example relevant line (truncated):

```bash theme={null}
NAME       TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)         AGE
kube-dns   ClusterIP   10.96.0.10    <none>        53/UDP,53/TCP   14m
```

From this:

* Service name exposing CoreDNS: `kube-dns`
* Service ClusterIP (used by pods): `10.96.0.10`

## 3. Inspect a CoreDNS pod to find the Corefile and mounts

Describe one of the CoreDNS pods to inspect container arguments, mounts, and volumes:

```bash theme={null}
k describe pod coredns-74ff55c5b-9lcxv -n kube-system
```

Relevant excerpts from the describe output:

```bash theme={null}
Containers:
  coredns:
    Image:         k8s.gcr.io/coredns:1.7.0
    Ports:         53/UDP, 53/TCP, 9153/TCP
    Args:
      -conf
      /etc/coredns/Corefile
    State:         Running
    Ready:         True
    Restart Count: 0
    Liveness:      http-get http://:8080/health delay=60s timeout=5s period=10s #success=1 #failure=5
    Readiness:     http-get http://:8181/ready delay=0s timeout=1s period=10s #success=1 #failure=3
    Mounts:
      /etc.coredns from config-volume (ro)
      /var/run/secrets/kubernetes.io/serviceaccount from coredns-token-8scbd (ro)

Volumes:
  config-volume:
    Type:       ConfigMap (a volume populated by a ConfigMap)
    Name:       coredns
    Optional:   false
  coredns-token-8scbd:
    Type:       Secret (a volume populated by a Secret)
    SecretName: coredns-token-8scbd
    Optional:   false
```

Key findings:

* CoreDNS reads its configuration from `/etc/coredns/Corefile` (see `-conf /etc/coredns/Corefile`).
* The `/etc.coredns` directory is mounted from a volume named `config-volume`.
* `config-volume` is a ConfigMap volume sourced from the `coredns` ConfigMap.

<Callout icon="lightbulb" color="#1CB2FE">
  CoreDNS configuration (the Corefile) is typically stored in the `coredns` ConfigMap in the `kube-system` namespace and volume-mounted into the CoreDNS pods at `/etc/coredns/Corefile`. You can inspect it with `kubectl get configmap coredns -n kube-system -o yaml`.
</Callout>

## 4. Quick reference — answers

| Question | Answer |
| - | - |
| DNS solution implemented | CoreDNS |
| Number of DNS pods | 2 |
| Service name used to access CoreDNS | `kube-dns` |
| Service ClusterIP | `10.96.0.10` |
| Corefile location inside pod | `/etc/coredns/Corefile` (provided via the `coredns` ConfigMap mounted as `config-volume`) |

## 5. Useful links and commands

* Inspect the CoreDNS ConfigMap:
  * `kubectl get configmap coredns -n kube-system -o yaml`
* Kubernetes DNS overview: [https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/)
* CoreDNS upstream docs: [https://coredns.io/](https://coredns.io/)

<Callout icon="lightbulb" color="#1CB2FE">
  Tip: If you need to edit the CoreDNS Corefile, update the `coredns` ConfigMap and then restart the CoreDNS pods (or let the Deployment/DaemonSet roll them) so the new Corefile is picked up.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/cka-certification-course-certified-kubernetes-administrator/module/44bc9a9f-319c-40ee-babd-0f7b53a70de7/lesson/57bcd734-dacc-4c1d-80a2-ea0ba7dea323" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.