Skip to content

CoreDNS Practice Questions


Question 1: Verify DNS Resolution

Objective: Test DNS resolution from within a pod.

Requirements:

  • Create a test pod using busybox image
  • Resolve the kubernetes service in default namespace
  • Resolve with full FQDN: kubernetes.default.svc.cluster.local

Verify:

bash
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup kubernetes
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup kubernetes.default.svc.cluster.local

Question 2: Check CoreDNS Status

Objective: Verify CoreDNS is running correctly.

Requirements:

  • Find CoreDNS pods
  • Check CoreDNS deployment replicas
  • Find the kube-dns service IP

Verify:

bash
kubectl get pods -n kube-system -l k8s-app=kube-dns
kubectl get deployment coredns -n kube-system
kubectl get svc kube-dns -n kube-system

Question 3: View Corefile Configuration

Objective: Extract and examine the Corefile from CoreDNS ConfigMap.

Requirements:

  • Get the CoreDNS ConfigMap
  • Display only the Corefile content
  • Identify the upstream DNS server

Verify:

bash
kubectl get cm coredns -n kube-system -o jsonpath='{.data.Corefile}'

Question 4: Resolve Service Across Namespaces

Objective: Test DNS resolution for a service in different namespace.

Setup:

bash
kubectl create namespace production
kubectl run web --image=nginx -n production
kubectl expose pod web --port=80 -n production

Requirements:

  • From default namespace, resolve web.production.svc.cluster.local
  • Test short form: web.production

Verify:

bash
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup web.production

Question 5: Debug Pod DNS Configuration

Objective: Check the DNS configuration inside a pod.

Requirements:

  • Create a pod named dns-check
  • Examine the /etc/resolv.conf file
  • Identify: nameserver, search domains

Verify:

bash
kubectl run dns-check --image=busybox --restart=Never -- sleep 3600
kubectl exec dns-check -- cat /etc/resolv.conf

Question 6: Pod with Custom DNS Config

Objective: Create a pod with custom DNS settings.

Requirements:

  • Name: custom-dns-pod
  • dnsPolicy: None
  • nameservers: 8.8.8.8, 8.8.4.4
  • search domain: example.com
  • ndots: 2

Verify:

bash
kubectl exec custom-dns-pod -- cat /etc/resolv.conf

Question 7: Troubleshoot DNS Not Resolving

Objective: CoreDNS pods are CrashLooping. Diagnose the issue.

Steps:

  1. Check CoreDNS pod status
  2. Check CoreDNS logs
  3. Check CoreDNS ConfigMap for errors
  4. Check if kube-dns service has endpoints

Commands:

bash
kubectl get pods -n kube-system -l k8s-app=kube-dns
kubectl logs -n kube-system -l k8s-app=kube-dns
kubectl get cm coredns -n kube-system -o yaml
kubectl get endpoints kube-dns -n kube-system

Question 8: Headless Service DNS

Objective: Test DNS for a headless service with StatefulSet.

Setup:

yaml
# Create headless service
apiVersion: v1
kind: Service
metadata:
  name: nginx-headless
spec:
  clusterIP: None
  selector:
    app: nginx-sts
  ports:
  - port: 80
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nginx-sts
spec:
  serviceName: nginx-headless
  replicas: 3
  selector:
    matchLabels:
      app: nginx-sts
  template:
    metadata:
      labels:
        app: nginx-sts
    spec:
      containers:
      - name: nginx
        image: nginx

Requirements:

  • Resolve individual pod: nginx-sts-0.nginx-headless
  • Resolve the headless service (should return all pod IPs)

Verify:

bash
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup nginx-sts-0.nginx-headless
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup nginx-headless

Question 9: Add Custom Host Entry to CoreDNS

Objective: Add a custom DNS entry for myapp.internal pointing to 10.0.0.50.

Requirements:

  • Edit the coredns ConfigMap
  • Add hosts plugin with custom entry
  • Verify resolution

Solution:

yaml
# Add to Corefile inside ConfigMap
hosts {
    10.0.0.50 myapp.internal
    fallthrough
}

Verify:

bash
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup myapp.internal

Question 10: Scale CoreDNS

Objective: Scale CoreDNS to 3 replicas for high availability.

Requirements:

  • Scale coredns deployment to 3 replicas
  • Verify all replicas are running

Verify:

bash
kubectl scale deployment coredns -n kube-system --replicas=3
kubectl get pods -n kube-system -l k8s-app=kube-dns

Solutions Reference

Question 6 Solution

yaml
apiVersion: v1
kind: Pod
metadata:
  name: custom-dns-pod
spec:
  dnsPolicy: "None"
  dnsConfig:
    nameservers:
    - 8.8.8.8
    - 8.8.4.4
    searches:
    - example.com
    options:
    - name: ndots
      value: "2"
  containers:
  - name: app
    image: busybox
    command: ["sleep", "3600"]

Question 9 Solution

bash
kubectl edit cm coredns -n kube-system

# Add hosts plugin before kubernetes plugin:
# hosts {
#     10.0.0.50 myapp.internal
#     fallthrough
# }

# Restart CoreDNS
kubectl rollout restart deployment coredns -n kube-system

Question 10 Solution

bash
kubectl scale deployment coredns -n kube-system --replicas=3

Released under the MIT License.