Create a Kubernetes managed Cluster on Google GCP with one line of code

!!Be Careful: running ths may incur costs on your project - make sure to delete the resources when finished!!

prerequisits

  • A project with Kubernetes API enabled
  • GCP CLI installed
  • An environment variable CLUSTER_NAME defined with the name of the cluster
  • Compute/Region set in project configuration to your preferred Region
  • default VPC in place.
gcloud config set compute/zone <preferred-region>
PROJECT_ID=$(gcloud config get-value project)
CLUSTER_NAME=<cluster-name>

The Code :


gcloud beta container clusters create $CLUSTER_NAME \
  --cluster-version=latest \
  --machine-type=e2-standard-4 \
  --enable-autoscaling \
  --min-nodes=1 \
  --max-nodes=3 \
  --num-nodes=1 

Get Credentials


gcloud container sclusters get-credentials $CLUSTER_NAME

Check pods

kubectl get pods -A

Delete cluster

Delte the resources when not longer needed:

cloud container clusters delete  $CLUSTER_NAME