Last active
November 25, 2025 19:47
-
-
Save r3xakead0/945690efa4f221b768b3a5c45b832cef to your computer and use it in GitHub Desktop.
Create a GKE Standard cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e # Stop the script if any command fails | |
| # Get the currently configured GCP Project ID | |
| PROJECT_ID=$(gcloud config get-value project --quiet) | |
| # Validate that a project is set | |
| if [ -z "$PROJECT_ID" ]; then | |
| echo "โ ERROR: No project is configured in gcloud." | |
| echo "Run: gcloud config set project <PROJECT_ID>" | |
| exit 1 | |
| fi | |
| # Define zone and cluster name | |
| ZONE="us-central1-a" | |
| CLUSTER_NAME="standard-cluster" | |
| echo "๐น Active project: $PROJECT_ID" | |
| echo "๐น Zone: $ZONE" | |
| echo "๐น Cluster name: $CLUSTER_NAME" | |
| # Enable required APIs for GKE Autopilot | |
| echo "๐ง Enabling required APIs..." | |
| gcloud services enable \ | |
| container.googleapis.com \ | |
| compute.googleapis.com \ | |
| --project "$PROJECT_ID" | |
| # Create the GKE Standard Cluster | |
| echo "๐ Creating GKE Standard Cluster..." | |
| gcloud container clusters create "$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --num-nodes 1 \ | |
| --machine-type e2-medium \ | |
| --project "$PROJECT_ID" | |
| # Fetch kubeconfig credentials for kubectl | |
| echo "๐ Fetching cluster credentials..." | |
| gcloud container clusters get-credentials "$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --project "$PROJECT_ID" | |
| echo "โ Standard Cluster created successfully!" | |
| echo "Run: kubectl get nodes" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e # Stop the script if any command fails | |
| # Get the currently configured GCP Project ID | |
| PROJECT_ID=$(gcloud config get-value project --quiet) | |
| # Validate that a project is set | |
| if [ -z "$PROJECT_ID" ]; then | |
| echo "โ ERROR: No project is configured in gcloud." | |
| echo "Run: gcloud config set project <PROJECT_ID>" | |
| exit 1 | |
| fi | |
| # Define zone and cluster name | |
| ZONE="us-central1-a" | |
| CLUSTER_NAME="standard-cluster" | |
| CTX="gke_${PROJECT_ID}_${ZONE}_${CLUSTER_NAME}" | |
| echo "๐น Active project: $PROJECT_ID" | |
| echo "๐น Zone: $ZONE" | |
| echo "๐น Cluster name: $CLUSTER_NAME" | |
| # Delete the GKE Standard Cluster if it exists | |
| if gcloud container clusters list --zone "$ZONE" --project "$PROJECT_ID" | grep -q "$CLUSTER_NAME"; then | |
| echo "๐ Deleting GKE Standard Cluster..." | |
| gcloud container clusters delete "$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --project "$PROJECT_ID" \ | |
| --quiet | |
| else | |
| echo "โ ๏ธ Cluster '$CLUSTER_NAME' does not existโskipping GKE delete." | |
| fi | |
| echo "๐งน Cleaning kubeconfig entries..." | |
| kubectl config delete-cluster "$CTX" 2>/dev/null || true | |
| kubectl config delete-context "$CTX" 2>/dev/null || true | |
| kubectl config delete-user "$CTX" 2>/dev/null || true | |
| echo "โ Cluster '$CLUSTER_NAME' deleted and kubeconfig cleaned successfully." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PROJECT_ID=$(gcloud config get-value project) | |
| CLUSTER_NAME="standard-cluster" | |
| gcloud container node-pools create "micro-pool-ssd \ | |
| --cluster="$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --num-nodes 1 \ | |
| --machine-type e2-small \ | |
| --project "$PROJECT_ID" \ | |
| --disk-size "30GB" \ | |
| --no-address | |
| gcloud container node-pools create "micro-pool-hdd" \ | |
| --cluster="$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --num-nodes 1 \ | |
| --machine-type e2-micro \ | |
| --disk-type pd-standard \ | |
| --project "$PROJECT_ID" \ | |
| --enable-private-nodes | |
| gcloud container node-pools list \ | |
| --cluster="$CLUSTER_NAME" \ | |
| --zone="$ZONE" | |
| gcloud container node-pools delete "micro-pool-ssd" \ | |
| --cluster="$CLUSTER_NAME" \ | |
| --zone="$ZONE" | |
| gcloud container node-pools delete "micro-pool-hdd" \ | |
| --cluster="$CLUSTER_NAME" \ | |
| --zone="$ZONE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PROJECT_ID=$(gcloud config get-value project) | |
| ZONE="us-central1-a" | |
| CLUSTER_NAME="standard-cluster" | |
| gcloud services enable \ | |
| container.googleapis.com \ | |
| compute.googleapis.com \ | |
| --project "$PROJECT_ID" | |
| gcloud container clusters create "$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --num-nodes 1 \ | |
| --machine-type e2-medium \ | |
| --project "$PROJECT_ID" | |
| gcloud container clusters get-credentials "$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --project "$PROJECT_ID" | |
| gcloud container clusters delete "$CLUSTER_NAME" \ | |
| --zone "$ZONE" \ | |
| --project "$PROJECT_ID" \ | |
| --quiet | |
| CTX="gke_${PROJECT_ID}_${ZONE}_${CLUSTER_NAME}" | |
| kubectl config delete-cluster "$CTX" | |
| kubectl config delete-context "$CTX" | |
| kubectl config delete-user "$CTX" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment