Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Success-Guy/3a79c72d613af1814c0e6360944def75 to your computer and use it in GitHub Desktop.
Save Success-Guy/3a79c72d613af1814c0e6360944def75 to your computer and use it in GitHub Desktop.
Auto-remove Node that is NotReady from Kubernetes cluster
#!/bin/bash
# Get the list of nodes in the Kubernetes cluster
nodes=$(kubectl get node)
# Filter the nodes that are NotReady and not control-plane
notready=$(echo "$nodes" | awk '$2 == "NotReady" && $3!="control-plane" {print $1}')
# Check if there are any nodes that are NotReady and not control-plane
if [[ -n "$notready" ]]; then
# If there are, delete those nodes
echo "The following nodes are NotReady and not control-plane, deleting them:"
echo "$notready"
kubectl delete node $notready
# Optionally, restart the coredns deployment in the kube-system namespace
echo "Restarting coredns deployment in kube-system namespace..."
kubectl -n kube-system rollout restart deployment coredns
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment