Bird
Raised Fist0
Kubernetesdevops~30 mins

DNS in Kubernetes (CoreDNS) - Mini Project: Build & Apply

Choose your learning style10 modes available
DNS in Kubernetes (CoreDNS)
📖 Scenario: You are managing a Kubernetes cluster and want to understand how DNS works inside it using CoreDNS. CoreDNS helps pods find each other by name instead of IP addresses.In this project, you will create a simple CoreDNS configuration, add a custom DNS entry, and test DNS resolution inside a pod.
🎯 Goal: Build a CoreDNS configuration with a custom DNS entry and verify DNS resolution inside a Kubernetes pod.
📋 What You'll Learn
Create a ConfigMap with CoreDNS configuration
Add a custom DNS entry for my-service.local
Deploy a pod to test DNS resolution
Use kubectl exec to run DNS lookup commands inside the pod
💡 Why This Matters
🌍 Real World
Kubernetes clusters use CoreDNS to provide DNS services for pods and services. Custom DNS entries help in service discovery and internal networking.
💼 Career
Understanding CoreDNS configuration and DNS troubleshooting is essential for Kubernetes administrators and DevOps engineers to maintain reliable cluster networking.
Progress0 / 4 steps
1
Create CoreDNS ConfigMap with base configuration
Create a ConfigMap called coredns in the kube-system namespace with the key Corefile containing this exact CoreDNS configuration:
.:53 {
    errors
    health
    kubernetes cluster.local in-addr.arpa ip6.arpa {
        pods insecure
        fallthrough in-addr.arpa ip6.arpa
    }
    prometheus :9153
    forward . /etc/resolv.conf
    cache 30
    loop
    reload
    loadbalance
}
Kubernetes
Hint

Use kubectl create configmap coredns -n kube-system --from-literal=Corefile='...' with the exact Corefile content.

2
Add a custom DNS entry for my-service.local
Add a new server block to the existing CoreDNS ConfigMap's Corefile that resolves my-service.local to IP 10.0.0.100. Append this block below the existing configuration:
my-service.local:53 {
    hosts {
        10.0.0.100 my-service.local
        fallthrough
    }
}

Update the ConfigMap coredns in the kube-system namespace with this new content.
Kubernetes
Hint

Append the new server block exactly as shown to the Corefile and update the ConfigMap with kubectl create configmap coredns -n kube-system --from-literal=Corefile='...'.

3
Deploy a pod to test DNS resolution
Create a pod named dns-test in the default namespace using the busybox image with a command that keeps it running:
kubectl run dns-test --image=busybox --restart=Never -- sleep 3600
Kubernetes
Hint

Use kubectl run dns-test --image=busybox --restart=Never -- sleep 3600 to create the pod.

4
Test DNS resolution inside the pod
Run the command kubectl exec dns-test -- nslookup my-service.local to check if my-service.local resolves to 10.0.0.100. Print the output exactly as returned by the command.
Kubernetes
Hint

Use kubectl exec dns-test -- nslookup my-service.local to test DNS resolution.

Practice

(1/5)
1. What is the main role of CoreDNS in a Kubernetes cluster?
easy
A. To manage container images in the cluster
B. To provide DNS resolution for services and pods inside the cluster
C. To schedule pods on nodes
D. To monitor cluster resource usage

Solution

  1. Step 1: Understand CoreDNS function

    CoreDNS acts as the DNS server inside Kubernetes, resolving names of services and pods.
  2. Step 2: Compare with other options

    Managing images, scheduling pods, and monitoring are done by other components like container registries, kube-scheduler, and metrics servers.
  3. Final Answer:

    To provide DNS resolution for services and pods inside the cluster -> Option B
  4. Quick Check:

    CoreDNS = DNS resolution inside Kubernetes [OK]
Hint: CoreDNS is Kubernetes' internal DNS server [OK]
Common Mistakes:
  • Confusing CoreDNS with pod scheduling
  • Thinking CoreDNS manages container images
  • Assuming CoreDNS monitors resources
2. Which Kubernetes resource holds the CoreDNS configuration?
easy
A. Secret named coredns in default namespace
B. Deployment in kube-system namespace
C. ConfigMap named coredns in kube-system namespace
D. ServiceAccount named coredns in kube-system namespace

Solution

  1. Step 1: Identify CoreDNS configuration storage

    The CoreDNS configuration is stored in a ConfigMap named 'coredns' inside the 'kube-system' namespace.
  2. Step 2: Eliminate other options

    Deployment runs CoreDNS pods but does not hold config; Secrets store sensitive data; ServiceAccounts manage permissions.
  3. Final Answer:

    ConfigMap named coredns in kube-system namespace -> Option C
  4. Quick Check:

    CoreDNS config = ConfigMap coredns in kube-system [OK]
Hint: CoreDNS config is a ConfigMap in kube-system [OK]
Common Mistakes:
  • Confusing ConfigMap with Secret
  • Looking in default namespace instead of kube-system
  • Thinking Deployment holds config data
3. Inside a pod, you run nslookup kubernetes.default.svc.cluster.local. What is the expected result?
medium
A. An IP address of the Kubernetes API service
B. An error saying domain not found
C. The pod's own IP address
D. The IP address of the CoreDNS pod

Solution

  1. Step 1: Understand the DNS query

    The domain 'kubernetes.default.svc.cluster.local' is the default Kubernetes API service DNS name inside the cluster.
  2. Step 2: Determine expected DNS resolution

    CoreDNS resolves this to the IP address of the Kubernetes API service, not the pod or CoreDNS pod IP.
  3. Final Answer:

    An IP address of the Kubernetes API service -> Option A
  4. Quick Check:

    Default service DNS resolves to API server IP [OK]
Hint: Default service DNS resolves to API server IP [OK]
Common Mistakes:
  • Expecting pod IP instead of service IP
  • Assuming CoreDNS pod IP is returned
  • Thinking query fails inside pod
4. You modified the CoreDNS ConfigMap but DNS queries inside pods still fail. What is the most likely fix?
medium
A. Restart the CoreDNS pods to reload the new config
B. Delete all pods in the default namespace
C. Reinstall Kubernetes cluster
D. Change pod DNSPolicy to Default

Solution

  1. Step 1: Recognize CoreDNS config reload behavior

    CoreDNS pods need to reload the ConfigMap changes, which usually requires restarting the pods.
  2. Step 2: Evaluate other options

    Deleting unrelated pods or reinstalling the cluster is unnecessary; changing DNSPolicy may break cluster DNS.
  3. Final Answer:

    Restart the CoreDNS pods to reload the new config -> Option A
  4. Quick Check:

    CoreDNS pods restart reloads ConfigMap changes [OK]
Hint: Restart CoreDNS pods after ConfigMap changes [OK]
Common Mistakes:
  • Deleting unrelated pods expecting DNS fix
  • Reinstalling cluster unnecessarily
  • Changing pod DNSPolicy incorrectly
5. You want to add a custom DNS entry for myapp.local inside your Kubernetes cluster using CoreDNS. Which step is required?
hard
A. Deploy a pod named myapp.local with a static IP
B. Create a new Service named myapp.local in default namespace
C. Modify the kubelet to add myapp.local to /etc/hosts on all nodes
D. Add a hosts plugin entry in the CoreDNS ConfigMap with myapp.local mapping

Solution

  1. Step 1: Understand how to add custom DNS entries in CoreDNS

    CoreDNS supports a hosts plugin where you can add static hostname-to-IP mappings in its ConfigMap.
  2. Step 2: Evaluate other options

    Creating a Service named myapp.local won't create a DNS entry for that domain; modifying kubelet hosts is manual and not scalable; pod names don't create DNS entries.
  3. Final Answer:

    Add a hosts plugin entry in the CoreDNS ConfigMap with myapp.local mapping -> Option D
  4. Quick Check:

    Custom DNS via hosts plugin in CoreDNS ConfigMap [OK]
Hint: Use hosts plugin in CoreDNS ConfigMap for custom DNS [OK]
Common Mistakes:
  • Thinking Service name creates arbitrary DNS names
  • Modifying node hosts files manually
  • Assuming pod names create DNS entries
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard