Last active
June 9, 2020 06:57
-
-
Save myclau/d63b44bb6f19b023a87c74f58c32367a to your computer and use it in GitHub Desktop.
Drain k8s node
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
#find node names | |
kubectl get no | |
set NODENAME=xxxxxxxxxxxxxxx | |
kubectl cordon $NODENAME | |
#check pod on node | |
kubectl get pods --all-namespaces --field-selector spec.nodeName=$NODENAME -o wide | |
#find mysql pod | |
kubectl get pods --all-namespaces --field-selector spec.nodeName=$NODENAME -o wide | grep mysql | |
#manual remove pod | |
kubectl -n <namespacename> delete pod <podname> | |
#remove stuck pods | |
kubectl -n <namespacename> delete pod <podname> --grace-period 0 --force | |
#drain node | |
kubectl drain $NODENAME --ignore-daemonsets | |
if it appear something like | |
``` | |
There are pending nodes to be drained: | |
$NODENAME | |
error: pods with local storage (use --delete-local-data to override): podname1-75ddd47ff5-hptq2, podname2-7d8cf5b448-j8bx4 | |
``` | |
kubectl get pods --all-namespaces --field-selector spec.nodeName=$NODENAME -o wide | grep -E "podname1-75ddd47ff5-hptq2|podname2-7d8cf5b448-j8bx4" | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod | |
#check pod on node | |
kubectl get pods --all-namespaces --field-selector spec.nodeName=$NODENAME -o wide |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment