k8s中的多pod节点动态控制资源倾斜给其中某一个pod

以nginx-test-limit1,nginx-test-limit2为例
1,查出容器id
kubectl describe pod nginx-test-limit1

2,容器id:3b4a485c589176227157cf394e31f8d4962a7700d1585f58002356ce9affb061

2,通过容器id查到Cgroup的路径:
docker inspect 3b4a485c5891|grep Cgroup

3,进入容器的cpu配置文件目录:
/sys/fs/cgroup/cpu/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod6fb1f21d_c7ab_4d2f_a621_daea4f8aa113.slice

4,cpu配额文件cpu.cfs_quota_us,默认为-1

5,将cpu.cfs_quota_us修改成30%cpu配额,不需要重启pod:
echo 30000 > cpu.cfs_quota_us

此时nginx-test-limit1的cpu使用率不超过30%
nginx-test-limit2的cpu使用率在150%左右

6,将nginx-test-limit的cpu配额文件cpu.cfs_quota_us,改回为-1,不需要重启pod:
echo -1 > cpu.cfs_quota_us

此时nginx-test-limit1资源在50%-120%之间浮动
nginx-test-limit2资源同样在50%-120%之间浮动

7,提高cpu使用率脚本:
#! /bin/sh
stop()
{
echo “”
}
start()
{
for i in seq $1
do
echo "
i=0;
while true
do
i=i+1;
done" | /bin/sh &
echo $! >> pid.txt
done
}
case $1 in
stop)
stop
;;
*)
start $1
;;
Esac

8,pod编排文件:
1,nginx-test-limit1:
apiVersion: v1
kind: Pod
metadata:
name: nginx-test-limit1
annotations:
lwt1: add
labels:
app: nginx-test-limit1
spec:
nodeName: moss-node48
containers:

  • name: nginx-test-limit1
    image: harbor.com/library/nginx:1.23
    command: [“/bin/sleep”,“infinity”]
    imagePullPolicy: IfNotPresent
    #resources:

    limits:

    #cpu: "3000m"
    #memory: "100Mi"
    
    #requests:
    #cpu: “1000m”
    #memory: “100Mi”
    ports:
    - containerPort: 180
    priorityClassName: high-priority-nonpreempting

2,nginx-test-limit2
apiVersion: v1
kind: Pod
metadata:
name: nginx-test-limit2
annotations:
lwt1: add
labels:
app: nginx-test-limit2
spec:
nodeName: moss-node48
containers:

  • name: nginx-test-limit2
    image: harbor.com/library/nginx:1.23
    command: [“/bin/sleep”,“infinity”]
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 181
    priorityClassName: second-nonpreempting
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值