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
kubernetesservice indefaultnamespace - Resolve with full FQDN:
kubernetes.default.svc.cluster.local
Verify:
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.localQuestion 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:
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-systemQuestion 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:
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:
kubectl create namespace production
kubectl run web --image=nginx -n production
kubectl expose pod web --port=80 -n productionRequirements:
- From default namespace, resolve
web.production.svc.cluster.local - Test short form:
web.production
Verify:
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup web.productionQuestion 5: Debug Pod DNS Configuration
Objective: Check the DNS configuration inside a pod.
Requirements:
- Create a pod named
dns-check - Examine the
/etc/resolv.conffile - Identify: nameserver, search domains
Verify:
kubectl run dns-check --image=busybox --restart=Never -- sleep 3600
kubectl exec dns-check -- cat /etc/resolv.confQuestion 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:
kubectl exec custom-dns-pod -- cat /etc/resolv.confQuestion 7: Troubleshoot DNS Not Resolving
Objective: CoreDNS pods are CrashLooping. Diagnose the issue.
Steps:
- Check CoreDNS pod status
- Check CoreDNS logs
- Check CoreDNS ConfigMap for errors
- Check if kube-dns service has endpoints
Commands:
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-systemQuestion 8: Headless Service DNS
Objective: Test DNS for a headless service with StatefulSet.
Setup:
# 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: nginxRequirements:
- Resolve individual pod:
nginx-sts-0.nginx-headless - Resolve the headless service (should return all pod IPs)
Verify:
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-headlessQuestion 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:
# Add to Corefile inside ConfigMap
hosts {
10.0.0.50 myapp.internal
fallthrough
}Verify:
kubectl run dnstest --rm -it --image=busybox --restart=Never -- nslookup myapp.internalQuestion 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:
kubectl scale deployment coredns -n kube-system --replicas=3
kubectl get pods -n kube-system -l k8s-app=kube-dnsSolutions Reference
Question 6 Solution
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
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-systemQuestion 10 Solution
kubectl scale deployment coredns -n kube-system --replicas=3