在kubernetes中有一个组件是kubelet是用来对节点资源情况进行分析,达到一定条件会自动执行发出内存、磁盘、pid资源压力警告。在kubelet组件中目前只支持两个钟文件系统分区,分别是
-
Nodes :kubelet相关的文件系统,里面存储了pod挂载的卷,守护程序日志等。
-
imagefs:容器文件系统,里面存储了容器运行时用于保存镜像和容器可写层。
更多的内容可以看看官网信息,这里就不多叙述:https://kubernetes.io/zh-cn/docs/concepts/scheduling-eviction/node-pressure-eviction/
这里主要说一下如何操作,就使用磁盘空间驱逐做示例。默认kubernetes集群中是没有配置的,需要手动添加一下,如果是公有云一般都会有的,这个和版本没关系,是kubernetes的开源功能。默认在kubelet中是没有配置的,下面我随便找一个node节点配置一下。
[root@www.wulaoer.org ~]# cat /etc/sysconfig/kubelet KUBELET_EXTRA_ARGS= 修改成 KUBELET_EXTRA_ARGS= --eviction-hard=nodefs.available<45% --eviction-hard=imagefs.available<45%
-
--eviction-hard=nodefs.available<45% 设置当kubelet相关存储可用的存储不足45%时开始驱逐pod
-
-eviction-hard=imagefs.available<45%当容器运行时文件系统可用存储空间不足45%时开启驱逐pod
也就是我如果磁盘100g,不能超过55G,超过55Gkubelet组件就会自动清理。
修改好后需要重启一下kubelet,否则不生效。
[root@www.wulaoer.org ~]# systemctl daemon-reload && systemctl restart kubelet
重启之后,我先在节点上拉取几个镜像,无所谓什么镜像,随便拉取即可。
[root@www.wulaoer.org ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE debian oldstable-slim 6ff3996a9c34 4 days ago 80.5MB debian oldstable-backports 9946fb52acca 4 days ago 124MB python 3.9-bookworm 60d390c1959b 6 weeks ago 997MB python 3.9.17-bullseye 949d1a3d4400 7 weeks ago 906MB calico/node v3.20.6 daeec7e26e1f 12 months ago 156MB calico/pod2daemon-flexvol v3.20.6 39b166f3f936 12 months ago 18.6MB calico/cni v3.20.6 13b6f63a50d6 12 months ago 138MB calico/kube-controllers v3.20.6 4dc6e7685020 12 months ago 60.2MB python bullseye a5d7930b60cc 19 months ago 917MB python latest a5d7930b60cc 19 months ago 917MB debian latest 6f4986d78878 19 months ago 124MB registry.aliyuncs.com/google_containers/kube-proxy v1.23.1 b46c42588d51 19 months ago 112MB centos 7 eeb6ee3f44bd 22 months ago 204MB centos centos7 eeb6ee3f44bd 22 months ago 204MB centos centos7.9.2009 eeb6ee3f44bd 22 months ago 204MB centos centos8 5d0da3dc9764 22 months ago 231MB centos centos8.4.2105 5d0da3dc9764 22 months ago 231MB centos latest 5d0da3dc9764 22 months ago 231MB registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12 23 months ago 683kB centos 7.6.1810 f1cb7c7d58b7 4 years ago 202MB
镜像拉取完成,为了使我的磁盘空间快速达到55%,我就使用dd做文件。
[root@www.wulaoer.org ~]# dd if=/dev/zero of=7test.txt count=10 bs=512M ^C [root@www.wulaoer.org ~]# docker images | wc -l 21 [root@node1 ~]# dd if=/dev/zero of=8test.txt count=10 bs=512M 10+0 records in 10+0 records out 5368709120 bytes (5.4 GB) copied, 7.24461 s, 741 MB/s [root@www.wulaoer.org ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs 7.9G 783M 7.1G 10% /run tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup /dev/vda1 108G 55G 54G 51% / tmpfs 16G 12K 16G 1% /var/lib/kubelet/pods/51f47a02-2ef6-4521-92ab-55a4dd631b79/volumes/kubernetes.io~projected/kube-api-access-4wccb overlay 108G 55G 54G 51% /var/lib/docker/overlay2/7a9fb263dcd3bc27ec217d2c8d29ce2c046e3315c2b9773b9354edb5963bf213/merged shm 64M 0 64M 0% /var/lib/docker/containers/14f11067fe1d97dc02b4e6a59846ce02962686dde2bba5a5b89d71aa35211b3a/mounts/shm overlay 108G 55G 54G 51% /var/lib/docker/overlay2/8041db4934c9b1460a4951c7a1166c0b3bcf5db8e5fa836d37546a6488492134/merged tmpfs 16G 12K 16G 1% /var/lib/kubelet/pods/a6cc77a5-18e5-48b1-a52e-d9cbceea57da/volumes/kubernetes.io~projected/kube-api-access-qn7z4 tmpfs 16G 12K 16G 1% /var/lib/kubelet/pods/61885ac8-f758-4fd7-8c1b-a9b0ee9d5491/volumes/kubernetes.io~projected/kube-api-access-k4lrj overlay 108G 55G 54G 51% /var/lib/docker/overlay2/99d9575cb57c76b7f2364b4f3493a5170630ce00b23fd6cd2cbd76326d1f3342/merged shm 64M 0 64M 0% /var/lib/docker/containers/9d5e4d9f0b2149e15cb398c82c9f05b301945b89dda70ab8e63d04c786a143d0/mounts/shm overlay 108G 55G 54G 51% /var/lib/docker/overlay2/9d1d83921609a03aad53a5125764dc1b4635c8a23c8a9427e5a1700e66d9c716/merged overlay 108G 55G 54G 51% /var/lib/docker/overlay2/57cc20b321e1bdc2dfacc0a1eaa0de0516a61b4a07b5dd66b30b5f0027d351c2/merged shm 64M 0 64M 0% /var/lib/docker/containers/184423ffc782427109cb4ad564e33e063458b36831a48f5b51ac23999f7bbaf1/mounts/shm overlay 108G 55G 54G 51% /var/lib/docker/overlay2/e4177d70cc601e365cdd839d2a7b22e417611f4744731ff9682f36e8be7bf19c/merged tmpfs 1.6G 0 1.6G 0% /run/user/0
磁盘空间已经接近55%了,下面我们测试一下如果我在创建一个文件,镜像是否会有删除,我总共有21个镜像,看看添加一个文件后如果镜像文件有少就说明实验成功了。
[root@www.wulaoer.org ~]# dd if=/dev/zero of=9test.txt count=10 bs=512M 10+0 records in 10+0 records out 5368709120 bytes (5.4 GB) copied, 7.15412 s, 750 MB/s [root@www.wulaoer.org ~]# dd if=/dev/zero of=10test.txt count=10 bs=512M 10+0 records in 10+0 records out 5368709120 bytes (5.4 GB) copied, 18.1444 s, 296 MB/s [root@www.wulaoer.org ~]# docker images | wc -l 19 [root@www.wulaoer.org ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE calico/node v3.20.6 daeec7e26e1f 12 months ago 156MB calico/pod2daemon-flexvol v3.20.6 39b166f3f936 12 months ago 18.6MB calico/cni v3.20.6 13b6f63a50d6 12 months ago 138MB calico/kube-controllers v3.20.6 4dc6e7685020 12 months ago 60.2MB registry.aliyuncs.com/google_containers/kube-proxy v1.23.1 b46c42588d51 19 months ago 112MB registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12 23 months ago 683kB
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏