Environment  环境
  • A Rancher-provisioned or standalone RKE2 or K3s cluster
    Rancher 配置或独立的 RKE2 或 K3s 集群
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.
本文详细介绍了如何在 RKE2 或 K3s 集群中配置 Kubernetes CPU Manager Policy。该策略通过 kubelet --cpu-manager-policy 标志进行配置,同时还包括相关的 --kube-reserved、--system-reserved、--reserved-cpus 和 --cpu-manager-policy-options 标志。

Rancher-provisioned RKE2 or K3s clusters
牧场配置 RKE2 或 K3s 集群

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.
    在通过集群配置表单填写所有所需配置后,点击页面底部的“ 编辑为 YAML”。
  2. Add the required kubelet-arg flags into the machineGlobalConfig block under rkeConfig, per the following example:
    按照以下示例,在 rkeConfig 下的 machineGlobalConfig 块中添加所需的 kubelet-arg 标志:
    <span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>[...]
    spec:
      [...]
      rkeConfig:
        [...]
        machineGlobalConfig:
          kubelet-arg:
            - cpu-manager-policy=static
            - system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
    [...]</code></span></span></span>
  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
    点击编辑为 YAML 代码
  4. Add the required kubelet-arg flags into the machineGlobalConfig block under rkeConfig, per the following example:
    按照以下示例,在 rkeConfig 下的 machineGlobalConfig 块中添加所需的 kubelet-arg 标志:
    <span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>[...]
    spec:
      [...]
      rkeConfig:
        [...]
        machineGlobalConfig:
          kubelet-arg:
            - cpu-manager-policy=static
            - system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
    [...]</code></span></span></span>
  5. Click Save to update the cluster with the new CPU Manager Policy.
    点击保存以更新集群,使用新的 CPU 管理器策略。
  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"
    集群将切换为更新状态,节点会卡在“Reconciling”状态,提示“等待探针:kubelet”
  7. When a node enters this state, open an SSH session to it, and remove the old CPU Manager state file:
    当节点进入该状态时,打开一个 SSH 会话,并删除旧的 CPU 管理器状态文件:
    <span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code># rm -rf /var/lib/kubelet/cpu_manager_state</code></span></span></span>
  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.
    重复步骤6,直到所有节点成功对账,集群恢复为活跃状态。

Standalone RKE2 or K3s clusters
独立的 RKE2 或 K3s 集群

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.:
在首次启动 rke2 服务器、rke2 代理或 k3s 服务之前,应在每个节点的 RKE2 或 K3s 配置文件中定义所需的 kubelet 标志,例如:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>kubelet-arg:
  - cpu-manager-policy=static
  - system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi

</code></span></span></span>

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:
你可以按照 Kubernetes CPU Manager 策略文档中描述的流程 ,对集群中的每个节点进行配置更新:

  1. Drain the node  排空节点
  2. Stop the RKE2 or K3s processes:
    停止 RKE2 或 K3s 进程:
    1. On RKE2 server nodes run systemctl stop rke2-server and rke2-killall.sh
      在 RKE2 服务器节点上运行 systemctl,stop rke2-server 和 rke2-killall.sh
    2. On RKE2 worker nodes run systemctl stop rke2-agent and rke2-killall.sh
      在 RKE2 上,工作节点运行 systemctl、stop rke2-agent 和 rke2-killall.sh
    3. On K3s server nodes run systemctl stop k3s and k3s-killall.sh
      在 K3s 服务器节点上运行 systemctl,停止 k3s 和 k3s k3s-killall.sh
    4. On K3s agent nodes run systemctl stop k3s-agent and k3s-killall.sh
      在 K3s 上,代理节点运行 systemctl、stop k3s-agent 和 k3s-killall.sh
  3. Remove the CPU Manager state file: rm -rf /var/lib/kubelet/cpu_manager_state
    移除 CPU 管理器状态文件: rm -rf /var/lib/kubelet/cpu_manager_state
  4. Define the required kubelet flags in the RKE2 or K3s configuration file on the node, e.g.:
    在节点上的 RKE2 或 K3s 配置文件中定义所需的 kubelet 标志 ,例如:
    <span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>kubelet-arg:
      - cpu-manager-policy=static
      - system-reserved=cpu=1,memory=1548Mi,ephemeral-storage=30Gi
    
    </code></span></span></span>
  5. Start the RKE2 or K3s service:
    启动 RKE2 或 K3s 服务:
    1. On RKE2 server nodes run systemctl start rke2-server
      在 RKE2 服务器节点上运行 systemctl start rke2-server
    2. On RKE2 agent nodes run systemctl start rke2-agent
      在 RKE2 代理节点上运行 systemctl start rke2-agent
    3. On K3s server nodes run systemctl start k3s
      在 K3s 上,服务器节点运行 systemctl start k3s
    4. On K3s agents nodes run systemctl start k3s-agent

访问Rancher-K8S解决方案博主,企业合作伙伴 :
https://blog.csdn.net/lidw2009

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐