
一. 增加工作节点
# vm-207 节点初始化操作
# kubeadm token create --print-join-command (建立token,生成join命令)
kubeadm join 192.168.100.190:8443 --token p262ay.ishd2gzcpluorsd0 --discovery-token-ca-cert-hash sha256:f50e85f09578b4fffbc8425df50950b21eefe8d2b10bbee234f5947485a588e0
# kubeadm join 192.168.100.190:8443 --token p262ay.ishd2gzcpluorsd0 --discovery-token-ca-cert-hash sha256:f50e85f09578b4fffbc8425df50950b21eefe8d2b10bbee234f5947485a588e0 --ignore-preflight-errors=all
# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
vm-191 Ready control-plane,master 24h v1.22.2 192.168.100.191 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-192 Ready control-plane,master 23h v1.22.2 192.168.100.192 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-193 Ready control-plane,master 23h v1.22.2 192.168.100.193 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-197 Ready <none> 23h v1.22.2 192.168.100.197 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-207 Ready <none> 34s v1.22.2 192.168.100.207 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
二. 撤销工作节点
# kubectl drain vm-207 --delete-local-data --delete-emptydir-data --force (调度迁移pod)
# kubectl cordon vm-207 (锁定资源分配)
# kubectl get nodes --all-namespaces -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
vm-191 Ready control-plane,master 24h v1.22.2 192.168.100.191 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-192 Ready control-plane,master 23h v1.22.2 192.168.100.192 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-193 Ready control-plane,master 23h v1.22.2 192.168.100.193 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-197 Ready <none> 23h v1.22.2 192.168.100.197 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
vm-207 Ready,SchedulingDisabled <none> 10m v1.22.2 192.168.100.207 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.9
# kubeadm reset (在工作节点操作,清空数据)
# kubectl delete nodes vm-207 (删除)
10. pod调度(指定工作节点)
- NodeName: 最简单的节点选择方式,直接指定节点,跳过调度器。
- Taint/Toleration: 通过 Pod 有洁癖的特性进行调整
- NodeSelector: 早期的简单控制方式,直接通过键—值对将 Pod 调度到具有特定 label 的 Node 上。
- NodeAffinity: NodeSelector 的升级版,支持更丰富的配置规则,使用更灵活。
- PodAffinity: 根据已在节点上运行的 Pod 标签来约束 Pod 可以调度到哪些节点,而不是根据 node label。