How to adjust the number of replicas for RKE2 CoreDNS
Article Number: 000021893
Environment
A Rancher-provisioned or standalone RKE2 cluster.
Situation
You want to adjust the number of CoreDNS replicas in the RKE2 cluster.
Resolution
RKE2 manages the number of CoreDNS Pods automatically through the rke2-coredns-autoscaler. Therefore, manually changing the replica count of the CoreDNS Deployment will be automatically overwritten and reverted to a pre-calculated value.
Steps
To apply the changes to the default CoreDNS deployment in RKE2, configure the appropriate helm values with a HelmChartConfig.
- For standalone RKE2 clusters, add the HelmChartConfig to each rke2-server (control plane) node as a .yaml file in the /var/lib/rancher/rke2/server/manifests directory
- For RKE2 clusters provisioned by Rancher, add the HelmChartConfig content when editing the cluster in Cluster Management. Paste/edit the content under Cluster Configuration > Additional Manifest and save
Examples
Configure minimum/maximum number of Pods:
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-coredns
namespace: kube-system
spec:
valuesContent: |
autoscaler:
min: 5
max: 10
Based on the number of nodes (one Pod per node):
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-coredns
namespace: kube-system
spec:
valuesContent: |
autoscaler:
nodesPerReplica: 1
Based on CPU cores (one Pod for every 6 cores):
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-coredns
namespace: kube-system
spec:
valuesContent: |
autoscaler:
coresPerReplica: 6
Note node-local-dns can also be an alternative to scaling the CoreDNS pods, as node-local-dns will start a pod on each node and provide other benefits