一、确认节点状态正常
[root@node1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
node1 Ready control-plane,master 43h v1.23.1
node2 Ready control-plane,master 43h v1.23.
二、设置node不可调度,不影响目前节点pod的运行
[root@node1 ~]# kubectl cordon node1
node/node1 cordoned
[root@node1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
node1 Ready,SchedulingDisabled control-plane,master 44h v1.23.1
node2 Ready control-plane,master 44h v1.23.1
[root@node1 ~]#
[root@node1 ~]#
三、驱散pod
[root@node1 ~]# kubectl drain node1 --delete-local-data --ignore-daemonsets --force
Flag --delete-local-data has been deprecated, This option is deprecated and will be deleted. Use --delete-emptydir-data.
node/node1 already cordoned
WARNING: ignoring DaemonSet-managed Pods: default/netchecker-agent-c6nlh, default/netchecker-agent-hostnet-ks5tt, kube-system/calico-node-wq79l, kube-system/kube-proxy-r6m7r, kube-system/nodelocaldns-zt6wl
evicting pod kube-system/coredns-5c5b9c5cb-rx4h5
pod/coredns-5c5b9c5cb-rx4h5 evicted
node/node1 drained
[root@node1 ~]#
四、查看docker服务状态,确认服务配置文件
五、拷贝docker目录到新的路径
[root@node1 ~]# cp -R /var/lib/docker /app/docker/
[root@node1 ~]# mv /var/lib/docker /var/lib/docker-bak
六、修改docker服务配置文件
服务配置文件
vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target containerd.service
BindsTo=containerd.service
[Service]
Type=notify
Environment=GOTRACEBACK=crash
ExecReload=/bin/kill -s HUP $MAINPID
Delegate=yes
KillMode=process
ExecStart=/usr/bin/dockerd \
$DOCKER_OPTS \ ####关于默认存储的配置存在于该变量中
$DOCKER_STORAGE_OPTIONS \
$DOCKER_DNS_OPTIONS
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=1min
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
vim /etc/systemd/system/docker.service.d/docker-options.conf
[Service]
Environment="DOCKER_OPTS= --iptables=false \
--exec-opt native.cgroupdriver=systemd \
\
\
--data-root=/app/docker \ ###修改此目录为新的存储目录
--log-opt max-size=50m --log-opt max-file=5 \
七、加载配置重启docker服务
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl restart docker
八、确认docker服务状态以及docker容器挂路径
容器启动后目录发生改变
九、设置节点可用
[root@node1 ~]# kubectl uncordon node1
node/node1 uncordoned
[root@node1 ~]#
[root@node1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
node1 Ready control-plane,master 44h v1.23.1
node2 Ready control-plane,master 44h v1.23.1