Kubeadm部署的K8S添加节点
新node节点部署环境# 初始化关闭防火墙、selinux关闭时swap分区同步master时间修改主机名# 安装dockeryum install -y yum-utils device-mapper-persistent-data lvm2 gityum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/ce
·
新node节点部署环境
# 初始化
关闭防火墙、selinux
关闭时swap分区
同步master时间
修改主机名
# 安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2 git
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker && systemctl enable docker
# 拉去镜像
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.20.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.20.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.20.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.20.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.7.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
# 修改镜像tag
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.20.2 k8s.gcr.io/kube-controller-manager:v1.20.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.20.2 k8s.gcr.io/kube-proxy:v1.20.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.20.2 k8s.gcr.io/kube-apiserver:v1.20.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.20.2 k8s.gcr.io/kube-scheduler:v1.20.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.7.0 k8s.gcr.io/coredns:1.7.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0 k8s.gcr.io/etcd:3.4.13-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2
# 添加yum源安装kubelet
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 install -y kubelet-1.20.2-0.x86_64 kubeadm-1.20.2-0.x86_64 kubectl-1.20.2-0.x86_64 ipvsadm
# 加载ipvs相关内核模块
如果重新开机,需要重新加载(可以写在 /etc/rc.local 中开机自动加载)
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4
# 编辑文件添加开机启动
# vim /etc/rc.local
# chmod +x /etc/rc.local
# 配置转发相关参数,否则可能会出错
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF
sysctl --system
# 配置启动kubelet
DOCKER_CGROUPS=`docker info |grep 'Cgroup' | awk ' NR==1 {print $3}'`
# 配置kubelet的cgroups
cat >/etc/sysconfig/kubelet<<EOF
KUBELET_EXTRA_ARGS="--cgroup-driver=$DOCKER_CGROUPS --pod-infra-container-image=k8s.gcr.io/pause:3.2"
EOF
systemctl daemon-reload
systemctl enable kubelet && systemctl restart kubelet
master 添加节点
# 重新生成token
kubeadm token create --print-join-command
# 重新生成证书
kubeadm init phase upload-certs --upload-certs
新节点加入集群
kubeadm join 192.168.96.165:6443 --token vtxxim.sy0u93t20ixpg4sq --discovery-token-ca-cert-hash sha256:308629a4406bfca94585345d0d15c00d95a9876bf772386cb3d54e9482af6fea
# 也可以添加master 节点
# 添加新master节点
kubeadm join apiserver.cluster.local:6443 --token sc2ty3.ej38ceisi5lmt9ad --discovery-token-ca-cert-hash sha256:42bf6e526b795854b61b7c0ca875f9a8292b989d44f0f51a4d8dec450711b89e --control-plane --certificate-key 0c00611d30adffe68126477aa33613604c4a423ae2c06e125fe55f838a88b45f
删除node节点
# 驱离node节点上的pod
kubectl drain k8s-node3 --delete-local-data --force --ignore-daemonsets
# 检查节点状态,被标记为不可调度节点
kubectl get nodes
# 删除这个node节点
kubectl delete node k8s-node3
更多推荐
已为社区贡献2条内容
所有评论(0)