mirror of
https://github.com/jbowdre/vsphere-k8s.git
synced 2024-11-21 15:42:19 +00:00
update script logic
This commit is contained in:
parent
87b627ebcb
commit
17a27d0570
2 changed files with 30 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash -eu
|
||||
source ./env.txt
|
||||
|
||||
if [ "${HOSTNAME}" == "${K8S_INITIAL_NODE}" ]; then
|
||||
if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then
|
||||
echo ">> Configuring kube-vip..."
|
||||
sudo ctr image pull ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}"
|
||||
|
@ -11,8 +12,6 @@ if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then
|
|||
--arp \
|
||||
--leaderElection | sudo tee /etc/kubernetes/manifests/kube-vip.yaml
|
||||
fi
|
||||
|
||||
if [ "${HOSTNAME}" == "${K8S_INITIAL_NODE}" ]; then
|
||||
if ! kubectl get nodes 2>/dev/null; then
|
||||
echo ">> Bootstrapping first controlplane node..."
|
||||
cat << EOF > kubeadminit.yaml
|
||||
|
@ -57,14 +56,14 @@ EOF
|
|||
|
||||
echo ">> Creating discovery config..."
|
||||
kubectl -n kube-public get configmap cluster-info -o jsonpath='{.data.kubeconfig}' > discovery.yaml
|
||||
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml
|
||||
sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml
|
||||
else
|
||||
echo ">> [ERROR] Cluster initialization unsuccessful on ${HOSTNAME}! <<"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo ">> Waiting up to 10 minutes for all control-plane nodes to be Ready..."
|
||||
python3 -m http.server &
|
||||
python3 -m http.server 2>/dev/null &
|
||||
PROC_ID=$!
|
||||
attempts_max=60
|
||||
attempt=0
|
||||
|
@ -388,8 +387,11 @@ else
|
|||
attempt=0
|
||||
until [ -f /etc/kubernetes/discovery.yaml ]; do
|
||||
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
|
||||
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null
|
||||
if [ ! -f /etc/kubernetes/discovery.yaml ]; then
|
||||
if ! sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null; then
|
||||
if [ ${attempt} -eq ${attempts_max} ]; then
|
||||
echo ">> [ERROR] Timeout waiting for discovery.yaml! <<"
|
||||
exit 1
|
||||
fi
|
||||
attempt=$((attempt+1))
|
||||
sleep 10
|
||||
fi
|
||||
|
@ -409,7 +411,17 @@ nodeRegistration:
|
|||
controlPlane:
|
||||
certificateKey: ${KUBEADM_CERTKEY}
|
||||
EOF
|
||||
if sudo kubeadm join "${K8S_CONTROLPLANE_VIP}":6443 --config kubeadmjoin.yaml; then
|
||||
if sudo kubeadm join "${K8S_CONTROLPLANE_VIP}:6443" --config kubeadmjoin.yaml; then
|
||||
if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then
|
||||
echo ">> Configuring kube-vip..."
|
||||
sudo ctr image pull ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}"
|
||||
sudo ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}" vip /kube-vip manifest pod \
|
||||
--interface ens192 \
|
||||
--vip "${K8S_CONTROLPLANE_VIP}" \
|
||||
--controlplane \
|
||||
--arp \
|
||||
--leaderElection | sudo tee /etc/kubernetes/manifests/kube-vip.yaml
|
||||
fi
|
||||
echo ">> Node ${HOSTNAME} successfully initialized!"
|
||||
touch .k8s-node-success
|
||||
mkdir -p "${HOME}"/.kube
|
||||
|
|
|
@ -17,7 +17,7 @@ echo ">> Continuing after $((attempt*10)) seconds."
|
|||
echo ">> Waiting up to 10 minutes for all control-plane nodes..."
|
||||
attempts_max=60
|
||||
attempt=0
|
||||
until "$(wget http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success)" 2>/dev/null; do
|
||||
until wget "http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success" 2>/dev/null; do
|
||||
if [ ${attempt} -eq ${attempts_max} ]; then
|
||||
echo ">> [ERROR] Timeout waiting for control-plane nodes! <<"
|
||||
exit 1
|
||||
|
@ -31,7 +31,7 @@ attempts_max=6
|
|||
attempt=0
|
||||
until [ -f /etc/kubernetes/discovery.yaml ]; do
|
||||
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
|
||||
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null
|
||||
sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null
|
||||
if [ ! -f /etc/kubernetes/discovery.yaml ]; then
|
||||
attempt=$((attempt+1))
|
||||
sleep 10
|
||||
|
|
Loading…
Reference in a new issue