Skip to content

Instantly share code, notes, and snippets.

@Laxman-SM
Forked from mgoodness/kube-rotate.sh
Created November 11, 2017 09:13
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 Laxman-SM/ea461977e632c187bfca89073ef7ba9c to your computer and use it in GitHub Desktop.
Save Laxman-SM/ea461977e632c187bfca89073ef7ba9c to your computer and use it in GitHub Desktop.
Bash script for draining & terminating EC2 Kubernetes nodes
#!/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