k8s部署前请准备好多台centos linux 7.9服务器,以及daemon.json、hosts、calico-v3.21.yaml等文件。并将文件放置在install-k8s.yaml指定的目录,本文在yaml目录。其中,daemon.json是用来配置docker运行参数文件,请根据自己需求配置;hosts是域名指向文件,如果有DNS服务器,那么请在服务器上配置;calico-v3.21.yaml是k8s的网络组件部署配置文件。
一、在管理机上运行yaml文件安装docker、kubeadm、kubectl、kubelet等相关程序,配置每台服务器。
运行install-k8s.yaml
二、在每台机器上下载images文件
kubeadm config images pull --kubernetes-version v1.19.16 --image-repository registry.aliyuncs.com/google_containers
docker pull registry.aliyuncs.com/google_containers/pause:3.2
docker pull registry.aliyuncs.com/google_containers/coredns:1.7.0
docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.19.0
docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.19.0
docker pull registry.aliyuncs.com/google_containers/kube-controller-manager:v1.19.0
docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.19.0
docker pull registry.aliyuncs.com/google_containers/etcd:3.4.13-0
docker pull registry.aliyuncs.com/google_containers/kube-controllers
docker pull registry.aliyuncs.com/google_containers/node
docker tag registry.aliyuncs.com/google_containers/kube-controllers calico/kube-controllers:v3.21.0
docker tag registry.aliyuncs.com/google_containers/node calico/node:v3.21.0
docker pull calico/node
docker pull calico/cni
docker tag calico/node calico/node:v3.21.0
docker tag calico/cni calico/cni:v3.21.0
docker tag calico/node calico/node:v3.21.0
docker tag calico/cni calico/cni:v3.21.0
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.19.0 k8s.gcr.io/kube-apiserver:v1.19.0
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.19.0 k8s.gcr.io/kube-controller-manager:v1.19.0
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.19.0 k8s.gcr.io/kube-scheduler:v1.19.0
docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.19.0 k8s.gcr.io/kube-proxy:v1.19.0
docker tag registry.aliyuncs.com/google_containers/pause:3.2 registry.aliyuncs.com/google_containers/pause:3.2
docker tag registry.aliyuncs.com/google_containers/etcd:3.4.13-0 k8s.gcr.io/etcd:3.4.13-0
docker tag registry.aliyuncs.com/google_containers/coredns:1.7.0 k8s.gcr.io/coredns:1.7.0
docker tag registry.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2
三、在master上执行init.yaml生成配置文件
kubeadm config print init-defaults >init.yaml
kubeadm init --config init.yaml
如下相关位置按个人需求修改
四、生成k8s的配置文件,并将配置文件拷贝到各个服务器节点
mkdir -p ~/.kube
cp -i /etc/kubernetes/admin.conf ~/.kube/config
scp root@192.168.126.152:/root/.kube/config yaml/.
scp yaml/config root@192.168.126.153:/root/.kube/config
scp yaml/config root@192.168.126.154:/root/.kube/config
五、部署网络组件calico
kubectl apply -f calico-v3.21.yaml
六、添加节点到集群
kubeadm join 192.168.126.152:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:aeef49daa2ccf3bbff72d7c43a9103a69902588796bc1b097433e6a4c8f80ca8 --v=5
五、如果在安装kubelet、kubeadm、kubeclt后加入节点到集群发生故障,执行以下命令:
rm -rf /etc/kubernetes/pki/ca.crt
rm -rf /etc/kubernetes/kubelet.conf
kubeadm reset -f
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
ipvsadm -C
kubeadm join 192.168.126.152:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:aeef49daa2ccf3bbff72d7c43a9103a69902588796bc1b097433e6a4c8f80ca8 --v=5