DNS Basics
This page is a hands-on intro to Kubernetes DNS: how names like service.namespace.svc.cluster.local resolve, what records CoreDNS serves, and how to test resolution from inside a pod.
Busque em todas as páginas da documentação
This page is a hands-on intro to Kubernetes DNS: how names like service.namespace.svc.cluster.local resolve, what records CoreDNS serves, and how to test resolution from inside a pod.
kubectl configured against the cluster.nicolaka/netshoot bundles dig, nslookup, and nc.Quick one-off debug pod:
kubectl run tmp --rm -it --image=nicolaka/netshoot --restart=Never -- bashInside the same namespace, the Service name alone is enough.
dig +short paymentsresolv.conf search list appends namespace.svc.cluster.local.payments expands to payments.<namespace>.svc.cluster.local.Add the namespace label to reach a Service elsewhere.
dig +short payments.billingpayments.billing expands via the svc.cluster.local suffix in the search list.The absolute FQDN skips the search-list guesswork.
dig +short payments.billing.svc.cluster.localsvc.cluster.local marks this as a Service A record.ndots:5 search behavior.See exactly what the kubelet injected.
kubectl exec tmp -- cat /etc/resolv.confsearch myns.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5nameserver is the cluster DNS Service ClusterIP (often 10.96.0.10).search domains enable short-name resolution.ndots:5 means names with fewer than 5 dots try the search list first.CoreDNS sits behind a Service named kube-dns.
kubectl -n kube-system get svc kube-dnskube-dns for backward compatibility even though CoreDNS serves it.nameserver in every pod's resolv.conf.kube-system.Services publish SRV records for named ports.
dig +short SRV _http._tcp.payments.billing.svc.cluster.local_port-name._protocol.service.namespace.svc.cluster.local.CoreDNS forwards names it does not own to upstream resolvers.
dig +short api.github.comcluster.local are forwarded via CoreDNS's forward plugin./etc/resolv.conf.Headless Services return pod IPs instead of one virtual IP.
apiVersion: v1
kind: Service
metadata:
name: cassandra
namespace: data
spec:
clusterIP: None
selector:
app: cassandra
ports:
- port: 9042dig +short cassandra.data.svc.cluster.localclusterIP: None makes this a headless Service.cassandra-0.cassandra.data.svc.cluster.local.High ndots can cause several failed lookups for external names.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
dnsConfig:
options:
- name: ndots
value: "2"
containers:
- name: web
image: registry.example.com/web:1.4.0@sha256:abc123ndots makes external FQDNs resolve on the first try.dnsConfig per pod or use a fully qualified name with a trailing dot.dnsPolicy: None gives you full control of resolv.conf.
spec:
dnsPolicy: None
dnsConfig:
nameservers:
- 10.96.0.10
searches:
- myns.svc.cluster.local
- svc.cluster.local
options:
- name: ndots
value: "5"dnsPolicy: None ignores cluster defaults and uses only your dnsConfig.nameservers if the pod still needs Service resolution.A default-deny egress policy blocks DNS unless you allow port 53.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns
namespace: myns
spec:
podSelector: {}
policyTypes:
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53kube-system namespace where CoreDNS runs.Use nslookup when a container lacks dig.
kubectl exec tmp -- nslookup payments.billing.svc.cluster.localServer: 10.96.0.10
Address: 10.96.0.10#53
Name: payments.billing.svc.cluster.local
Address: 10.104.12.7Server confirms the cluster DNS ClusterIP is answering.Address is the Service ClusterIP for a normal Service.NXDOMAIN, check the namespace label and that the Service exists.Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Revisado por Chris St. John·Última atualização: 19 de jul. de 2026