DEV Community

Ibrahim S
Ibrahim S

Posted on

DNS | Kubernetes

CoreDNS is a flexible and powerful DNS server commonly used in modern cloud-native environments, especially in Kubernetes clusters. It acts as the default DNS server for Kubernetes starting from version 1.13, replacing Kube-DNS.

CoreDNS is the primary DNS service inside the Kubernetes cluster that gets a lot of flack and usually gets a finger point when outages arise. Let's demystify this a bit and talk about DNS in Kubernetes!

By default, CoreDNS is a service running in the cluster, just like everything else. It has a single replica but can be scaled up based on workload demand or even with a HPA.

In front of it is a service usually called something like Kube-DNS that uses the standard 53 UDP/TCP ports. Pods, when spun up in the cluster, will have /etc/resolv.conf generated and pointed to the inter-CoreDNS service endpoint.

CoreDNS will track DNS resolution to services in the cluster. By default, every service will get a resolvable DNS name. The names follow a pretty predictable pattern that you can use in your, applications to reference other services in the cluster:
<service_name>.<namespace>.svc.cluster.local

CoreDNS is configured via a standard Kubernetes config map and is extremely flexible and modular. So much so—I've seen organizations expose CoreDNS and use it as an internal DNS service for their organizations!

By default, CoreDNS will act as a forwarder for any names in can't be resolved (anything not *.cluster.local). If you look in the default config map, you will see that it forwards to a local file:

. /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

This means that core DNS by default will look at the node it's running on to determine upstream DNS configurations. This is why every node NEEDS to have the same configuration. This is a common gotcha that breaks DNS in clusters!

That's pretty much it! By default, it's very simple and resolves internal addresses and forwards to external addresses via the resolv.conf on the node.

There are some cool integrations you can use to speed up the resolution of DNS in the cluster, such as node-local DNS and caching as well!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay