kubernetes之添加删除node

Posted cptao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubernetes之添加删除node相关的知识,希望对你有一定的参考价值。

添加node

1、master生成token

[[email protected]01 ~]# kubeadm token create --print-join-command
kubeadm join 172.19.8.250:8443 --token 83glhm.30nf8cih0q8960nu     --discovery-token-ca-cert-hash sha256:30d13676940237d9c4f0c5c05e67cbeb58cc031f97e3515df27174e6cb777f60

2、待加入的node节点确保kubelet,docker已启动

每一个node的kubelet都必须进去设置cgroup-drive和swap关闭的启动选项.

注意检查 /var/lib/kubelet/kubeadm-flags.env

[[email protected]06 ~]# cat /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS=--cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.1

3、 docker采用docker-ce需要注意该文件,如果没有就创建

[[email protected]06 ~]# cat /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}

4、 关闭swap,并注销/etc/fstab 关于swap的配置信息

swapoff -a

5、 启动kubelet和docker

[[email protected]06 ~]# systemctl start kubelet
[[email protected]-06 ~]# systemctl strart docker

6、 master 检查节点是否加入

[[email protected]01 ~]# kubectl get nodes
NAME      STATUS   ROLES    AGE     VERSION
node-01   Ready    master   2d19h   v1.14.1
node-02   Ready    master   2d19h   v1.14.1
node-03   Ready    master   2d19h   v1.14.1
node-04   Ready    <none>   2d19h   v1.14.1
node-05   Ready    <none>   2d19h   v1.14.1
node-06   Ready    <none>   78s     v1.14.1

如果node上显示添加成功,但Master上显示不出来,在node机上使用systemctl status kubelet查看下服务的状态,检查里面的各项状态,单独处理。


删除node

1、 删除一个节点前,先驱赶掉上面的pod

kubectl drain node-06 --delete-local-data --force --ignore-daemonsets

此时节点上面的pod开始迁移

检查节点状态,被标记为不可调度节点

[[email protected]01 ~]# kubectl get nodes
NAME      STATUS                     ROLES    AGE     VERSION
node-01   Ready                      master   2d19h   v1.14.1
node-02   Ready                      master   2d18h   v1.14.1
node-03   Ready                      master   2d18h   v1.14.1
node-04   Ready                      <none>   2d18h   v1.14.1
node-05   Ready                      <none>   2d18h   v1.14.1
node-06   Ready,SchedulingDisabled   <none>   2d18h   v1.14.1

最后删除节点

[[email protected]01 ~]# kubectl delete node node-06
node "node-06” deleted

[[email protected]-01 ~]# kubectl get nodes
NAME      STATUS   ROLES    AGE     VERSION
node-01   Ready    master   2d19h   v1.14.1
node-02   Ready    master   2d19h   v1.14.1
node-03   Ready    master   2d19h   v1.14.1
node-04   Ready    <none>   2d18h   v1.14.1
node-05   Ready    <none>   2d18h   v1.14.1

 

以上是关于kubernetes之添加删除node的主要内容,如果未能解决你的问题,请参考以下文章

kubernetes addons之node-problem-detector

k8s之Label

k8s之pods

k8s之Label

k8s之pods

kubernetes:pod无法删除