kubernetes kubeadm 部署etcd集群(内部方法二)
一、添加etcd优先级启动# 注意pause版本cat << EOF > /usr/lib/systemd/system/kubelet.service.d/20-etcd-service-manager.conf[Service]ExecStart=#Replace "systemd" with the cgroup driver of your container runti
·
一、添加etcd优先级启动
# 注意pause版本
cat << EOF > /usr/lib/systemd/system/kubelet.service.d/20-etcd-service-manager.conf
[Service]
ExecStart=
# Replace "systemd" with the cgroup driver of your container runtime. The default value in the kubelet is "cgroupfs".
ExecStart=/usr/bin/kubelet --address=127.0.0.1 --pod-manifest-path=/etc/kubernetes/manifests --cgroup-driver=systemd --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.2
Restart=always
EOF
systemctl daemon-reload
systemctl restart kubelet
二、生成配置,sh脚本
# 使用你主机的IP地址或可解析的域名设置HOST0、HOST1和HOST2
export HOST0=192.168.50.121
export HOST1=192.168.50.122
export HOST2=192.168.50.123
# 创建临时目录来存储最终将在其他主机上运行的文件
mkdir -p /tmp/${HOST0}/ /tmp/${HOST1}/ /tmp/${HOST2}/
ETCDHOSTS=(${HOST0} ${HOST1} ${HOST2})
NAMES=("etcd-1" "etcd-2" "etcd-3")
for i in "${!ETCDHOSTS[@]}"; do
HOST=${ETCDHOSTS[$i]}
NAME=${NAMES[$i]}
cat << EOF > /tmp/${HOST}/kubeadmcfg.yaml
apiVersion: "kubeadm.k8s.io/v1beta2"
kind: ClusterConfiguration
etcd:
local:
serverCertSANs:
- "${HOST}"
peerCertSANs:
- "${HOST}"
extraArgs:
initial-cluster: ${NAMES[0]}=https://${ETCDHOSTS[0]}:2380,${NAMES[1]}=https://${ETCDHOSTS[1]}:2380,${NAMES[2]}=https://${ETCDHOSTS[2]}:2380
initial-cluster-state: new
name: ${NAME}
listen-peer-urls: https://${HOST}:2380
listen-client-urls: https://${HOST}:2379
advertise-client-urls: https://${HOST}:2379
initial-advertise-peer-urls: https://${HOST}:2380
imageRepository: registry.aliyuncs.com/google_containers
EOF
done
三、下载镜像
docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.20.2
docker pull registry.aliyuncs.com/google_containers/kube-controller-manager:v1.20.2
docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.20.2
docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.20.2
docker pull registry.aliyuncs.com/google_containers/pause:3.2
docker pull registry.aliyuncs.com/google_containers/etcd:3.4.13-0
docker pull registry.aliyuncs.com/google_containers/coredns:1.7.0
# 可以这样下载
kubeadm config images pull /tmp/${HOST0}/kubeadmcfg.yaml
四、执行脚本 ,ssh分发自行解决
kubeadm init phase certs etcd-ca
HOST1=192.168.50.121
HOST2=192.168.50.122
HOST3=192.168.50.123
kubeadm init phase certs etcd-server --config=/tmp/${HOST3}/kubeadmcfg.yaml
kubeadm init phase certs etcd-peer --config=/tmp/${HOST3}/kubeadmcfg.yaml
kubeadm init phase certs etcd-healthcheck-client --config=/tmp/${HOST3}/kubeadmcfg.yaml
kubeadm init phase certs apiserver-etcd-client --config=/tmp/${HOST3}/kubeadmcfg.yaml
cp -R /etc/kubernetes/pki /tmp/${HOST3}/
find /etc/kubernetes/pki -not -name ca.crt -not -name ca.key -type f -delete
kubeadm init phase certs etcd-server --config=/tmp/${HOST2}/kubeadmcfg.yaml
kubeadm init phase certs etcd-peer --config=/tmp/${HOST2}/kubeadmcfg.yaml
kubeadm init phase certs etcd-healthcheck-client --config=/tmp/${HOST2}/kubeadmcfg.yaml
kubeadm init phase certs apiserver-etcd-client --config=/tmp/${HOST2}/kubeadmcfg.yaml
cp -R /etc/kubernetes/pki /tmp/${HOST2}/
# cleanup non-reusable certificates
find /etc/kubernetes/pki -not -name ca.crt -not -name ca.key -type f -delete
kubeadm init phase certs etcd-server --config=/tmp/${HOST1}/kubeadmcfg.yaml
kubeadm init phase certs etcd-peer --config=/tmp/${HOST1}/kubeadmcfg.yaml
kubeadm init phase certs etcd-healthcheck-client --config=/tmp/${HOST1}/kubeadmcfg.yaml
kubeadm init phase certs apiserver-etcd-client --config=/tmp/${HOST1}/kubeadmcfg.yaml
# No need to move the certs because they are for HOST0
# clean up certs that should not be copied off this host
find /tmp/${HOST2} -name ca.key -type f -delete
find /tmp/${HOST3} -name ca.key -type f -delete
rsync -a /tmp/${HOST3}/pki ${HOST3}:/etc/kubernetes/
rsync -a /tmp/${HOST2}/pki ${HOST2}:/etc/kubernetes/
rsync -a /tmp/${HOST3}/kubeadmcfg.yaml ${HOST3}:~/.
rsync -a /tmp/${HOST2}/kubeadmcfg.yaml ${HOST2}:~/.
五、每台机器执行
root@HOST0 $ kubeadm init phase etcd local --config=/tmp/${HOST0}/kubeadmcfg.yaml
root@HOST1 $ kubeadm init phase etcd local --config=/home/${HOST1}/kubeadmcfg.yaml
root@HOST2 $ kubeadm init phase etcd local --config=/home/${HOST2}/kubeadmcfg.yaml
更多推荐
已为社区贡献2条内容
所有评论(0)