K8s node节点替换

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 ...
相关推荐
BullSmall22 分钟前
Sonarqube9.9 docker 镜像启动后 conf 下的配置文件没有了
docker·容器·eureka
spider_xcxc1 小时前
Docker 实战:容器化多服务应用,Dockerfile 与 Compose 配置全解析
docker·云原生·eureka·虚拟化·容器化
hay_lee2 小时前
Kubernetes StatefulSet:OrderedReady 极简指南
云原生·容器·kubernetes
晚风吹长发2 小时前
Docker使用——Docker容器及相关命令
linux·运维·服务器·docker·容器·架构
ShiXZ2132 小时前
Docker Compose 安装与配置指南
运维·docker·容器
BullSmall3 小时前
Anolis OS 8.10 Docker 部署 SonarQube 9.9 完整教程
运维·docker·容器
人间凡尔赛4 小时前
AI-Native 云原生架构:2026 年从容器编排到智能体编排的范式革命
后端·云原生·架构
成为你的宁宁4 小时前
【K8s HPA 水平扩缩容】
kubernetes·hpa
欢醉5 小时前
k8s调度容器失败The node had condition: [DiskPressure]
kubernetes·springcloud
Linux-187414 小时前
分布式链路追踪系统之docker-compose安装skywalking
云原生·docker-compose·skywalking·分布式链路追踪系统·应用程序性能监控