Skip to content

Instantly share code, notes, and snippets.

@WilliamDenniss
Created October 17, 2024 00:13
Show Gist options
  • Save WilliamDenniss/ae865360020ebf60355abffe975213f8 to your computer and use it in GitHub Desktop.
Save WilliamDenniss/ae865360020ebf60355abffe975213f8 to your computer and use it in GitHub Desktop.
GKE bulk node pool upgrader
#!/bin/bash
# Variables
PROJECT_ID="your-project-id" # Replace with your Google Cloud project ID
CLUSTER_NAME="your-cluster-name" # Replace with your GKE cluster name
LOCATION="us-central1" # Replace with the zone of your cluster, e.g., us-central1-a
# Get the current GKE control plane version
CONTROL_PLANE_VERSION=$(gcloud container clusters describe "$CLUSTER_NAME" \
--location "$LOCATION" \
--project "$PROJECT_ID" \
--format="value(currentMasterVersion)")
echo "Current Control Plane Version: $CONTROL_PLANE_VERSION"
# Get the list of node pools in the cluster
NODE_POOLS=$(gcloud container node-pools list --cluster="$CLUSTER_NAME" --location="$LOCATION" --project="$PROJECT_ID" --format="value(name)")
# Update each node pool to the control plane version
for NODE_POOL in $NODE_POOLS; do
echo "Updating node pool: $NODE_POOL"
gcloud container clusters upgrade "$CLUSTER_NAME" \
--node-pool="$NODE_POOL" \
--location="$LOCATION" \
--project="$PROJECT_ID" \
--async \
--quiet
done
echo "All node pools have been updated to the control plane version."
#!/bin/bash
# Variables
PROJECT_ID="your-project-id" # Replace with your Google Cloud project ID
CLUSTER_NAME="your-cluster-name" # Replace with your GKE cluster name
LOCATION="us-central1" # Replace with the zone of your cluster, e.g., us-central1-a
# Get the current GKE control plane version
CONTROL_PLANE_VERSION=$(gcloud container clusters describe "$CLUSTER_NAME" \
--location "$LOCATION" \
--project "$PROJECT_ID" \
--format="value(currentMasterVersion)")
echo "Current Control Plane Version: $CONTROL_PLANE_VERSION"
# Get the list of node pools in the cluster
NODE_POOLS=$(gcloud container node-pools list --cluster="$CLUSTER_NAME" --location="$LOCATION" --project="$PROJECT_ID" --format="value(name)")
# Print the version of each node pool
for NODE_POOL in $NODE_POOLS; do
NODE_VERSION=$(gcloud container node-pools describe "$NODE_POOL" \
--cluster="$CLUSTER_NAME" \
--location="$LOCATION" \
--project="$PROJECT_ID" \
--format="value(version)")
echo "Node pool: $NODE_POOL is running version: $NODE_VERSION"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment