提示:如上仅需Master01节点操作,从而实现所有节点自动化安装,同时此时不需要启动kubelet,初始化的过程中会自动启动的,如果此时启动了会出现报错,忽略即可。
说明:同时安装了cri-tools, kubernetes-cni, socat三个依赖:
socat:kubelet的依赖;
cri-tools:即CRI(Container Runtime Interface)容器运行时接口的命令行工具。
初始化过程中会pull大量镜像,并且镜像位于国外,可能出现无法pull的情况导致Kubernetes初始化失败。建议提前准备镜像,保证后续初始化。
[root@master01 ~]# kubeadm --kubernetes-version=v1.21.0 config images list #列出所需镜像 [root@master01 ~]# cat <<EOF > kubeadm/conloadimage.sh #!/bin/sh #****************************************************************# # ScriptName: conloadimage.sh # Author: xhy # Create Date: 2021-04-15 14:03 # Modify Author: xhy # Modify Date: 2021-04-15 17:35 # Version: #***************************************************************# KUBE_VERSION=v1.21.0 CALICO_VERSION=v3.18.1 CALICO_URL='docker.io/calico' KUBE_PAUSE_VERSION=3.4.1 ETCD_VERSION=3.4.13-0 CORE_DNS_VERSION=v1.8.0 GCR_URL=k8s.gcr.io METRICS_SERVER_VERSION=v0.4.2 INGRESS_VERSION=v0.45.0 CSI_PROVISIONER_VERSION=v1.6.0-lh1 CSI_NODE_DRIVER_VERSION=v1.2.0-lh1 CSI_ATTACHER_VERSION=v2.2.1-lh1 CSI_RESIZER_VERSION=v0.5.1-lh1 DEFAULTBACKENDVERSION=1.5 ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers UCLOUD_URL=uhub.service.ucloud.cn/uxhy QUAY_URL=quay.io mkdir -p conimages/ # config node hostname export ALL_NAMES=(master02 master03 worker01 worker02 worker03) kubeimages=(kube-proxy:\${KUBE_VERSION} kube-scheduler:\${KUBE_VERSION} kube-controller-manager:\${KUBE_VERSION} kube-apiserver:\${KUBE_VERSION} pause:\${KUBE_PAUSE_VERSION} etcd:\${ETCD_VERSION} ) corednsimages=(coredns:\${CORE_DNS_VERSION} ) for corednsimageName in \${corednsimages[@]} ; do echo \${corednsimageName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${corednsimageName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${corednsimageName} \${GCR_URL}/coredns/\${corednsimageName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${corednsimageName} ctr -n k8s.io images export conimages/\${corednsimageName}\.tar \${GCR_URL}/coredns/\${corednsimageName} done for kubeimageName in \${kubeimages[@]} ; do echo \${kubeimageName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${kubeimageName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${kubeimageName} \${GCR_URL}/\${kubeimageName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${kubeimageName} ctr -n k8s.io images export conimages/\${kubeimageName}\.tar \${GCR_URL}/\${kubeimageName} done metricsimages=(metrics-server:\${METRICS_SERVER_VERSION}) for metricsimageName in \${metricsimages[@]} ; do echo \${metricsimageName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${metricsimageName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${metricsimageName} \${GCR_URL}/metrics-server/\${metricsimageName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${metricsimageName} ctr -n k8s.io images export conimages/\${metricsimageName}\.tar \${GCR_URL}/metrics-server/\${metricsimageName} done calimages=(cni:\${CALICO_VERSION} pod2daemon-flexvol:\${CALICO_VERSION} node:\${CALICO_VERSION} kube-controllers:\${CALICO_VERSION}) for calimageName in \${calimages[@]} ; do echo \${calimageName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${calimageName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${calimageName} \${CALICO_URL}/\${calimageName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${calimageName} ctr -n k8s.io images export conimages/\${calimageName}\.tar \${CALICO_URL}/\${calimageName} done ingressimages=(controller:\${INGRESS_VERSION}) for ingressimageName in \${ingressimages[@]} ; do echo \${ingressimageName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${ingressimageName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${ingressimageName} \${GCR_URL}/ingress-nginx/\${ingressimageName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${ingressimageName} ctr -n k8s.io images export conimages/\${ingressimageName}\.tar \${GCR_URL}/ingress-nginx/\${ingressimageName} done csiimages=(csi-provisioner:\${CSI_PROVISIONER_VERSION} csi-node-driver-registrar:\${CSI_NODE_DRIVER_VERSION} csi-attacher:\${CSI_ATTACHER_VERSION} csi-resizer:\${CSI_RESIZER_VERSION} ) for csiimageName in \${csiimages[@]} ; do echo \${csiimageName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${csiimageName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${csiimageName} longhornio/\${csiimageName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${csiimageName} ctr -n k8s.io images export conimages/\${csiimageName}\.tar longhornio/\${csiimageName} done otherimages=(defaultbackend-amd64:\${DEFAULTBACKENDVERSION}) for otherimagesName in \${otherimages[@]} ; do echo \${otherimagesName} ctr -n k8s.io images pull \${UCLOUD_URL}/\${otherimagesName} ctr -n k8s.io images tag \${UCLOUD_URL}/\${otherimagesName} \${GCR_URL}/\${otherimagesName} ctr -n k8s.io images rm \${UCLOUD_URL}/\${otherimagesName} ctr -n k8s.io images export conimages/\${otherimagesName}\.tar \${GCR_URL}/\${otherimagesName} done allimages=(kube-proxy:\${KUBE_VERSION} kube-scheduler:\${KUBE_VERSION} kube-controller-manager:\${KUBE_VERSION} kube-apiserver:\${KUBE_VERSION} pause:\${KUBE_PAUSE_VERSION} etcd:\${ETCD_VERSION} coredns:\${CORE_DNS_VERSION} metrics-server:\${METRICS_SERVER_VERSION} cni:\${CALICO_VERSION} pod2daemon-flexvol:\${CALICO_VERSION} node:\${CALICO_VERSION} kube-controllers:\${CALICO_VERSION} controller:\${INGRESS_VERSION} csi-provisioner:\${CSI_PROVISIONER_VERSION} csi-node-driver-registrar:\${CSI_NODE_DRIVER_VERSION} csi-attacher:\${CSI_ATTACHER_VERSION} csi-resizer:\${CSI_RESIZER_VERSION} defaultbackend-amd64:\${DEFAULTBACKENDVERSION} ) for all_name in \${ALL_NAMES[@]} do echo ">>> \${all_name}" ssh root@\${all_name} "mkdir /root/conimages" scp -rp conimages/* root@\${all_name}:/root/conimages/ done for allimageName in \${allimages[@]} do for all_name in \${ALL_NAMES[@]} do echo "\${allimageName} copy to \${all_name}" ssh root@\${all_name} "ctr -n k8s.io images import conimages/\${allimageName}\.tar" done done EOF #确认版本,提前下载镜像 [root@master01 ~]# bash kubeadm/conloadimage.sh