CoreDNS
Introduction
The CoreDNS add-on is a DNS server that provides domain name resolution for Kubernetes through chained plugins.
CoreDNS is a CNCF-incubated, open-source cloud-native DNS server designed for service discovery. Its plugin chain architecture enables modular, on-demand functionality with high efficiency and flexible configuration. In Kubernetes clusters, CoreDNS automatically discovers services and provides internal DNS resolution. Additionally, by forwarding to cloud-based DNS servers, it resolves external domains for cluster workloads.
This add-on is installed by default during cluster creation.
Kubernetes backs 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
Constraints
To run CoreDNS properly or to upgrade it, ensure that all CoreDNS pods are running. Otherwise, the add-on will malfunction or the upgrade will fail.
Editing the Add-on
This add-on is installed by default. To modify its settings, perform the following steps:
- Log in to the CCE console, click the cluster name to go to the cluster console, choose Add-ons in the navigation pane, find the CoreDNS add-on on the right, and click Edit.
- On the Edit Add-on slide-out panel, view the specifications.
You can adjust the number of add-on pods and resource quotas as needed. CoreDNS QPS is positively correlated with CPU consumption. As the number of containers in the cluster increases, the CoreDNS workload increases accordingly. Adjust the number of add-on pods and their CPU and memory quotas based on the cluster scale.
- Modify the parameters.
Table 1 CoreDNS add-on parameters Parameter
Description
Stub Zone (Optional)
A domain name server for a custom domain name. The format is a key-value pair. The key is a domain name suffix, and the value is one or more DNS IP addresses, for example, acme.local -- 1.2.3.4,6.7.8.9.
For details, see Configuring the Stub Domain for CoreDNS.
(Optional) Extended Parameter Settings
- parameterSyncStrategy: indicates whether to configure a consistency check when the add-on is upgraded.
- ensureConsistent: indicates that the configuration consistency check is enabled. If the delivered configuration differs from the current configuration, the current configuration will be replaced. However, if the delivered configuration is the same as the current configuration, the current configuration will be preserved. The ensureConsistent parameter ensures the configuration consistency. If a ConfigMap is modified manually, the add-on cannot be upgraded. In such cases, you will need to use the force or inherit policy to upgrade the add-on.
- force: indicates that the configuration consistency check is ignored during an upgrade. If the configuration delivered during an add-on upgrade is identical to the configuration before the upgrade, the ConfigMap will not be updated and the effective configuration will remain unchanged. If the configuration is modified during an add-on upgrade, the new configuration delivered with the upgrade is applied. It is important to ensure that the configuration delivered during the add-on upgrade matches the current effective configuration. After the add-on is upgraded, you need to restore the value of parameterSyncStrategy to ensureConsistent to enable the configuration consistency check again.
- inherit: If the configuration provided during the add-on upgrade differs from the current effective configuration, the current effective configuration will be used instead. After the add-on is upgraded, the value of parameterSyncStrategy is automatically restored to ensureConsistent to enable the configuration consistency check again. CAUTION:
After the automatic inheritance of parameter settings (parameterSyncStrategy=inherit) is enabled, stub domain settings will be merged into the extended parameter settings. The original stub domain settings remain unchanged and can still be viewed under Extended Parameter Settings.
- stub_domains: indicates the subdomains, which allow you to configure a domain name server for a custom domain name. A subdomain is in the format of a key-value pair, where the key is the suffix of a DNS domain name and the value is one or more DNS IP addresses.
- upstream_nameservers: indicates the IP address of the upstream DNS server.
- servers: indicates the name servers, which are available in CoreDNS v1.23.1 and later versions. You can customize nameservers. For details, see dns-custom-nameservers. plugins indicates the configuration of each component in CoreDNS. Typically, the default settings are retained to prevent CoreDNS from being unavailable due to configuration errors. Each plugin component contains name, parameters (optional), and configBlock (optional). The format of the generated Corefile is as follows:
$name $parameters { $configBlock }Table 2 describes common plugins. For details, see Plugins.
Example:
{ "servers": [ { "plugins": [ { "name": "bind", "parameters": "{$POD_IP}" }, { "name": "cache", "parameters": 30 }, { "name": "errors" }, { "name": "health", "parameters": "{$POD_IP}:8080" }, { "name": "ready", "{$POD_IP}:8081" }, { "configBlock": "pods insecure\nfallthrough in-addr.arpa ip6.arpa", "name": "kubernetes", "parameters": "cluster.local in-addr.arpa ip6.arpa" }, { "name": "loadbalance", "parameters": "round_robin" }, { "name": "prometheus", "parameters": "{$POD_IP}:9153" }, { "configBlock": "policy random", "name": "forward", "parameters": ". /etc/resolv.conf" }, { "name": "reload" } ], "port": 5353, "zones": [ { "zone": "." } ] } ], "stub_domains": { "acme.local": [ "1.2.3.4", "6.7.8.9" ] }, "upstream_nameservers": ["8.8.8.8", "8.8.4.4"] }
Table 2 Default plugin configuration of the active CoreDNS zone Plugin Name
Description
bind
Host IP address listened to by CoreDNS. Retain the default value {$POD_IP}. For details, see bind.
cache
Enables DNS cache. For details, see cache.
If the add-on version is v1.25.10 or later, SERVFAIL caching can be disabled. To disable SERVFAIL caching, set configBlock to servfail 0. Otherwise, the unit of SERVFAIL caching is second and cannot be omitted.
errors
Errors are logged to stdout. For details, see errors.
health
Health check for CoreDNS. {$POD_IP}:8080 is listened on. Retain the default setting. Otherwise, the CoreDNS health check will fail and the add-on will restart repeatedly. For details, see health.
ready
Check whether the backend server is ready to receive traffic. {$POD_IP}:8081 is listened on. If the backend server is not ready, CoreDNS will suspend DNS resolution until the backend server is ready. For details, see ready.
kubernetes
CoreDNS Kubernetes plugin, which provides the service parsing capability in a cluster. For details, see kubernetes.
loadbalance
Round-robin DNS load balancer that randomizes the order of A, AAAA, and MX records in an answer. For details, see loadbalance.
prometheus
API for obtaining CoreDNS metrics. By default, {$POD_IP}:9153 is listened on. Retain the default setting. Otherwise, Prometheus cannot collect CoreDNS metrics. For details, see Prometheus.
forward
Forwards any queries that are not within the cluster domain of Kubernetes to the predefined resolvers (/etc/resolv.conf). For details, see forward.
reload
Automatically reloads modified Corefiles. After you modify a ConfigMap, wait for two minutes for the modification to take effect. For details, see reload.
log
Enables CoreDNS logging. For details, see log.
Example:
{ "name": "log" }template
A quick response template, where AAAA indicates an IPv6 request. If NXDOMAIN is returned in an rcode response, no IPv6 resolution result is returned. For details, see Template.
Example:
{ "configBlock": "rcode NXDOMAIN", "name": "template", "parameters": "ANY AAAA" } - parameterSyncStrategy: indicates whether to configure a consistency check when the add-on is upgraded.
- Click OK.
Components
| Component | Description | Resource Type |
|---|---|---|
| CoreDNS | DNS server for clusters | Deployment |
How Does Domain Name Resolution Work in Kubernetes?
DNS policies can be configured for each pod. Kubernetes supports DNS policies Default, ClusterFirst, ClusterFirstWithHostNet, and None. For details, see DNS for Services and Pods. These policies are specified in the pod-specific dnsPolicy field.
- Default: Pods inherit the name resolution configuration from the subnet where they run. The custom upstream DNS servers and the stub domains cannot be used together with this policy.
- ClusterFirst: Any DNS query that does not match the configured cluster domain suffix, such as www.kubernetes.io, is forwarded to the upstream name server inherited from the subnet where the pods run. Cluster administrators may have extra stub domains and upstream DNS servers configured.
- ClusterFirstWithHostNet: For pods running with hostNetwork, use ClusterFirstWithHostNet.
- None: This allows a pod to ignore DNS settings from the Kubernetes environment. All DNS settings should be provided using the dnsPolicy field in dnsConfigPod.
- Clusters of Kubernetes v1.10 and later support Default, ClusterFirst, ClusterFirstWithHostNet, and None. Clusters earlier than Kubernetes v1.10 support only Default, ClusterFirst, and ClusterFirstWithHostNet.
- Default is not the default DNS policy. If dnsPolicy is not explicitly specified, ClusterFirst is used by default.
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 pod's subnet.
With stub domain configurations: If stub domains and upstream DNS servers are configured, DNS queries are routed according to the following flow:
- The query is first sent to the DNS caching layer in CoreDNS.
- From the caching layer, the suffix of the request is examined and then the request is forwarded to the corresponding DNS:
- Names with the cluster suffix, for example, .cluster.local: The request is sent to CoreDNS.
- Names with the stub domain suffix, for example, .acme.local: The request is sent to the configured custom DNS resolver that listens, for example, on 1.2.3.4.
- Names that do not match the suffix (for example, widget.com): The request is forwarded to the upstream DNS.
Release History
| Add-on Version | Supported Cluster Version | New Feature | Community Version |
|---|---|---|---|
| 1.32.6 |
| Supported CCE Autopilot clusters v1.36. | |
| 1.32.4 |
| Supported CCE Autopilot clusters v1.35. | |
| 1.32.3 |
| Supported CCE Autopilot clusters v1.34. | |
| 1.32.1 |
| Supported CCE Autopilot clusters v1.32. | |
| 1.28.11 |
| Supported CCE Autopilot clusters v1.31. | |
| 1.28.10 |
| Supported CCE Autopilot clusters v1.31. | |
| 1.28.9 |
| Fixed some issues. | |
| 1.28.8 |
| Performed a regular upgrade of add-on dependencies. | |
| 1.28.7 |
| Performed a regular upgrade of add-on dependencies. | |
| 1.28.6 |
| Fixed some issues. |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot