Why Add a Custom DNS Zone?
Adding a custom DNS zone in CoreDNS can be useful for:
- Internal testing (e.g.,
*.local
or*.internal
) - Service discovery for non-Kubernetes services
- Custom mappings and overrides
Step-by-Step Guide
1. Edit the CoreDNS ConfigMap
kubectl -n kube-system edit configmap coredns
Add a new zone block like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
internal.test:53 {
hosts {
10.10.10.10 service1.internal.test
10.10.10.11 service2.internal.test
fallthrough
}
}
2. Restart CoreDNS
kubectl -n kube-system rollout restart deployment coredns
3. Test the Zone
From any pod:
nslookup service1.internal.test
You should get back 10.10.10.10
as expected.
Tips
- You can use
hosts
orfile
plugins depending on your needs. - Don’t forget
fallthrough
if you want unresolved queries to continue to the next plugin. - Keep zone names unique to avoid conflicts.
Conclusion
Custom zones in CoreDNS are a powerful tool to fine-tune DNS behavior within Kubernetes. Great for testing, hybrid architectures, or overriding legacy names.
→ Learn more: