calico.yaml:calico网络组件部署文件,位于config/calico/目录
提示:如上仅需Master01节点操作,更多config文件参考:https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2。
此kubeadm部署初始化配置更多参考:https://pkg.go.dev/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2?tab=doc。
默认kubeadm配置可使用kubeadm config print init-defaults > config.yaml生成。
提示:如上仅需Master01节点操作,从而实现所有节点自动启动服务。
初始化集群-Master 拉取镜像 [root@master01 ~]# kubeadm --kubernetes-version=v1.20.4 config images list #列出所需镜像 [root@master01 ~]# cat config/conloadimage.sh #确认版本,提前下载镜像 #!/bin/sh #****************************************************************# # ScriptName: conloadimage.sh # Author: xhy # Create Date: 2021-02-25 14:03 # Modify Author: xhy # Modify Date: 2021-02-25 14:03 # Version: #***************************************************************# KUBE_VERSION=v1.20.4 CALICO_VERSION=v3.17.1 CALICO_URL='crictl.io/calico' KUBE_PAUSE_VERSION=3.2 ETCD_VERSION=3.4.13-0 CORE_DNS_VERSION=1.7.0 GCR_URL=k8s.gcr.io METRICS_SERVER_VERSION=v0.4.1 INGRESS_VERSION=v0.41.2 CSI_PROVISIONER_VERSION=v1.4.0 CSI_NODE_DRIVER_VERSION=v1.2.0 CSI_ATTACHER_VERSION=v2.0.0 CSI_RESIZER_VERSION=v0.3.0 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/ # 设置节点信息 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} pause-amd64:${KUBE_PAUSE_VERSION} etcd:${ETCD_VERSION} coredns:${CORE_DNS_VERSION} ) 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} ${QUAY_URL}/k8scsi/${csiimageName} ctr -n k8s.io images rm ${UCLOUD_URL}/${csiimageName} ctr -n k8s.io images export conimages/${csiimageName}\.tar ${QUAY_URL}/k8scsi/${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 [root@master01 ~]# bash config/conloadimage.sh