gcloud -q compute instances delete \
controller0 controller1 controller2 \
worker0 worker1 worker2
gcloud -q compute forwarding-rules delete kubernetes-rule
gcloud -q compute target-pools delete kubernetes-pool
gcloud -q compute http-health-checks delete kube-apiserver-check
gcloud -q compute addresses delete kubernetes
gcloud -q compute firewall-rules delete \
kubernetes-allow-api-server \
kubernetes-allow-healthz \
kubernetes-allow-icmp \
kubernetes-allow-internal \
kubernetes-allow-rdp \
kubernetes-nginx-service \
kubernetes-allow-ssh
gcloud -q compute routes delete \
kubernetes-route-10-200-0-0-24 \
kubernetes-route-10-200-1-0-24 \
kubernetes-route-10-200-2-0-24
gcloud -q compute networks subnets delete kubernetes
gcloud -q compute networks delete kubernetes
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}" | \
jq -j '.Reservations[].Instances[].InstanceId')
aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
done
aws iam remove-role-from-instance-profile \
--instance-profile-name kubernetes \
--role-name kubernetes
aws iam delete-instance-profile \
--instance-profile-name kubernetes
aws iam delete-role-policy \
--role-name kubernetes \
--policy-name kubernetes
aws iam delete-role --role-name kubernetes
aws ec2 delete-key-pair --key-name kubernetes
Be sure to wait about a minute for all VMs to terminates to avoid the following errors:
An error occurred (DependencyViolation) when calling ...
Network resources cannot be deleted while VMs hold a reference to them.
aws elb delete-load-balancer \
--load-balancer-name kubernetes
VPC_ID=$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.Vpcs[].VpcId')
INTERNET_GATEWAY_ID=$(aws ec2 describe-internet-gateways \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.InternetGateways[].InternetGatewayId')
aws ec2 detach-internet-gateway \
--internet-gateway-id ${INTERNET_GATEWAY_ID} \
--vpc-id ${VPC_ID}
aws ec2 delete-internet-gateway \
--internet-gateway-id ${INTERNET_GATEWAY_ID}
SECURITY_GROUP_ID=$(aws ec2 describe-security-groups \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.SecurityGroups[].GroupId')
aws ec2 delete-security-group \
--group-id ${SECURITY_GROUP_ID}
SUBNET_ID=$(aws ec2 describe-subnets \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.Subnets[].SubnetId')
aws ec2 delete-subnet --subnet-id ${SUBNET_ID}
ROUTE_TABLE_ID=$(aws ec2 describe-route-tables \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.RouteTables[].RouteTableId')
aws ec2 delete-route-table --route-table-id ${ROUTE_TABLE_ID}
VPC_ID=$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.Vpcs[].VpcId')
aws ec2 delete-vpc --vpc-id ${VPC_ID}
DHCP_OPTION_SET_ID=$(aws ec2 describe-dhcp-options \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.DhcpOptions[].DhcpOptionsId')
aws ec2 delete-dhcp-options \
--dhcp-options-id ${DHCP_OPTION_SET_ID}