提示:如上仅需Master01节点操作,从而实现所有节点自动化安装。
[root@master01 ~]# vi hakek8s.sh
#!/bin/sh #****************************************************************# # ScriptName: hakek8s.sh # Author: xhy # Create Date: 2020-06-08 20:00 # Modify Author: xhy # Modify Date: 2020-06-15 18:15 # Version: v2 #***************************************************************# ####################################### # set variables below to create the config files, all files will create at ./config directory ####################################### # master keepalived virtual ip address export K8SHA_VIP=172.24.8.100 # master01 ip address export K8SHA_IP1=172.24.8.71 # master02 ip address export K8SHA_IP2=172.24.8.72 # master03 ip address export K8SHA_IP3=172.24.8.73 # master01 hostname export K8SHA_HOST1=master01 # master02 hostname export K8SHA_HOST2=master02 # master03 hostname export K8SHA_HOST3=master03 # master01 network interface name export K8SHA_NETINF1=eth0 # master02 network interface name export K8SHA_NETINF2=eth0 # master03 network interface name export K8SHA_NETINF3=eth0 # keepalived auth_pass config export K8SHA_KEEPALIVED_AUTH=412f7dc3bfed32194d1600c483e10ad1d # kubernetes CIDR pod subnet export K8SHA_PODCIDR=10.10.0.0 # kubernetes CIDR svc subnet export K8SHA_SVCCIDR=10.20.0.0[root@master01 ~]# ./hakek8s.sh
解释:如上仅需Master01节点操作。执行脚本后会生产如下配置文件清单:
执行k8s_ha.sh脚本后,会自动生成以下配置文件:
kubeadm-config.yaml:kubeadm初始化配置文件,位于当前目录
keepalived:keepalived配置文件,位于各个master节点的/etc/keepalived目录
haproxy:haproxy的配置文件,位于各个master节点的/etc/haproxy/目录
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.18.3" #设置安装版本 controlPlaneEndpoint: "172.24.11.254:16443" #设置相关API VIP地址 apiServer: certSANs: - master01 - master02 - master03 - 127.0.0.1 - 192.168.2.11 - 192.168.2.12 - 192.168.2.13 - 192.168.2.200 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。
提示:如上仅需Master01节点操作,从而实现所有节点自动启动服务。
初始化集群