Scale stateful workloads

This document describes how to scale existing stateful workloads running in a Google Distributed Cloud (GDC) air-gapped Kubernetes cluster. You must scale the pods running in your stateful workloads as your container workload requirements evolve.

This document is for developers within the application operator group who are responsible for managing application workloads for their organization. For more information, see Audiences for GDC air-gapped documentation.

Before you begin

To complete the tasks in this document, you must request the necessary permissions and prepare your environment.

Request IAM roles

You must have specific roles to get the permissions you need to scale stateful workloads. The roles you require depend on whether you are working within an organization-scoped shared cluster or project-scoped standard cluster. For more information, see Kubernetes cluster configurations.

Shared cluster roles

To create, delete, edit, or view workloads in a shared cluster, ask your Project IAM Admin to grant you the Namespace Admin (namespace-admin) role. This role is bound to your project namespace.

Standard cluster roles

To create, delete, edit, or view workloads in a standard cluster, ask your Project IAM Admin to grant you the Cluster Developer (cluster-developer) role. This role is bound to your project namespace.

Prepare your environment

To run commands against a Kubernetes cluster using the API, make sure you have the following resources:

  • Locate the Kubernetes cluster name, or ask a member of the platform administrator group what the cluster name is.

  • Sign in and generate the kubeconfig file for the Kubernetes cluster.

  • Use the kubeconfig path of the Kubernetes cluster to replace KUBERNETES_CLUSTER_KUBECONFIG in these instructions.

Scale a StatefulSet resource

Use the scaling functionality of Kubernetes to appropriately scale the amount of pods running in your StatefulSet resource.

Manually scale the pods of a StatefulSet resource

To manually scale your StatefulSet resource, run:

kubectl --kubeconfig KUBERNETES__CLUSTER_KUBECONFIG -n NAMESPACE \
    scale statefulset STATEFULSET_NAME \
    --replicas NUMBER_OF_REPLICAS

Replace the following:

  • KUBERNETES_CLUSTER_KUBECONFIG: the kubeconfig file for the cluster.

  • NAMESPACE: the namespace. For shared clusters, this must be a project namespace. For standard clusters, it can be any namespace.

  • STATEFULSET_NAME: the name of the StatefulSet object in which to scale.

  • NUMBER_OF_REPLICAS: the number of replicated Pod objects in the StatefulSet object.

Scale the pods by making an in-place update

To scale the pods of a StatefulSet resource directly in the manifest file, run:

kubectl --kubeconfig KUBERNETES__CLUSTER_KUBECONFIG -n NAMESPACE \
    patch statefulsets STATEFULSET_NAME \
    -p '{"spec":{"replicas":NUMBER_OF_REPLICAS}}'

Replace the following:

  • KUBERNETES__CLUSTER_KUBECONFIG: the kubeconfig file for the cluster.

  • NAMESPACE: the namespace. For shared clusters, this must be a project namespace. For standard clusters, it can be any namespace.

  • STATEFULSET_NAME: the name of the StatefulSet object in which to scale.

  • NUMBER_OF_REPLICAS: the number of replicated Pod objects in the StatefulSet object.

What's next