kubernetes/NEW/kubernetes集群添加新节点.md
2024-12-22 22:27:07 +08:00

3.0 KiB
Raw Permalink Blame History

kubernetes集群添加新节点

作者:行癫(盗版必究)


一:项目背景

当现有的节点无法提供足够的CPU、内存或存储资源来运行更多的Pod时添加新的节点可以增加集群的总资源池从而支持更多的应用部署和服务通过增加工作节点的数量可以在某些节点失效时保证其他节点能够继续为用户提供服务从而提高整个系统的高可用性和容错性。这对于生产环境中的关键任务应用尤为重要

二:节点准备

第一部分

1.修改所有节点的主机名 (规范)

2.所有节点本地解析

3.网络配置(所有节点全部使用静态地址)

4.所有节点保证yum仓库可用 base epel https://developer.aliyun.com/mirror/

5.所有节点关闭swap交换分区

使用free -m 来判断 如果是没有swap交换分区 此步略过

使用free -m 来判断 如果是有swap交换分区 swapoff -a 修改/etc/fstab 把swap的挂载去掉

6.集群所有节点保持时间一致,不一致做时间同步

第二部分

1.container runtime 所有节点 docker 安装

2.安装核心组件 kubelet 引导工具 kubeadm 命令行管理工具 kubectl 依赖包 ipvsadm

需要指定版本安装(√)

修改kubelet的配置文件(√)

3.加载内核模块 修改内核参数

第三部分

1.获取加入命令

Master节点执行

[root@master ~]# kubeadm token create --print-join-command
kubeadm join 10.9.12.234:6443 --token nu1g7p.w5sg414ekfm6hlcw --discovery-token-ca-cert-hash sha256:92d8500db9480e0159f47b959139a27c9efea0809c3fa7a9c98016b14dfe2bca 

2.新节点执行加入

[root@node-4 ~]# kubeadm join 10.9.12.234:6443 --token nu1g7p.w5sg414ekfm6hlcw --discovery-token-ca-cert-hash sha256:92d8500db9480e0159f47b959139a27c9efea0809c3fa7a9c98016b14dfe2bca
[preflight] Running pre-flight checks
        [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 26.1.4. Latest validated version: 20.10
        [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

3.主节点验证

[root@master ~]# kubectl get nodes