In specific scenarios, you must manually manage and maintain CoreDNS due to the highly customized requirements of the business. Alibaba Cloud Container Compute Service (ACS) clusters support unmanaged CoreDNS. This allows you to configure custom CoreDNS configurations. This topic describes how to use the unmanaged CoreDNS plug-in in an ACS cluster.
Prerequisites
An ACS cluster is created. For more information, see Create an ACS cluster. If the CoreDNS plug-in is installed in the ACS cluster, uninstall the managed CoreDNS plug-in by following the installation procedure described in this topic.
-
When you create a new cluster, go to Component Configurations > Service Discovery and select Disable.
The unmanaged CoreDNS plug-in is an open-source standard plug-in. You are responsible for the resource costs and the O&M of the plug-in. You can resolve issues that may arise when your use the CoreDNS plug-in.
By default, the plug-in template provided by ACS uses the anti-affinity mechanism to distribute pods across zones. If you configured a single zone for ACS, only one replica of CoreDNS can run as expected. We recommend that you configure multiple zones to ensure disaster recovery and availability.
Installation procedure
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, click Add-ons.
-
(Optional) On the Networking tab, find CoreDNS (with a
Managedlabel) and click Uninstall. If you do not see CoreDNS (Managed) in the component list, skip this step.WarningIf you uninstall CoreDNS (Managed), the Domain Name System (DNS) resolution feature of the cluster is unavailable. Make sure that business traffic does not exist in the cluster before you uninstall CoreDNS (Managed).
-
On the Networking tab, find CoreDNS (without a
Managedlabel) and click Install. -
Configure the parameters based on your requirements. After you confirm the settings, click OK to install the component.
ImportantIf you do not set the CpuRequest parameter during installation, the corresponding pod in the ACS cluster will have only 250m of available CPU resources. We recommend that you set an appropriate value for CpuRequest to avoid cluster exceptions caused by excessive load on the pod.
The configuration form includes the following parameters: MemoryRequest (default:
100Mi), CpuRequest (default:100m), MemoryLimit (default:2Gi), and CpuLimit (default: empty). For NodeSelector, the default key iskubernetes.io/osand the value islinux. Tolerations is empty by default and can be configured as needed. Use kubectl to connect to the cluster and run the following command to query the pod:
kubectl get po -n kube-system|grep corednsExpected output:
NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-85dc775876-sh558 1/1 Running 0 3m35s kube-system coredns-85dc775876-xzcpp 1/1 Running 0 3m35sThe CoreDNS pod is started. This indicates that the unmanaged CoreDNS plug-in is installed.
-
Run the following command in a pod in the ACS cluster to check whether the DNS resolution feature in the cluster works as expected:
nslookup kubernetesExpected output:
Server: 10.0.0.10 Address: 10.0.0.10#53 Name: kubernetes.default.svc.cluster.local Address: 10.0.0.1The output indicates that the domain name resolution is successful and CoreDNS runs as expected.
Custom CoreDNS configurations
You can configure custom CoreDNS configurations by modifying the Corefile configurations, which is stored in the ACS cluster as a ConfigMap. You can directly modify the Corefile configurations to modify the CoreDNS configurations. Example:
Run the following command to modify the Corefile configurations of CoreDNS:
kubectl -n kube-system edit cm coredns-
Modify the Corefile configurations of CoreDNS based on the following content:
Corefile: | .:53 { errors health { lameduck 15s } ready kubeapi k8s_event { level info error warning } kubernetes cluster.local in-addr.arpa ip6.arpa { pods verified ttl 30 fallthrough in-addr.arpa ip6.arpa } prometheus :9153 # forward . /etc/resolv.conf { # Change the forward DNS server from the default in resolv.conf to 192.168.1.10. forward . 192.168.1.10 { prefer_udp } cache 30 log loop reload loadbalance }After the modification, CoreDNS automatically forwards non-cluster domain names to the DNS server whose IP address is
192.168.1.10. You can change the IP address of the DNS server based on your business requirements.
References
You can modify the configurations of the unmanaged CoreDNS plug-in based on your business requirements. For more information, see Configure unmanaged CoreDNS.
For more information about how to configure DNS policies and DNS resolution for pods in an ACS cluster, see DNS resolution policies and caching policies.
For more information about how to troubleshoot issues related to CoreDNS, see DNS troubleshooting.