Skip to content

Instantly share code, notes, and snippets.

@NimJay
Last active March 16, 2023 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimJay/cd0d4ae67bbe0eec6f76916e49e0ca24 to your computer and use it in GitHub Desktop.
Save NimJay/cd0d4ae67bbe0eec6f76916e49e0ca24 to your computer and use it in GitHub Desktop.
Create a GKE Cluster

Create Google Kubernetes Engine (GKE) Cluster

I regularly have to create new Google Kubernetes Engine (GKE) clusters (via Google Cloud Shell). I use the bash snippets below to do so.

Create cluster.

1. Set environment variables.

export PROJECT_ID=$GOOGLE_CLOUD_PROJECT
export CLUSTER_NAME=my-cluster-5
export KUBECONTEXT_NAME=my-cluster-5
export ZONE=us-central1-b
export NUM_OF_NODES=2

2. Create cluster.

gcloud container clusters create ${CLUSTER_NAME} \
  --project=${PROJECT_ID} --zone=${ZONE} \
  --machine-type=e2-standard-4 --num-nodes=${NUM_OF_NODES}

3. Rename the kubeconfig context of the cluster.

kubectx ${CLUSTER_NAME}=gke_${PROJECT_ID}_${ZONE}_${CLUSTER_NAME}

Clean up.

1. Delete cluster using the console/UI.

2. Remove the kubeconfig context of the cluster.

kubectx -d ${CLUSTER_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment