Skip to content

Instantly share code, notes, and snippets.

@r3xakead0
Last active November 25, 2025 19:47
Show Gist options
  • Select an option

  • Save r3xakead0/945690efa4f221b768b3a5c45b832cef to your computer and use it in GitHub Desktop.

Select an option

Save r3xakead0/945690efa4f221b768b3a5c45b832cef to your computer and use it in GitHub Desktop.
Create a GKE Standard cluster
#!/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"
#!/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."
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"
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