1.控制平面组件特性门控
编辑如下路径 /etc/kubernetes/manifests/
的kube-apiserver.yaml, kube-controller-manager.yaml, kube-scheduler.yaml配置文件,在各自容器启动命令行参数添加配置项:
- --feature gates=InPlacePodVerticalScaling=true
2.kubelet 组件特性门控
配置/var/lib/kubelet/config.yaml
,加入featureGates:
apiVersion: kubelet.config.k8s.io/v1beta1
featureGates:
InPlacePodVerticalScaling: true
修改 configmap 形式的 kubelet 配置,featureGates同上:
kubectl -n kube-system edit configmaps kubelet-config
3.kubeproxy 组件特性门控
# kubectl -n kube-system edit configmaps kube-proxy
apiVersion: kubeproxy.config.k8s.io/v1alpha1
featureGates:
InPlacePodVerticalScaling: true
4.进行验证
创建一个pod资源
nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: default
spec:
containers:
- name: nginx
image: nginx
resizePolicy:
- resourceName: cpu
restartPolicy: NotRequired
- resourceName: memory
restartPolicy: NotRequired
resources:
limits:
memory: "200Mi"
cpu: "700m"
requests:
memory: "200Mi"
cpu: "700m"
通过kubectl apply -f nginx.yaml
创建后,通过执行patch命令,实现对pod资源动态调整:
0.7cpu->0.6cpu:
kubectl patch pod nginx --patch '{"spec":{"containers":[{"name":"nginx", "resources":{"requests":{"cpu":"600m"}, "limits":{"cpu":"600m"}}}]}}'
200Mi->500Mi:
kubectl patch pod nginx --patch '{ "spec" :{ "containers" :[{ "name" : "nginx" , "resources" :{"requests":{"memory":"500Mi"}, "limits" :{ "memory" : "500Mi" }}}]} }'
当未进行配置时,patch时可能会出现如下情况:
注意该项特性k8s版本要求1.27以上
k3s配置流程
编辑/etc/rancher/k3s/config.yaml
(没有的创建一个),加入以下配置项:
kubelet-arg:
- feature-gates=InPlacePodVerticalScaling=true
kube-apiserver-arg:
- feature-gates=InPlacePodVerticalScaling=true
重启集群即可
参考链接