mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Make kube-down more robust for GCE provider
This commit is contained in:
parent
4172c2ec9e
commit
d0eeebaa66
@ -87,7 +87,6 @@ function detect-project () {
|
|||||||
echo "Project: $PROJECT (autodetected from gcloud config)"
|
echo "Project: $PROJECT (autodetected from gcloud config)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Take the local tar files and upload them to Google Storage. They will then be
|
# Take the local tar files and upload them to Google Storage. They will then be
|
||||||
# downloaded by the master as part of the start up script for the master.
|
# downloaded by the master as part of the start up script for the master.
|
||||||
#
|
#
|
||||||
@ -435,40 +434,81 @@ EOF
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete a kubernetes cluster
|
# Delete a kubernetes cluster.
|
||||||
|
#
|
||||||
|
# Assumed vars:
|
||||||
|
# MASTER_NAME
|
||||||
|
# INSTANCE_PREFIX
|
||||||
|
# ZONE
|
||||||
|
# PROJECT
|
||||||
|
# This function tears down cluster resources 10 at a time to avoid issuing too many
|
||||||
|
# API calls and exceeding API quota. It is important to bring down the instances before bringing
|
||||||
|
# down the firewall rules and routes.
|
||||||
function kube-down {
|
function kube-down {
|
||||||
# Detect the project into $PROJECT
|
# Detect the project into $PROJECT
|
||||||
detect-project
|
detect-project
|
||||||
|
|
||||||
echo "Bringing down cluster"
|
echo "Bringing down cluster"
|
||||||
gcloud compute firewall-rules delete \
|
|
||||||
|
# First delete the master (if it exists).
|
||||||
|
gcloud compute instances delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${MASTER_NAME}-https" &
|
--delete-disks all \
|
||||||
|
--zone "${ZONE}" \
|
||||||
local minion
|
"${MASTER_NAME}" || true
|
||||||
for minion in "${MINION_NAMES[@]}"; do
|
# Find out what minions are running.
|
||||||
gcloud compute firewall-rules delete \
|
local -a minions
|
||||||
--project "${PROJECT}" \
|
minions=( $(gcloud compute instances list \
|
||||||
--quiet \
|
--project "${PROJECT}" --zone "${ZONE}" \
|
||||||
"${minion}-all" &
|
--regexp "${INSTANCE_PREFIX}-minion-[0-9]+" \
|
||||||
|
| awk 'NR >= 2 { print $1 }') )
|
||||||
gcloud compute routes delete \
|
# If any minions are running, delete them in batches.
|
||||||
--project "${PROJECT}" \
|
while (( "${#minions[@]}" > 0 )); do
|
||||||
--quiet \
|
echo Deleting nodes "${minions[*]::10}"
|
||||||
"${minion}" &
|
|
||||||
done
|
|
||||||
|
|
||||||
for minion in "${MASTER_NAME}" "${MINION_NAMES[@]}"; do
|
|
||||||
gcloud compute instances delete \
|
gcloud compute instances delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
--delete-disks all \
|
--delete-disks all \
|
||||||
--zone "${ZONE}" \
|
--zone "${ZONE}" \
|
||||||
"${minion}" &
|
"${minions[@]::10}" || true
|
||||||
|
minions=( "${minions[@]:10}" )
|
||||||
|
done
|
||||||
|
|
||||||
|
# Delete firewall rule for the master.
|
||||||
|
gcloud compute firewall-rules delete \
|
||||||
|
--project "${PROJECT}" \
|
||||||
|
--quiet \
|
||||||
|
"${MASTER_NAME}-https" || true
|
||||||
|
|
||||||
|
# Delete firewall rules for minions.
|
||||||
|
# TODO(satnam6502): Adjust this if we move to just one big firewall rule.\
|
||||||
|
local -a firewall_rules
|
||||||
|
firewall_rules=( $(gcloud compute firewall-rules list --project "${PROJECT}" \
|
||||||
|
--regexp "${INSTANCE_PREFIX}-minion-[0-9]+-all" \
|
||||||
|
| awk 'NR >= 2 { print $1 }') )
|
||||||
|
while (( "${#firewall_rules[@]}" > 0 )); do
|
||||||
|
echo Deleting firewall rules "${firewall_rules[*]::10}"
|
||||||
|
gcloud compute firewall-rules delete \
|
||||||
|
--project "${PROJECT}" \
|
||||||
|
--quiet \
|
||||||
|
"${firewall_rules[@]::10}" || true
|
||||||
|
firewall_rules=( "${firewall_rules[@]:10}" )
|
||||||
|
done
|
||||||
|
|
||||||
|
# Delete routes.
|
||||||
|
local -a routes
|
||||||
|
routes=( $(gcloud compute routes list --project "${PROJECT}" \
|
||||||
|
--regexp "${INSTANCE_PREFIX}-minion-[0-9]+" | awk 'NR >= 2 { print $1 }') )
|
||||||
|
while (( "${#routes[@]}" > 0 )); do
|
||||||
|
echo Deleting routes "${routes[*]::10}"
|
||||||
|
gcloud compute routes delete \
|
||||||
|
--project "${PROJECT}" \
|
||||||
|
--quiet \
|
||||||
|
"${routes[@]::10}" || true
|
||||||
|
routes=( "${routes[@]:10}" )
|
||||||
done
|
done
|
||||||
|
|
||||||
wait
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update a kubernetes cluster with latest source
|
# Update a kubernetes cluster with latest source
|
||||||
|
Loading…
Reference in New Issue
Block a user