0
0
Kubernetesdevops~30 mins

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

Choose your learning style9 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
Need a 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
Need a 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
Need a 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
Need a hint?

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