The coredns add-on is a DNS server that provides domain name resolution services for Kubernetes clusters. coredns chains plug-ins to provide additional features.
coredns is an open-source software and has been a part of CNCF. It provides a means for cloud services to discover each other in cloud-native deployments. Each of the plug-ins chained by coredns provides a particular DNS function. You can integrate coredns with only the plug-ins you need to make it fast, efficient, and flexible. When used in a Kubernetes cluster, coredns can automatically discover services in the cluster and provide domain name resolution for these services. By working with a cloud DNS server, coredns can resolve external domain names for workloads in a cluster.
coredns is a system resource add-on. It is installed by default when a cluster of Kubernetes v1.11 or later is created.
Kubernetes v1.11 and later back CoreDNS as the official default DNS for all clusters going forward.
CoreDNS official website: https://coredns.io/
Open source community: https://github.com/coredns/coredns
When CoreDNS is running properly or being upgraded, ensure that the number of available nodes is greater than or equal to the number of CoreDNS instances and all CoreDNS instances are running. Otherwise, the upgrade will fail.
This add-on has been installed by default. If it is uninstalled due to some reasons, you can reinstall it by performing the following steps:
Parameter |
Description |
---|---|
Add-on Specifications |
Concurrent domain name resolution ability. Select add-on specifications that best fit your needs. |
Instances |
Number of pods that will be created to match the selected add-on specifications. The number cannot be modified. |
Container |
CPU and memory quotas of the container allowed for the selected add-on specifications. The quotas cannot be modified. |
Notes |
Add-on precautions. Read the precautions before you proceed with the step. |
stub domain |
A domain name server for a user-defined domain name. The format is a key-value pair. The key is a suffix of DNS domain name, and the value is one or more DNS IP addresses. For example, acme.local -- 1.2.3.4,6.7.8.9 means that DNS requests with the .acme.local suffix are forwarded to a DNS listening at 1.2.3.4,6.7.8.9. |
After the add-on is installed, click Go Back to Previous Page. On the Add-on Instance tab page, select the corresponding cluster to view the running instance. This indicates that the add-on has been installed on each node in the cluster.
Cluster administrators can modify the ConfigMap for the CoreDNS Corefile to change how service discovery works. They can configure stub domains for CoreDNS using the proxy plug-in.
Assume that a cluster administrator has a Consul DNS server located at 10.150.0.1 and all Consul domain names have the suffix .consul.local.
To configure this Consul DNS server in CoreDNS, run the following command to edit the CoreDNS ConfigMap:
kubectl edit configmap coredns -n kube-system
Example configuration:
consul.local:5353 { errors cache 30 proxy . 10.150.0.1 }
In clusters of v1.15.11 and later, the modified ConfigMap is as follows:
apiVersion: v1 metadata: name: coredns namespace: kube-system selfLink: /api/v1/namespaces/kube-system/configmaps/coredns uid: 00cb8f29-62d7-4df8-a769-0a16237903c1 resourceVersion: '2074614' creationTimestamp: '2021-04-07T03:52:42Z' labels: app: coredns k8s-app: coredns kubernetes.io/cluster-service: 'true' kubernetes.io/name: CoreDNS release: cceaddon-coredns data: Corefile: |- .:5353 { bind {$POD_IP} cache 30 errors health {$POD_IP}:8080 kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream /etc/resolv.conf fallthrough in-addr.arpa ip6.arpa } loadbalance round_robin prometheus {$POD_IP}:9153 forward . /etc/resolv.conf reload } consul.local:5353 { errors cache 30 proxy . 10.150.0.1 }
In clusters earlier than v1.15.11, the modified ConfigMap is as follows:
apiVersion: v1 data: Corefile: |- .:5353 { cache 30 errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream /etc/resolv.conf fallthrough in-addr.arpa ip6.arpa } loadbalance round_robin prometheus 0.0.0.0:9153 proxy . /etc/resolv.conf reload } consul.local:5353 { errors cache 30 proxy . 10.150.0.1 } kind: ConfigMap metadata: name: coredns namespace: kube-system
DNS policies can be set on a per-pod basis. Currently, Kubernetes supports four types of DNS policies: Default, ClusterFirst, ClusterFirstWithHostNet, and None. For details, see https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/. These policies are specified in the dnsPolicy field in the pod-specific.
Routing
Without stub domain configurations: Any query that does not match the configured cluster domain suffix, such as www.kubernetes.io, is forwarded to the upstream DNS server inherited from the node.
With stub domain configurations: If stub domains and upstream DNS servers are configured, DNS queries are routed according to the following flow:
Parameter |
Description |
---|---|
Add-on Specifications |
Concurrent domain name resolution ability. Select add-on specifications that best fit your needs. |
stub domain |
A domain name server for a user-defined domain name. The format is a key-value pair. The key is a suffix of DNS domain name, and the value is one or more DNS IP addresses. For example, acme.local -- 1.2.3.4,6.7.8.9 means that DNS requests with the .acme.local suffix are forwarded to a DNS listening at 1.2.3.4,6.7.8.9. |