How to stop gcloud container engine clusters

Solution 1:

You can temporarily scale the number of nodes in your cluster down to zero by running:

gcloud container clusters resize $CLUSTER_NAME --num-nodes=0

Then scale it back up later by running that with a non-zero value for the size flag.

Solution 2:

--zone also shoud be specified to be able to resize cluster nodes to zero in gcloud SDK v 2.0.27

gcloud container clusters resize $CLUSTER --size=0 --zone=$ZONE

Solution 3:

This problem obviously needs an improved solution, as I still had to use the GCP console under Kubernetes Engine -> Clusters.

I changed the number of nodes running in my cluster to 0, as well as changing the minimum number of nodes to 0, because autoscaling was enabled and then it worked.

The gcloud command above provides useful insight, but it fails due to the autoscaling feature that is enabled. A better solution would be to scale down the minimum number of nodes to 0 before resizing the cluster to zero as seen below:

gcloud container clusters update [CLUSTER_NAME] --enable-autoscaling \
    --min-nodes 0 --max-nodes 10 --node-pool [NODE_POOL_NAME]

Or you can disable autoscaling completely:

gcloud container clusters update [CLUSTER_NAME] --no-enable-autoscaling \
--node-pool [NODE_POOL_NAME] --project [PROJECT_ID]]

Then you can now resize the cluster nodes to zero:

gcloud container clusters resize [CLUSTER_NAME] --num-nodes=0

Solution 4:

The same effect can be achieved in the web GCP console by clicking the Edit button on the cluster and setting the size of every node pool to 0.

Reference: https://cloud.google.com/kubernetes-engine/docs/how-to/resizing-a-cluster