Last active
January 15, 2024 09:52
-
-
Save Success-Guy/3a79c72d613af1814c0e6360944def75 to your computer and use it in GitHub Desktop.
Auto-remove Node that is NotReady from Kubernetes cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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