How to configure cpu-manager-policy in an RKE2 or K3s cluster
Article Number: 000022055
Environment
- A Rancher-provisioned or standalone RKE2 or K3s cluster
Procedure
This article details how to configure Kubernetes CPU Manager Policy in an RKE2 or K3s cluster. The policy is configured via the kubelet --cpu-manager-policy flag, alongside the related --kube-reserved, --system-reserved, --reserved-cpus and --cpu-manager-policy-options flags.
Rancher-provisioned RKE2 or K3s clusters
Configuration at cluster creation time
- After filling in all desired configuration via the Cluster Configuration form, click Edit as YAML on the bottom section of the page.
- Add the required kubelet-arg flags into the machineGlobalConfig block under rkeConfig, per the following example:
[...]
spec:
[...]
rkeConfig:
[...]
machineGlobalConfig:
kubelet-arg:
- cpu-manager-policy=static
- system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
[...]
Configuration after initial cluster creation
- Navigate to Cluster Management
- Click Edit Config for the desired downstream cluster
- Click Edit as YAML
- Add the required kubelet-arg flags into the machineGlobalConfig block under rkeConfig, per the following example:
[...]
spec:
[...]
rkeConfig:
[...]
machineGlobalConfig:
kubelet-arg:
- cpu-manager-policy=static
- system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
[...]
# rm -rf /var/lib/kubelet/cpu_manager_state
Standalone RKE2 or K3s clusters
Configuration at cluster creation time
The required kubelet flags should be defined in the RKE2 or K3s configuration file on each node, before starting the rke2-server, rke2-agent or k3s service for the first time, e.g.:
kubelet-arg:
- cpu-manager-policy=static
- system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
Configuration after initial cluster creation
You can perform the configuration update on each node in the cluster, following the process outlined in the Kubernetes CPU Manager Policy documentation:
- Drain the node
-
Stop the RKE2 or K3s processes:
-
On RKE2 server nodes run
systemctl stop rke2-serverandrke2-killall.sh - On RKE2 worker nodes run
systemctl stop rke2-agentandrke2-killall.sh - On K3s server nodes run
systemctl stop k3sandk3s-killall.sh - On K3s agent nodes run
systemctl stop k3s-agentandk3s-killall.sh - Remove the CPU Manager state file:
rm -rf /var/lib/kubelet/cpu_manager_state - Define the required kubelet flags in the RKE2 or K3s configuration file on the node, e.g.:
kubelet-arg:
- cpu-manager-policy=static
- system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
- On RKE2 server nodes run
systemctl start rke2-server - On RKE2 agent nodes run
systemctl start rke2-agent - On K3s server nodes run
systemctl start k3s - On K3s agents nodes run
systemctl start k3s-agent