K8s node节点替换
一、node节点下线
1.将节点设置为不可调度,防止Pod调度在此节点
Bash
# kubectl cordon <node-name>
# 执行后kubectl get nodes 可以查看到该节点有SchedulingDisable字段
2.驱逐该节点所有Pod
bash
# kubectl drain <node-name> --ignore-daemonsets --force
- --ignore-daemonsets ds也驱逐
- --force 删除所有Pod
3.查看是否该节点是否还有Pod
bash
# kubectl get pods -A -o wide |grep <node-name>
4.确认无Pod后,删除节点
bash
# kubectl delete node <node-name>
5.删除秘钥、配置文件等
bash
# systemctl stop kubelet
# rm -f /etc/kubernetes/kubelet.conf
# kubeadmin安装直接停止docker即可
# systemctl stop docker.socket
# systemctl stop docker.service
二、node节点上线
1.节点主机初始化【结合具体环境】,如关闭防火墙,关闭swap,开启iptables转发等
bash
1、关闭防火墙及selinux
# systemctl stop firewalld
# systemctl disable firewalld
# sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
# setenforce 0 # 临时
2、关闭swap
# swapoff -a # 临时
# vim /etc/fstab # 永久 (注释掉swap分区挂载)
3、设置主机名并写入hosts
# hostnamectl set-hostname <hostname>
4、将桥接的IPv4流量传递到iptables的链
# cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# sysctl --system # 生效
5、时间同步
# yum install ntpdate -y
# ntpdate time.windows.com
6、安装docker
2.安装kubeadm,kubelet和kubectl【确认版本】
bash
yum install -y kubelet-1.22.2 kubeadm-1.22.2 kubectl-1.22.2
3.启动kubelet并加入集群
bash
# systemctl start kubelet
# 在master节点创建token,执行完命令后会出现node节点join的命令,在node节点执行即可
# kubeadm token create --print-join-command
# node节点加入集群
# kubeadm join ...