OpsCanary
Back to daily brief
kubernetesnetworkingPractitioner

Mastering DNS for Kubernetes Services and Pods

5 min read Kubernetes DocsApr 22, 2026
PractitionerHands-on experience recommended

DNS is the backbone of service discovery in Kubernetes. It allows Pods to find and communicate with each other without needing to know their IP addresses. This is vital in dynamic environments where Pods are frequently created and destroyed. By automatically creating DNS records for Services and Pods, Kubernetes simplifies the process of service discovery, enabling you to focus on building your applications rather than managing network configurations.

Kubernetes uses various DNS records to facilitate this. Normal Services receive A and/or AAAA records based on their IP family. For named ports in Services, SRV records are created, which help in routing traffic correctly. Each Pod can also have a specific hostname and subdomain, defined in its spec, allowing for more granular control over how Pods are addressed. The DNS policy for each Pod can be set individually, with the default being 'ClusterFirst', which prioritizes cluster DNS over external DNS. This is particularly useful when accessing Services in different namespaces, as queries can be expanded to include the namespace, such as data.test.svc.cluster.local.

In production, be aware of the limitations of the hostname field in Linux, which is capped at 64 characters. If your Pod's FQDN exceeds this limit, it will fail to start. This is a critical consideration when designing your service architecture, especially if you're using long names. Also, note that this feature is not supported on Windows, which could impact your deployment strategy if you're working in a mixed OS environment. Keep your Kubernetes version in mind as well; features and behaviors can change between versions, so always test in your specific environment before rolling out changes.

Key takeaways

  • Understand how Kubernetes creates DNS records for Services and Pods to facilitate service discovery.
  • Use A and AAAA records for normal Services to manage IP addressing effectively.
  • Leverage SRV records for named ports to ensure proper traffic routing.
  • Set the Pod's DNS policy to control DNS resolution behavior based on your application needs.
  • Be cautious of the 64-character limit for hostnames in Linux to avoid startup failures.

Why it matters

Effective DNS management in Kubernetes directly impacts the reliability and scalability of your applications. Misconfigurations can lead to service outages, making it essential to understand how DNS operates within your cluster.

Code examples

YAML
1apiVersion:v1
2kind:Service
3metadata:
4  name: busybox-subdomain
5spec:
6  selector:
7    name: busybox
8  clusterIP: None
9  ports:
10    - name: foo # name is not required for single-port Services
11      port: 1234
YAML
1apiVersion:v1
2kind:Pod
3metadata:
4  name: busybox1
5labels:
6  name: busybox
7spec:
8  hostname: busybox-1
9  subdomain: busybox-subdomain
10  containers:
11    - image: busybox:1.28
12      command: [-sleep, '3600']
13      name: busybox
plaintext
nameserver 10.32.0.10
search <namespace>.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.