# more /lib/systemd/system/kubelet.service --cpu-manager-policy=static \ --kube-reserved=cpu=200m,memory=1Gi,ephemeral-storage=1Gi \ --system-reserved=cpu=200m,memory=1G \
二、如何使用 Pod 必须是 Guaranteed 的 QoS 类型 Pod中该Container的Cpu request必须为整数CPUs 三、实例
# more deploy1.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 4 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 resources: limits: memory: "200Mi" cpu: "2" requests: memory: "200Mi" cpu: "2"效果查看
# docker ps|grep nginx 7bead158cbf5 84581e99d807 "nginx -g 'daemon of…" 27 seconds ago Up 27 seconds k8s_nginx_nginx-deployment-c585c6cf8-22x5h_default_3babe9d2-e085-11eb-9b5a-fa163e1b0c2f_0 ab63ab8d72b3 mirrorgooglecontainers/pause-amd64:3.0 "/pause" 28 seconds ago Up 27 seconds k8s_POD_nginx-deployment-c585c6cf8-22x5h_default_3babe9d2-e085-11eb-9b5a-fa163e1b0c2f_0 # cd /sys/fs/cgroup/cpuset/kubepods/pod3babe9d2-e085-11eb-9b5a-fa163e1b0c2f/7bead158cbf532e325fc3c57afe77fda026b32b5eb0dc9ced509e2e3834df35f/ # more cpuset.cpus 1-2 //绑定在cpu1-2 # more cpuset.mems 0
四、报错处理
报错:configured policy "static" differs from state checkpoint policy "none" # kubectl get node NAME STATUS ROLES AGE VERSION 10.30.20.106 Ready <none> 8d v1.14.4 10.30.20.119 Ready <none> 47h v1.14.4 10.30.20.129 Ready <none> 8d v1.14.4 10.30.20.94 Ready <none> 8d v1.14.4 # kubectl drain 10.30.20.94 --ignore-daemonsets # mv /var/lib/kubelet/cpu_manager_state /var/lib/kubelet/cpu_manager_state-old # kubectl uncordon minikube # kubectl uncordon 10.30.20.94 node/10.30.20.94 uncordoned # systemctl daemon-reload # systemctl restart kubelet # systemctl status kubelet # more /var/lib/kubelet/cpu_manager_state-old {"policyName":"none","defaultCpuSet":"","checksum":3242152201}
参考文档:
https://cloud.tencent.com/developer/article/1402119 https://www.alibabacloud.com/blog/kubernetes-cpu-management-policies_595205