磁盘空间不足导致k3s自动删除镜像

事件: 

在测试服务器中,磁盘只有500GB,但是这边测试比较频繁,导致磁盘发生不够的情况。发现很多docker镜像不见了。

结论: 

在k3s.service 文件的ExecStart位置中添加: 

   '--kubelet-arg=image-gc-high-threshold=100' \
    '--kubelet-arg=image-gc-low-threshold=99' \ 

 

如: 

ExecStart=/usr/local/bin/k3s \
    '--kubelet-arg=image-gc-high-threshold=100' \
    '--kubelet-arg=image-gc-low-threshold=99' \ 

 

验证过程: 

k3s-.1.24一下版本: 

在k3s.service 文件的ExecStart位置中添加:   (不添加将导致,无法访问服务器10250接口)

'--kubelet-arg=anonymous-auth=true' \
'--kubelet-arg=authorization-mode=AlwaysAllow' \

 

k3s-1.24 及以上版本: 

1. 创建调用接口用户

kubectl create serviceaccount monitor-user -n default 

2. 赋予制度权限   安全-可去除-看环境

kubectl create clusterrolebinding monitor-user-view \
  --serviceaccount=default:monitor-user \
  --clusterrole=view

3. 写一个yaml文件 1.24及以上必须执行   使用kubectl apply -f xxx.yaml 执行

apiVersion: v1
kind: Secret
metadata:
  name: monitor-user-token
  namespace: default
  annotations: 
    kubernetes.io/service-account.name: monitor-user
type: kubernetes.io/service-account-token

4. 获取token 

kubectl get secret monitor-user-token -n default -o jsonpath='{.data.token}' | base64 -d 

5. 使用postman访问服务器的地址:  https://xxx.xxx.x.xxx:10250/configz

header中配置 Authorization: Bear ${token}

可以看到对应的配置信息: 

"imageGCHighThresholdPercent" : 85 #这个就是磁盘达到85百分比的时候清理镜像
"imageGCLowThresholdPercent" : 80#这个就是磁盘达到80的时候不清理

 

posted @ 2026-01-09 16:51  沙师弟demo  阅读(2)  评论(0)    收藏  举报