在安装k8s集群时,没有更改docker的data目录,使用的是默认路径/var/lib/docker

导致的问题是,随着镜像的使用增多,/var/lib/docker的使用越来越大,而默认情况下,/var路径下磁盘空间是很小的,通常需要挂载新的数据目录/data,磁盘较大。

调整docker的数据目录。

echo "停止之前 检查docker状态"
sudo systemctl status docker.service | grep Active
echo "stop docker"
sudo systemctl stop docker.service
echo "停止之前,检查kubelet状态"
sudo systemctl status kubelet | grep Active
sudo systemctl stop kubelet
echo "都停止完后,检查状态"
sudo systemctl status docker.service | grep Active
sudo systemctl status kubelet | grep Active

最终执行的结果

 # sudo systemctl status kubelet | grep Active
   Active: inactive (dead) since Fri 2023-03-24 14:56:21 CST; 61ms ago
#  sudo systemctl status kubelet | grep Active
   Active: inactive (dead) since Fri 2023-03-24 14:56:21 CST; 28s ago

手动移动原docker目录,这样保留已经存在的镜像文件,否则,还要自己在去找净镜像

# sudo mv docker /data/
mv: 无法删除 'docker/containers/02e3da8176b78187965bc0f309975b082eaaf2c4518027de1f41b7787f0bb18d/mounts/shm': 设备或资源忙

修改/etc/docker/daemon.json文件,添加数据路径data-root

# cat /etc/docker/daemon.json
{
  "exec-opts": [
    "native.cgroupdriver=systemd"
  ],
  "insecure-registries": [
    "10.221.236.232:5000",
    "0.0.0.0/0",
    "127.0.0.1"
  ],
  "data-root": "/data/docker",
  "log-opts": {
    "max-file": "3",
    "max-size": "5m"
  },
  "registry-mirrors": [
    "https://mirrors.tuna.tsinghua.edu.cn",
    "https://registry.docker-cn.com"
  ]
}

重新启动docker,kubelet

# sudo systemctl daemon-reload 
# sudo systemctl restart docker.service
# sudo systemctl restart docker.service 
# sudo systemctl status docker.service         
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-03-24 15:04:41 CST; 19s ago
     Docs: https://docs.docker.com
 Main PID: 18682 (dockerd)
    Tasks: 238
   Memory: 230.2M
   CGroup: /system.slice/docker.service
           ├─18682 /usr/bin/dockerd

# sudo systemctl status kubelet.service        
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since Fri 2023-03-24 15:04:52 CST; 15s ago
     Docs: http://kubernetes.io/docs/
 Main PID: 18950 (kubelet)
    Tasks: 16
   Memory: 118.6M
   CGroup: /system.slice/kubelet.service
           └─18950 /usr/local/bin/kubelet --bootstrap-kubeconfig=

df -h 查看,docker的目录已经到新的目录上了

 

在另一台master主机上,查看pod情况,新Pod也都正常。

 也遇到过问题

failed to listen on 0.0.0.0:6443: listen tcp 0.0.0.0:6443: bind: address alr

 哪有那么复杂的,kill掉原来的进程,再重启动,便正常了。

$ netstat -lutpn | grep 6443
tcp6       0      0 :::6443                 :::*                    LISTEN      11395/some-service

$ kill 11395

$ service kubelet restart
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐