Last active
November 11, 2017 09:13
-
-
Save mgoodness/f1b598857ed2b7c31fa194a0d503136d to your computer and use it in GitHub Desktop.
Bash script for draining & terminating EC2 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=$(echo $1 | cut -f2 -d '/') | |
kubectl drain --force --ignore-daemonsets --delete-local-data ${k8s_node} | |
if [[ $? -eq 0 ]]; then | |
kubectl delete node ${k8s_node} | |
fi | |
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