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
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!
Top comments (0)