Skip to content

Instantly share code, notes, and snippets.

@rimusz
Forked from mgoodness/kube-rotate.sh
Created October 26, 2016 14:13
Show Gist options
  • Save rimusz/fbe51979533c8b896487416f30474551 to your computer and use it in GitHub Desktop.
Save rimusz/fbe51979533c8b896487416f30474551 to your computer and use it in GitHub Desktop.
Bash script for draining & terminating Kubernetes nodes
#!/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