首页 > 其他分享 >k8s中删除节点之后再添加节点

k8s中删除节点之后再添加节点

时间:2023-07-24 22:00:11浏览次数:42  
标签:reset kubernetes kubelet -- etc 添加 kubeadm k8s 节点

删除节点

先标记为不可调度,驱逐节点上的pod

#先标记节点
$ kubectl drain centos7909 --delete-emptydir-data --force --ignore-daemonsets 
node/centos7909 already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-flannel/kube-flannel-ds-hnmmg, kube-system/kube-proxy-87gpm
node/centos7909 drained

#查看节点状态
$ kubectl get nodes 
NAME         STATUS                        ROLES                 AGE   VERSION
centos7906   Ready    					control-plane   	   28m    v1.27.4
centos7909   Ready,SchedulingDisabled     <none>         		 8m39s   v1.27.4
centos7910   Ready    					<none>          	   8m30s  v1.27.4

#已经标记为SchedulingDisabled

删除节点

kubectl delete node centos7909
node "centos7909" deleted

#再查看,就已经看不到了
$ ubectl get nodes 
NAME         STATUS   ROLES                  AGE   VERSION
centos7906   Ready    control-plane,master   65m   v1.27.4
centos7910   Ready    <none>                 19m   v1.27.4

这个时候就完成了删除节点。

如果之后旧node又想重新加入怎么办?

停掉kubelet

(在需要添加进来的节点上操作)

systemctl stop kubelet

重置

正情况下

kubeadm  reset

[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W0728 15:54:54.944853   10725 removeetcdmember.go:80] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] No etcd config found. Assuming external etcd
[reset] Please, manually reset etcd to prevent further issues
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
[reset] Deleting contents of stateful directories: [/var/lib/kubelet /var/lib/dockershim /var/run/kubernetes /var/lib/cni]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.

1.24版本之后仍然使用docker的

kubeadm  reset  --cri-socket unix:///run/cri-dockerd.sock
# 需要加上docker的cri


[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W0728 15:54:54.944853   10725 removeetcdmember.go:80] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] No etcd config found. Assuming external etcd
[reset] Please, manually reset etcd to prevent further issues
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
[reset] Deleting contents of stateful directories: [/var/lib/kubelet /var/lib/dockershim /var/run/kubernetes /var/lib/cni]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.

清理旧文件

根据提示,删除必要文件,清理必要策略

rm -rf /etc/cni/net.d

清理策略

使用iptables的

iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X

使用ipvs的

ipvsadm --clear

没有ipvsadm命令的,需要安装

yum install ipvsadm -y

获取token和ca-hash

在master节点上执行

kubeadm token create --ttl 0 --print-join-command
kubeadm join 10.0.0.3:6443 --token vxzs52.lx25mhodqlimerqg --discovery-token-ca-cert-hash sha256:ed83dba16c0cbe603ff7a7f4fc4f12f81e922739505e80f81f45edc96b92caed

加入集群

在待加入节点上执行

正常情况下

kubeadm join 10.0.0.3:6443 --token vxzs52.lx25mhodqlimerqg --discovery-token-ca-cert-hash sha256:ed83dba16c0cbe603ff7a7f4fc4f12f81e922739505e80f81f45edc96b92caed

1.24版本之后仍然使用docker的

kubeadm join 10.0.0.3:6443 --token vxzs52.lx25mhodqlimerqg --discovery-token-ca-cert-hash sha256:ed83dba16c0cbe603ff7a7f4fc4f12f81e922739505e80f81f45edc96b92caed  --cri-socket unix:///run/cri-dockerd.sock

这就完成了加入

标签:reset,kubernetes,kubelet,--,etc,添加,kubeadm,k8s,节点
From: https://www.cnblogs.com/guangdelw/p/17578475.html

相关文章

  • Tool-CMake-添加自定义宏定义
    Tool-CMake-添加自定义宏定义cmake,makefile中定义的宏变量,其实和C/C++中的#define是一致的,可以传入到C/C++中。控制程序的编译比如:cmake中有宏定义:add_definitions(-Dhello="hellocmake")......
  • MongoDB 教程二: 添加, 删除,查询 shell命令
       MongoDBShell常用操作命令MonoDB shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的。 Ø数据库//1、Help查看命令提示helpdb.help();db.yourColl.help();db.youColl.find().help();rs.help();//2、切换/创建......
  • kubernets(k8s) 部署1.23.6版本
    kubernets(k8s)部署1.23.6版本环境准备环境介绍操作系统:CentOSLinuxrelease7.6.1810(Core)k8s组件版本:1.23.6docker版本:Dockerversion24.0.4,build3713ee12核CPU、2G内存、20G硬盘节点:(本实验采用虚拟机)k8s-master172.16.100.130    k8s-node1172.16.......
  • k8s遇到的坑
    换源之后出现数字签名错误W:GPG错误:https://mirrors.aliyun.com/kubernetes/aptkubernetes-xenialInRelease:由于没有公钥,无法验证下列签名:NO_PUBKEYB53DC80D13EDEF05E:仓库“https://mirrors.aliyun.com/kubernetes/aptkubernetes-xenialInRelease”没有数字签名。......
  • k8s架构
    核心组件etcd保存整个集群的状态apiserver提供资源操作的唯一入口,并提供认证、授权、访问控制、API注册和发现等机制controllermanager负责维护集群的状态,比如故障检测、自动扩展、滚动更新等scheduler负责资源的调度,按照预定的调度策略将Pod调度到相应的机器上kubelet负责......
  • 尚硅谷 k8s 学习笔记
    K8S进阶部分       1.Deployment部署           1.1自愈能力           1.2多副本           1.3扩容、缩容           1.4滚动更新           1.5版本回退           1.6工作负载  ......
  • 在Linux添加定时任务删除5天前的日志文件
    在Linux添加定时任务删除5天前的日志文件利用shell脚本自动清理1.删除文件命令:find对应目录-mtime+天数-name"文件名"-execrm-f{}\;实例命令:find/usr/local/mysql/logs-typef-mtime+5-name"*.txt"-execrm-f{}\;说明:将/usr/local/mysql/logs目录下所......
  • android init.rc添加服务
    Androidinit.rc添加服务在Android系统中,init.rc文件是一个重要的配置文件,它用于初始化系统的各种服务和进程。通过修改init.rc文件,我们可以添加自定义的服务,以满足特定的需求。本文将详细介绍如何在Androidinit.rc文件中添加自定义服务,并提供相应的代码示例。init.rc文件概述i......
  • uboot添加自定义命令 CMD
    原文:https://blog.csdn.net/weixin_41252596/article/details/128317180有些用户玩uboot比较花,除了引导系统还要做一堆驱动,有些驱动除了按流程执行还要留出命令行接口用于调试。比如我现在的设备外接了个fpga,fpga和cpu的接口已经做好了,但是为了调试要新增个命令,在命令行下手动与f......
  • k8s修改证书有效期
    k8s各组件非常依赖证书而默认情况下ca证书是十年,而其他证书都只有一年Kubernetes中的如果证书过期了,会导致集群中的许多组件无法正常通信,从而影响整个集群的功能。所以在生产环境下,这是非常大的坑查看证书有效期方法一cd/etc/kubernetes/pkiforiin$(ls*.crt);doech......