在已有的k8s集群中加入一个新的node节点,并正常工作。
已有的k8s集群节点信息:
192.168.109.130 master
192.168.206.128 k8s-node01
192.168.206.129 k8s-node02
新加入一个节点:
192.168.206.139 k8s-node03
kubectl get nodes
在进行下面的步骤之前,要找到最初创建k8s集群时,系统提示的用来将新节点加入集群的语句:
在master节点上执行这句:kubeadm token create --print-join-command
找到这句:kubeadm join 192.168.109.130:6443 --token 2wly0a.ehwba9iukw6cpjws --discovery-token-ca-cert-hash sha256:283390bd4b0bdccf6961d4a899fc7ce8175d24a9c41efbe612b35a723c555188
接下来,修改各个节点上的hosts文件
注意,在接入节点上执行swapoff -a
Kubernetes 不支持在启用交换空间的情况下运行,通过以上命令来禁用交换空间
#修改系统参数
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
setenforce 0
swapoff -a
yes | cp /etc/fstab /etc/fstab_bak
cat /etc/fstab_bak |grep -v swap > /etc/fstab
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#配置yum源:
cd /etc/yum.repos.d
wget http://mirrors.aliyun.com/repo/Centos-7.repo
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum clean all
yum makecache fast
#安装docker
yum -y install docker
cat << EOF > /etc/docker/daemon.json
{
"registry-mirrors": ["https://wyrsf017.mirror.aliyuncs.com"]
}
EOF
systemctl start docker
systemctl enable docker
docker version
------------------------------------------------------------------------------------------
yum -y install kubelet-1.19.0 kubeadm-1.19.0
systemctl restart kubelet
systemctl enable kubelet
systemctl daemon-reload
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
------------------------------------------------------------------------------------------
最后,在接入节点上执行
kubeadm join 192.168.109.130:6443 --token 2wly0a.ehwba9iukw6cpjws --discovery-token-ca-cert-hash sha256:283390bd4b0bdccf6961d4a899fc7ce8175d24a9c41efbe612b35a723c555188