-
-
Save rimusz/fbe51979533c8b896487416f30474551 to your computer and use it in GitHub Desktop.
Bash script for draining & terminating Kubernetes nodes
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
#!/usr/bin/env bash | |
k8s_node="$1" | |
kubectl drain --force --ignore-daemonsets --delete-local-data ${k8s_node} | |
if [[ $? -eq 0 ]]; then | |
instance_id=$(aws ec2 describe-instances --out=text\ | |
--filters Name=network-interface.private-dns-name,Values=${k8s_node} \ | |
--query 'Reservations[0].Instances[0].{InstanceID:InstanceId}') | |
aws ec2 terminate-instances --instance-ids ${instance_id} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment