How to stop gcloud container engine clusters
Asked Answered
P

5

53

I use gcloud to provision kubernetes clusters, and use container engine to do so.

Aside from the production cluster, I would like to create short-lived clusters, for testing etc'.

Instead of recreating clusters, I would like to have a test cluster and be able to stop/start on demand. Trying to hit "stop" on the vm instances listed at compute engine will make them restart eventually.

What is the proper way to stop & start a test cluster?

The motivation for short lived test clusters is from cost consideration.

Plump answered 12/7, 2016 at 8:1 Comment(0)
T
112

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.

Tellurian answered 12/7, 2016 at 9:3 Comment(4)
Thanks! the docs are a bit tricky on this subject. This doc has all the CRUD operation on a cluster except the U (resize), while the resize doc is detached from the other how-to guides.Plump
When I do this on a cluster that was created with gcloud container clusters create $CLUSTER_NAME --num-nodes 1 --machine-type g1-small, gcloud container clusters describe $CLUSTER_NAME still reports currentNodeCount: 1. What am I getting wrong?Absenteeism
Oh, so it apparently takes a few seconds (after gcloud container clusters resize $CLUSTER_NAME --size=0 returns) for the change to become effective. When taking this into account, now works for me also.Absenteeism
Note that this will not work with all machine types. For example a cluster of f1-micro instances needs to be at least of size 3 (this is enforced both in the GUI console and the CLI).Sicklebill
E
27

--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
Erminois answered 7/11, 2017 at 19:52 Comment(0)
R
15

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
Respecting answered 9/9, 2018 at 2:28 Comment(0)
I
7

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

Israelite answered 27/6, 2018 at 12:0 Comment(0)
C
1

You can do it by following below steps:

  1. Go to the GKE page and select the name of the cluster you want to pause. Click on the "Nodes" tab.
  2. In the "Node Pools" section, click the name of the pool you wish to resize. Click on "Resize."
  3. In the "Number of Nodes" field, enter "0" and click "Resize."
Counterclaim answered 21/10, 2023 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.