当前位置: 首页 > news >正文

实验kubernetes的CPU绑定策略

CPU 管理配置

CPU 管理策略通过 kubelet 参数 --cpu-manager-policy 或 KubeletConfiguration 中的 cpuManagerPolicy 字段来指定。 支持两种策略:

  • none:默认策略。
  • static:允许为节点上具有某些资源特征的 Pod 赋予增强的 CPU 亲和性和独占性。

更改 CPU 管理器策略

以minikube为例,修改kubelet配置:

1、添加配置:

kubectl edit configmaps kubelet-config -n kube-system

    cpuManagerPolicy: static
    kubeReserved: {cpu: 100m, memory: 100Mi}

2、在节点机器删除 rm /var/lib/kubelet/cpu_manager_state

3、重启kubelet。

4、观察是否启动成功:

systemctl status kubelet

journalctl -f

5、查看 /var/lib/kubelet/cpu_manager_state 是否变化,如:

cat /var/lib/kubelet/cpu_manager_state
{"policyName":"static","defaultCpuSet":"0-3","checksum":611748604}

设置pod绑定cpu核数

1、绑定cpu的pod配置(Guaranteed Pod):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 100%
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: docker.io/nginx:1.27.0
          imagePullPolicy: Never
          resources:
            requests:
              cpu: 1
              memory: "50Mi"
            limits:
              cpu: 1
              memory: "50Mi"
          ports:
            - name: http
              containerPort: 80
      terminationGracePeriodSeconds: 6

2、没有绑定cpu的pod配置(非Guaranteed Pod):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 100%
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
        - name: myhello
          image: docker.io/library/myhello:v1.4
          imagePullPolicy: Never
          ports:
            - name: http
              containerPort: 8000
      terminationGracePeriodSeconds: 6

3、先后部署hello和nginx:

kubectl apply -f hello-deployment-rs2.yaml

kubectl apply -f nginx-deployment-rs2.yaml

观察cpu绑定效果

1、只部署hello后的绑定情况:

docker ps | grep hello

docker inspect fa0c12f34ae5 | grep -i pid

taskset -pc 94245

pid 94245's current affinity list: 0-3

2、然后继续部署nginx容器的绑定情况:

docker ps | grep nginx
docker inspect 0d42e09a0f56 | grep -i pid
taskset -pc 59820
pid 59820's current affinity list: 1

2、查看hello容器的cpu绑定情况:

taskset -pc 94245
pid 94245's current affinity list: 0,2,3

3、查看kubelet的cpu_manager_state:

cat /var/lib/kubelet/cpu_manager_state

{"policyName":"static","defaultCpuSet":"0,2-3","entries":{"9268f4b8-bf6c-4910-9f3a-a9ac879ffc60":{"nginx":"1"}},"checksum":1987962493}

4、删除nginx容器:

kubectl delete -f nginx-deployment-rs2.yaml

5、再次查看kubelet的cpu_manager_state:

cat /var/lib/kubelet/cpu_manager_state

{"policyName":"static","defaultCpuSet":"0,2-3","entries":{"9268f4b8-bf6c-4910-9f3a-a9ac879ffc60":{"nginx":"1"}},"checksum":1987962493}

6、再次查看hello的cpu绑定状态:

taskset -pc 94245
pid 94245's current affinity list: 0,2,3

hello使用的cpu并没有变化,依然只能使用3个核。

7、删除hello并再次部署hello:

kubectl delete -f hello-deployment-rs2.yaml

kubectl apply -f hello-deployment-rs2.yaml

8、观察hello的cpu绑定情况:

#hello:

taskset -pc 91704
pid 91704's current affinity list: 0-3

hello恢复调度所有cpu。

9、再次查看kubelet的cpu_manager_state:

cat /var/lib/kubelet/cpu_manager_state
{"policyName":"static","defaultCpuSet":"0-3","checksum":611748604}

实验结论:

1、虽然设置了static调度模式,但是只要不部署独占cpu的pod即Guaranteed Pod,其他pod都可以在所有cpu上调度。

2、Guaranteed Pod部署后,非Guaranteed Pod会动态腾出cpu核心供Guaranteed Pod独占。

3、节点内的cpu已存在被Guaranteed Pod绑定核心后,只有在独占cpu核心的Guaranteed Pod全部退出后,然后其他pod重新部署后才能恢复其他pod在所有cpu上的调度。

--end--

http://www.lryc.cn/news/460794.html

相关文章:

  • Zsh 安装与配置
  • Redis可视化工具Redis Desktop Manager(附安装包)
  • sql server删除过期备份文件脚本
  • 【Docker系列】Docker查看镜像架构
  • Python案例 | 测试网络的下载速度上传速度和 ping 延迟
  • 一键找回,2024四大固态硬盘数据恢复工具推荐!
  • 数据结构~AVL树
  • ffmpeg面向对象——rtsp拉流探索(1)
  • 【启明智显分享】ZX7981PM WIFI6 5G-CPE:2.5G WAN口,2.4G/5G双频段自动调速
  • openresty“热部署“lua
  • 基于SpringBoot+Vue+MySQL的企业招聘管理系统
  • vue3之defineComponent
  • springboot+vue家政服务管理平台
  • python pip安装requirements.txt依赖与国内镜像
  • 解决Qt的QWidget设计师编辑UI后和软件运行显示不一致
  • 交易所开发:构建安全、高效、可靠的数字资产交易平台
  • 【Next.js 入门教程系列】09-优化技巧
  • Windows 11 开发详解:工具与高级用法
  • leetcode 292.Nim游戏
  • 《最优化方法》
  • fork中的死锁问题
  • Java面试题———SpringBoot篇
  • 模块化沙箱:构建零信任架构的关键技术
  • 10.14学习日志
  • “我们为什么缺少科学精神”演讲内容拆解
  • openpyxl 3.0.7 中文教程
  • idea开发工具使用
  • Android map 获取值
  • Leetcode.13 罗马数字转整数
  • 骨架提取(持续更新)