#!/bin/bash # Bring up the control plane after the pause image pull failed, then install Flannel. set -eu export KUBECONFIG=/root/.kube/config log() { echo "=== $* ==="; } log "pause image" docker pull registry.aliyuncs.com/google_containers/pause:3.10.2 docker tag registry.aliyuncs.com/google_containers/pause:3.10.2 registry.k8s.io/pause:3.10 mkdir -p /etc/systemd/system/cri-docker.service.d cat > /etc/systemd/system/cri-docker.service.d/pause.conf << 'EOF' [Service] ExecStart= ExecStart=/usr/local/bin/cri-dockerd --container-runtime-endpoint fd:// --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.10.2 EOF systemctl daemon-reload systemctl restart cri-docker.service systemctl restart kubelet log "wait for api" ok=0 for i in $(seq 1 60); do if curl -sk -m 3 -o /dev/null https://10.0.1.47:6443/readyz; then ok=1 break fi sleep 5 done if [ "$ok" != "1" ]; then echo API_NOT_READY journalctl -u kubelet -n 20 --no-pager -o cat | grep -Ei 'Failed to create sandbox|Error' | tail -n 15 || true crictl --runtime-endpoint unix:///run/cri-dockerd.sock ps -a | head exit 1 fi echo API_READY mkdir -p /root/.kube cp /etc/kubernetes/admin.conf /root/.kube/config chmod 600 /root/.kube/config CFG=/usr/cluster/k8s/kubeadm-config.yaml log "finish kubeadm phases" kubeadm init phase upload-config all --config "$CFG" || true kubeadm init phase kubelet-finalize all --config "$CFG" || true kubeadm init phase bootstrap-token --config "$CFG" || true kubeadm init phase addon all --config "$CFG" log "flannel" if [ ! -s /usr/cluster/k8s/kube-flannel.yml ]; then curl -fL --retry 3 -o /usr/cluster/k8s/kube-flannel.yml \ https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml fi python3 - << 'PY' from pathlib import Path p = Path("/usr/cluster/k8s/kube-flannel.yml") text = p.read_text(encoding="utf-8") if '"EnableNFTables"' not in text: text = text.replace( '"Network": "10.244.0.0/16"', '"Network": "10.244.0.0/16",\n "EnableNFTables": false', ) p.write_text(text, encoding="utf-8") print("flannel yaml ready") PY kubectl apply -f /usr/cluster/k8s/kube-flannel.yml kubectl taint nodes prod102 node-role.kubernetes.io/control-plane:NoSchedule- || true log "wait node" kubectl wait --for=condition=Ready node/prod102 --timeout=240s kubectl get nodes -o wide kubectl get pods -A -o wide echo CONTROL_PLANE_OK