在旧node上scp证书和配置文件到新的node
scp -r /etc/etcd/ 192.168.39.137:/etc/
scp -r /etc/kubernetes/ 192.168.39.137:/etc/
scp -r /etc/flannel/ 192.168.39.137:/etc/
删除一些无用证书
cd ssl/
rm -rf kubelet-client*
cd ../cfg
rm -rf kubelet.kubeconfig
在旧node上把命令scp到新node
scp /usr/local/bin/* 192.168.39.137:/usr/local/bin/
复制启动文件
systemctl status kube-proxy
#看loaded路径
scp /usr/lib/systemd/system/kube* 192.168.39.137:/usr/lib/systemd/system/
scp /usr/lib/systemd/system/flanneld.service 192.168.39.137:/usr/lib/systemd/system/
在新node节点主机上 修改配置文件ip
cd /etc/kubernetes/cfg
grep '刚刚复制的旧nodeip'
sed -i 's#旧nodeip#新nodeip#g' *
安装docker
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum list docker-ce --showduplicates
yum -y install docker-ce-19.03.15 docker-ce-cli-19.03.15
mkdir /etc/docker -p
镜像加速
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://ig2l319y.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
配置docker的启动文件
cat > /usr/lib/systemd/system/docker.service <<'EOF'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
[Service]
Type=notify
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
或者从旧节点复制过来
scp /usr/lib/systemd/system/docker.service 192.168.39.137:/usr/lib/systemd/system/
新的节点上启动flannel
systemctl daemon-reload
systemctl restart flanneld.service
检查flannel (看最后一行的ip与下面启动docker的一致)
cat /var/run/flannel/subnet.env
启动docker
systemctl start docker
systemctl status docker
启动kube-proxy
systemctl start kube-proxy
systemctl start kubelet
去master节点操作验证
kubectl get csr #看是否有请求
kubectl certificate approve 上一条命令结果中的name
kubectl get nodes(可以看到新加进来的node等一会ready)
创建pod验证
kubectl scale deployment nginx-dp --replicas=4
kubectl get pod -o wide
发现新进入的节点ip也能创建pod