安装Docker-ce
yum install docker-ce-20.10.6 docker-ce-cli-20.10.6 containerd.io -y
配置docker镜像加速器和驱动
[root@ecs-k8s-master1 ~]#vim /etc/docker/daemon.json
{
"registry-mirrors":["https://rsbud4vc.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com","http://qtid6917.mirror.aliyuncs.com", "https://rncxm540.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl daemon-reload && systemctl restart docker
安装k8s软件包
# yum install -y kubelet-1.20.6 kubeadm-1.20.6 kubectl-1.20.6
# systemctl enable kubelet && systemctl start kubelet
kubeadm初始化k8s集群
在ecs-k8s-master1上创建kubeadm-config.yaml文件:
# cd /root/
# vim kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.20.6
controlPlaneEndpoint: 192.168.40.199:16443
imageRepository: registry.aliyuncs.com/google_containers
apiServer:
certSANs:
- 192.168.40.180
- 192.168.40.181
- 192.168.40.182
- 192.168.40.199
networking:
podSubnet: 10.244.0.0/16
serviceSubnet: 10.10.0.0/16
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
事先获取当前版本k8s初始化需要的镜像包k8simage-1-20-6.tar.gz
手动加载到docker本地镜像
# docker load -i k8simage-1-20-6.tar.gz
初始化k8s
# kubeadm init --config kubeadm-config.yaml
添加master节点
将master2作为master节点添加到集群中
[root@ecs-k8s-master1 ~]# ls -l /etc/kubernetes/pki/
total 60
-rw-r--r-- 1 root root 1294 Oct 20 22:09 apiserver.crt
-rw-r--r-- 1 root root 1135 Oct 20 22:09 apiserver-etcd-client.crt
-rw------- 1 root root 1675 Oct 20 22:09 apiserver-etcd-client.key
-rw------- 1 root root 1679 Oct 20 22:09 apiserver.key
-rw-r--r-- 1 root root 1143 Oct 20 22:09 apiserver-kubelet-client.crt
-rw------- 1 root root 1675 Oct 20 22:09 apiserver-kubelet-client.key
-rw-r--r-- 1 root root 1066 Oct 20 22:09 ca.crt
-rw------- 1 root root 1675 Oct 20 22:09 ca.key
drwxr-xr-x 2 root root 4096 Oct 20 22:09 etcd
-rw-r--r-- 1 root root 1078 Oct 20 22:09 front-proxy-ca.crt
-rw------- 1 root root 1675 Oct 20 22:09 front-proxy-ca.key
-rw-r--r-- 1 root root 1103 Oct 20 22:09 front-proxy-client.crt
-rw------- 1 root root 1675 Oct 20 22:09 front-proxy-client.key
-rw------- 1 root root 1679 Oct 20 22:09 sa.key
-rw------- 1 root root 451 Oct 20 22:09 sa.pub
将除apiserver以外的所有文件拷贝到master2主机相同目录下
在master1上查看加入节点的命令:
[root@ecs-k8s-master1 ~]# kubeadm token create --print-join-command
kubeadm join 192.168.40.199:16443 --token nbs3b9.cziv8byviay6l6tt --discovery-token-ca-cert-hash sha256:aea3b483dd1a3acc947fe06a5ac77e3abea64af04d43bd5f6b90dc57d1a75fd2
在master2上执行该命令:
[root@ecs-k8s-master2 ~]# kubeadm join 192.168.40.199:16443 --token nbs3b9.cziv8byviay6l6tt --discovery-token-ca-cert-hash sha256:aea3b483dd1a3acc947fe06a5ac77e3abea64af04d43bd5f6b90dc57d1
a75fd2
[preflight] Running pre-flight checks