Skip to content

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

  1. After filling in all desired configuration via the Cluster Configuration form, click Edit as YAML on the bottom section of the page.
  2. 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
[...]
3. Then click Create to create the cluster.

Configuration after initial cluster creation

  1. Navigate to Cluster Management
  2. Click Edit Config for the desired downstream cluster
  3. Click Edit as YAML
  4. 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
[...]
5. Click Save to update the cluster with the new CPU Manager Policy. 6. The cluster will transition to an Updating status, and the cluster's nodes will get stuck in a Reconciling state with the message "Waiting for probes: kubelet" 7. When a node enters this state, open an SSH session to it, and remove the old CPU Manager state file:

# rm -rf /var/lib/kubelet/cpu_manager_state
8. The node will then complete reconciling successfully. 9. Repeat step 6 until all the nodes are successfully reconciled and the cluster returns to an Active 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:

  1. Drain the node
  2. Stop the RKE2 or K3s processes:

  3. On RKE2 server nodes run systemctl stop rke2-server and rke2-killall.sh

  4. On RKE2 worker nodes run systemctl stop rke2-agent and rke2-killall.sh
  5. On K3s server nodes run systemctl stop k3s and k3s-killall.sh
  6. On K3s agent nodes runsystemctl stop k3s-agentand k3s-killall.sh
  7. Remove the CPU Manager state file: rm -rf /var/lib/kubelet/cpu_manager_state
  8. 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
5. Start the RKE2 or K3s service:

  1. On RKE2 server nodes run systemctl start rke2-server
  2. On RKE2 agent nodes run systemctl start rke2-agent
  3. On K3s server nodes run systemctl start k3s
  4. On K3s agents nodes run systemctl start k3s-agent