K8S DNS Optimization
- RNREDDY
- Aug 26
- 2 min read

It's easy to fall into the trap of default configurations. The out-of-the-box setup often works, but at what cost?
Let's explore a scenario that may seem familiar and then examine how some adjustments can create a faster, more consistent experience.


apiVersion: v1
kind: Pod
metadata:
name: checkout-service
spec:
containers:
- name: checkout-container
image: ecom-checkout:v3.5
Issues with this setup:
By default, Kubernetes relies on the cluster's DNS service to resolve service names. The DNS resolver might struggle to keep up with frequent lookups.
The default DNS policy (ClusterFirst) sends queries to the cluster DNS service, even for external names. This can lead to unnecessary traffic and delays in DNS resolution.
Under certain conditions, such as DNS cache exhaustion or network congestion, potential DNS resolution failures causes delays or even downtime for your checkout service.
Now, consider making a few adjustments to your Kubernetes Pod configuration to optimize DNS resolution:
apiVersion: v1
kind: Pod
metadata:
name: checkout-service
spec:
dnsPolicy: "None"
dnsConfig:
nameservers:
- 169.254.20.10
searches:
- svc.cluster.local
options:
- name: ndots
value: "5"
containers:
- name: checkout-container
image: ecom-checkout:v3.5
Technical Improvements:
Custom DNS Policy: By setting dnsPolicy: "None", you bypass the default cluster DNS and explicitly define how DNS resolution should occur.
Optimized DNS Configurations: With dnsConfig, you specify a dedicated nameserver (169.254.20.10 in this case) that’s tailored for your environment, ensuring faster and more reliable lookups.
Search Domain Optimization: By setting searches to svc.cluster.local, you streamline the domain search process, making it faster for Kubernetes to resolve service names within the cluster.
Reduced Lookup Depth: The ndots: "5" option configures the resolver to treat names with more than 5 dots as fully qualified domain names (FQDNs), reducing the time spent on unnecessary search path expansions and speeding up DNS resolution.
Why This Matters
By customizing your DNS configurations, you can reduce latency, avoid unnecessary lookups, and ultimately deliver a faster, more consistent service.
"Default isn't always bad, but optimizing beyond the default can turn good enough into great."
Comments