Skip to content

Commit

Permalink
Merge pull request #885 from areed/nlb-2
Browse files Browse the repository at this point in the history
Make Kubernetes API health checks more reliable
  • Loading branch information
areed authored Nov 11, 2020
2 parents 38d7663 + 3e6a4b3 commit e00c7f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 10 additions & 1 deletion scripts/common/kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function kubernetes_api_address() {
}

function kubernetes_api_is_healthy() {
curl --noproxy "*" --fail --silent --insecure "https://$(kubernetes_api_address)/healthz"
curl --noproxy "*" --fail --silent --insecure "https://$(kubernetes_api_address)/healthz" >/dev/null
}

function spinner_kubernetes_api_healthy() {
Expand All @@ -178,6 +178,15 @@ function spinner_kubernetes_api_healthy() {
fi
}

# With AWS NLB kubectl commands may fail to connect to the Kubernetes API immediately after a single
# successful health check
function spinner_kubernetes_api_stable() {
for i in {1..10}; do
sleep 1
spinner_kubernetes_api_healthy
done
}

function kubernetes_drain() {
kubectl drain "$1" \
--delete-local-data \
Expand Down
8 changes: 4 additions & 4 deletions scripts/common/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ function upgrade_kubernetes_local_master_patch() {

kubernetes_drain "$node"

spinner_kubernetes_api_healthy
spinner_kubernetes_api_stable
kubeadm upgrade apply "v$k8sVersion" --yes --config /opt/replicated/kubeadm.conf --force
sed -i "s/kubernetesVersion:.*/kubernetesVersion: v${k8sVersion}/" /opt/replicated/kubeadm.conf

kubernetes_install_host_packages "$k8sVersion"
systemctl daemon-reload
systemctl restart kubelet
spinner_kubernetes_api_healthy
spinner_kubernetes_api_stable
kubectl uncordon "$node"

spinner_until 120 kubernetes_node_has_version "$node" "$k8sVersion"
Expand Down Expand Up @@ -178,7 +178,7 @@ EOF
printf "${YELLOW}Drain local node and apply upgrade? ${NC}"
confirmY " "

spinner_kubernetes_api_healthy
spinner_kubernetes_api_stable
kubeadm upgrade apply "v$k8sVersion" --yes --config /opt/replicated/kubeadm.conf --force
upgrade_etcd_image_18 "$k8sVersion"
sed -i "s/kubernetesVersion:.*/kubernetesVersion: v${k8sVersion}/" /opt/replicated/kubeadm.conf
Expand All @@ -187,7 +187,7 @@ EOF
systemctl daemon-reload
systemctl restart kubelet

spinner_kubernetes_api_healthy
spinner_kubernetes_api_stable
kubectl uncordon "$node"

# force deleting the cache because the api server will use the stale API versions after kubeadm upgrade
Expand Down
3 changes: 2 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ EOF
spinner_until 120 cert_has_san "$PRIVATE_ADDRESS:6443" "$LOAD_BALANCER_ADDRESS"
fi

spinner_kubernetes_api_stable

exportKubeconfig
KUBEADM_TOKEN_CA_HASH=$(cat /tmp/kubeadm-init | grep 'discovery-token-ca-cert-hash' | awk '{ print $2 }' | head -1)

Expand Down Expand Up @@ -173,7 +175,6 @@ EOF
fi
fi

spinner_kubernetes_api_healthy
labelNodes
kubectl cluster-info

Expand Down

0 comments on commit e00c7f1

Please sign in to comment.