您现在的位置是:首页 >其他 >k8s 1.27新特性in-place使用方法:避坑指南(官方文档有坑,已提issue)网站首页其他
k8s 1.27新特性in-place使用方法:避坑指南(官方文档有坑,已提issue)
简介k8s 1.27新特性in-place使用方法:避坑指南(官方文档有坑,已提issue)
背景
按照官方文档试用新版的in-place特性时,一字不差地执行了,但是却出现了执行失败的情况:
- 执行
kubectl -n qos-example patch pod qos-demo-5 --patch '{"spec":{"containers":[{"name":"qos-demo-ctr-5", "resources":{"requests":{"cpu":"800m"}, "limits":{"cpu":"800m"}}}]}}'
后该pod一直处于RunContainerError
状态; - 使用
kubectl describe
查看详情,eventlog如下:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m41s default-scheduler Successfully assigned qos-example/qos-demo-5 to 172.30.94.201
Normal Pulled 2m38s kubelet Successfully pulled image "nginx" in 2.468850418s (2.468866698s including waiting)
Normal Started 2m38s kubelet Started container qos-demo-ctr-5
Normal Killing 27s kubelet Container qos-demo-ctr-5 definition changed, will be restarted
Normal Pulled 25s kubelet Successfully pulled image "nginx" in 2.412743103s (2.412766469s including waiting)
Normal Pulled 22s kubelet Successfully pulled image "nginx" in 2.484909047s (2.484925388s including waiting)
Normal Pulling 9s (x4 over 2m41s) kubelet Pulling image "nginx"
Normal Created 7s (x4 over 2m38s) kubelet Created container qos-demo-ctr-5
Warning Failed 7s (x3 over 25s) kubelet Error: failed to start container "qos-demo-ctr-5": Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error setting cgroup config for procHooks process: failed to write "80000": write /sys/fs/cgroup/cpu,cpuacct/kubepods.slice/kubepods-poda24bc212_b6c2_4fd4_af47_111b6b937b10.slice/qos-demo-ctr-5/cpu.cfs_quota_us: invalid argument: unknown
Normal Pulled 7s kubelet Successfully pulled image "nginx" in 2.314366627s (2.314379589s including waiting)
- 可以看到是修改cgroup限制时失败,参数不对,因此第一反应是docker、k8s、linux内核及cgroup版本不一致导致某接口参数格式不一致,所以报此错误,全部升级到要求版本后仍未解决;
- 给官方提了issue,很智障的是他们说自己的文档忘了写事前准备导致执行不了,thanks me后,我再问就让我去别的地方提问,修复日期和方法也不说,无语;
- 开始自己挖掘,解决方法如下
解决办法
- 在master节点执行
vim /etc/kubernetes/manifests/kube-apiserver.yaml
,在command
下添加--feature-gates=InPlacePodVerticalScaling=true
,等待apiserver自动重启完成; - 在所有的node都执行一遍:
(1)执行/var/lib/kubelet/kubeadm-flags.env
,在末尾添加/var/lib/kubelet/kubeadm-flags.env
;
(2)执行systemctl restart kubelet
;
(3)执行systemctl status kubelet
,状态变为active (running)
后操作结束;
(4)对所有node重复上述操作;
后续操作
完成上述事前准备后,就可以按照官方文档玩耍了
另外k8s 1.27版本搭建可以看这篇文章,我按照他的方法一步步执行,基本没踩到坑
参考资料:
(1)https://stackoverflow.com/questions/52416671/kubelet-configuration
(2)https://stackoverflow.com/questions/59814862/how-do-you-enable-feature-gates-in-k8s
(3)https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
(4)https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。