mirror of
https://github.com/kelseyhightower/kubernetes-the-hard-way.git
synced 2025-10-17 01:12:52 +03:00
cleanup ec2: Ignore terminated instances
If users had previously terminated an instance and recreated it, e.g manually in the console, the clean-up script will have issues since terminated instance remain available in AWS some time. This commit only takes instances with a state of stopped or running for termination.
This commit is contained in:
@@ -67,7 +67,7 @@ KUBERNETES_HOSTS=(controller0 controller1 controller2 worker0 worker1 worker2)
|
||||
```
|
||||
for host in ${KUBERNETES_HOSTS[*]}; do
|
||||
INSTANCE_ID=$(aws ec2 describe-instances \
|
||||
--filters "Name=tag:Name,Values=${host}" | \
|
||||
--filters "Name=tag:Name,Values=${host}" "Name=instance-state-name,Values=running,stopped" | \
|
||||
jq -j '.Reservations[].Instances[].InstanceId')
|
||||
aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
|
||||
done
|
||||
|
Reference in New Issue
Block a user