Skip to content

Pause and delete

To save money on a cluster you don’t use for a while, scale its node pools to zero and stop its Cloud SQL instance. The WAL disks, the bucket and the metadata are kept, so the cluster comes back as it was.

While paused, clients can’t publish or consume, and the console shows the cluster as offline. The cluster management fee, the regional disks, the bucket and the internal load balancer keep billing.

Terminal window
PROJECT=acme-lowtide-dev REGION=us-central1 CLUSTER=lowtide-orders-dev
# Node pools: autoscaling off first, or it adds nodes back for the pending pods.
for pool in $(gcloud container node-pools list --cluster $CLUSTER --region $REGION --project $PROJECT --format='value(name)'); do
gcloud container node-pools update $pool --cluster $CLUSTER --region $REGION --project $PROJECT --no-enable-autoscaling
gcloud container clusters resize $CLUSTER --node-pool $pool --num-nodes 0 --region $REGION --project $PROJECT --quiet
done
# A scale-up the autoscaler started before it was turned off can land after the
# resize. Check that no node group is left above 0; if one is, run the resize again.
gcloud compute instance-groups managed list --project $PROJECT \
--filter="name~^gke-$CLUSTER- AND targetSize>0" --format='value(name)'
# Cloud SQL
SQL=$(gcloud sql instances list --project $PROJECT --format='value(name)' --filter="name~^$CLUSTER-")
gcloud sql instances patch $SQL --project $PROJECT --activation-policy NEVER
Terminal window
gcloud sql instances patch $SQL --project $PROJECT --activation-policy ALWAYS
for pool in $(gcloud container node-pools list --cluster $CLUSTER --region $REGION --project $PROJECT --format='value(name)'); do
gcloud container node-pools update $pool --cluster $CLUSTER --region $REGION --project $PROJECT \
--enable-autoscaling --min-nodes 1 --max-nodes 2
gcloud container clusters resize $CLUSTER --node-pool $pool --num-nodes 1 --region $REGION --project $PROJECT --quiet
done

Use the node counts your size needs (--max-nodes is twice the gateway pods per zone for the gateway pool). The pods are ready again after about 10 minutes: nodes start, the disks attach and each pod recovers its WAL. The next terraform apply of the module also restores the node pools.

On the cluster page, select Delete cluster and type the cluster’s name. The provisioner needs its access for this, so grant it again first if you removed it.

The deletion run:

  1. turns deletion protection off on what exists,
  2. records the WAL disks,
  3. empties the segment bucket,
  4. destroys everything the setup created: the GKE cluster, the Cloud SQL instance with the metadata, the bucket, the network and the service accounts,
  5. deletes the WAL disks, if you left Also delete the disks the cluster keeps on,
  6. deletes the Terraform state bucket last,
  7. removes the cluster from the console.

Clients of the endpoint stop working, and the messages in the cluster are gone. This can’t be undone.

If you turned off Also delete the disks the cluster keeps, the run page lists the disks and the commands to delete them later. They bill until you do.

Afterwards, remove the provisioner’s remaining grants with the commands on the Setup tab, and delete the shadow role you created in each Pub/Sub project if no other cluster uses it.

Remove from the console only removes the cluster from lowtide Cloud and leaves everything in your project. Use it if you deleted the resources yourself.

Delete a cluster you installed with Terraform

Section titled “Delete a cluster you installed with Terraform”
  1. Set deletion_protection = false and run terraform apply. GKE and Cloud SQL refuse deletion otherwise.

  2. List the WAL disks before you destroy, so you can find them afterwards:

    Terminal window
    gcloud compute disks list --project PROJECT \
    --filter="description~'\"kubernetes.io/created-for/pvc/namespace\":\"lowtide\"'"
  3. Empty the segment bucket, or the destroy fails: gcloud storage rm -r "gs://BUCKET/**".

  4. Run terraform destroy. The Helm release is uninstalled first.

  5. Delete the WAL disks once you are sure nothing on them is needed. They are kept on purpose, because a WAL can hold acknowledged messages that are not in Cloud Storage yet. They bill until you delete them:

    Terminal window
    gcloud compute disks delete DISK --region REGION --project PROJECT
  6. Remove the cluster in the console (Delete cluster).

Left behind on purpose: the Private Service Access peering (free; Cloud SQL takes a while to release it), the enabled APIs, and the shadows in your Pub/Sub projects. The Cloud SQL instance name stays reserved for about a week. The module adds a random suffix, so a new install doesn’t collide with it.

helm uninstall lowtide -n lowtide removes the workloads. The WAL volumes are kept (Retain). Delete them, your bucket, database and service accounts yourself, then remove the cluster in the console.