附031.Kubernetes_v1.20.4高可用部署架构二 (3)

calico.yaml:calico网络组件部署文件,位于config/calico/目录

[root@master01 ~]# cat kubeadm-config.yaml #检查集群初始化配置 apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration networking: serviceSubnet: "10.20.0.0/16" #设置svc网段 podSubnet: "10.10.0.0/16" #设置Pod网段 dnsDomain: "cluster.local" kubernetesVersion: "v1.20.4" #设置安装版本 controlPlaneEndpoint: "172.16.10.254:16443" #设置相关API VIP地址 apiServer: certSANs: - master01 - master02 - master03 - 127.0.0.1 - 172.16.10.11 - 172.16.10.12 - 172.16.10.13 - 172.16.10.254 timeoutForControlPlane: 4m0s certificatesDir: "/etc/kubernetes/pki" imageRepository: "k8s.gcr.io" --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 kind: KubeProxyConfiguration featureGates: SupportIPVSProxyMode: true mode: ipvs


提示:如上仅需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生成。

启动服务 [root@master01 ~]# cat /etc/keepalived/keepalived.conf [root@master01 ~]# cat /etc/keepalived/check_apiserver.sh #确认Keepalived配置 [root@master01 ~]# for master_ip in ${MASTER_IPS[@]} do echo ">>> ${master_ip}" ssh root@${master_ip} "systemctl start haproxy.service && systemctl enable haproxy.service" ssh root@${master_ip} "systemctl start keepalived.service && systemctl enable keepalived.service" ssh root@${master_ip} "systemctl status keepalived.service | grep Active" ssh root@${master_ip} "systemctl status haproxy.service | grep Active" done [root@master01 ~]# for all_ip in ${ALL_IPS[@]} do echo ">>> ${all_ip}" ssh root@${all_ip} "ping -c1 172.16.10.254" done #等待10s执行检查

提示:如上仅需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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsxypz.html