This topic explains how to scale a Tanzu Kubernetes cluster in three ways:

Scale Worker Nodes with Cluster Autoscaler

To enable Cluster Autoscaler in a Tanzu Kubernetes cluster, use the --enable-cluster-options autoscaler option of the tkg create cluster command:

  1. Set the following configuration parameters either in the Tanzu Kubernetes Grid configuration file, .tkg/config.yaml, or as environment variables:

    • For clusters with a single machine deployment such as dev clusters on vSphere, Amazon EC2, or Azure and prod clusters on vSphere or Azure, set AUTOSCALER_MIN_SIZE_0 and AUTOSCALER_MAX_SIZE_0.
    • For clusters with multiple machine deployments such as prod clusters on Amazon EC2, set:
      • AUTOSCALER_MIN_SIZE_0 and AUTOSCALER_MAX_SIZE_0
      • AUTOSCALER_MIN_SIZE_1 and AUTOSCALER_MAX_SIZE_1
      • AUTOSCALER_MIN_SIZE_2 and AUTOSCALER_MAX_SIZE_2

    You cannot modify these values after you deploy the cluster. For information about the default configuration of Cluster Autoscaler in Tanzu Kubernetes Grid, including the above variables, see Autoscaler Configuration Options.

  2. Create the cluster. For example:

     tkg create cluster example-cluster --plan prod --enable-cluster-options autoscaler 

    For each Tanzu Kubernetes cluster that you create with the --enable-cluster-options autoscaler option, Tanzu Kubernetes Grid creates a Cluster Autoscaler deployment in the management cluster. To disable Cluster Autoscaler, delete the Cluster Autoscaler deployment associated with your Tanzu Kubernetes cluster.

Autoscaler Configuration Options

The table below describes the default configuration of Cluster Autoscaler in Tanzu Kubernetes Grid. To modify one or more of these configuration options, set them either in the Tanzu Kubernetes Grid configuration file, .tkg/config.yaml, or as environment variables before running tkg create cluster.

Variable Default value Description
AUTOSCALER_MAX_NODES_TOTAL 0 Maximum number of worker nodes in the cluster. Cluster Autoscaler does not attempt to scale your cluster beyond this limit. If set to 0, Cluster Autoscaler makes scaling decisions based on the minimum and maximum values that you configure for each machine deployment. See below.
AUTOSCALER_SCALE_DOWN_DELAY_AFTER_ADD 10m Amount of time that Cluster Autoscaler waits after a scale-up operation and then resumes scale-down scans.
AUTOSCALER_SCALE_DOWN_DELAY_AFTER_DELETE 10s Amount of time that Cluster Autoscaler waits after deleting a node and then resumes scale-down scans.
AUTOSCALER_SCALE_DOWN_DELAY_AFTER_FAILURE 3m Amount of time that Cluster Autoscaler waits after a scale-down failure and then resumes scale-down scans.
AUTOSCALER_SCALE_DOWN_UNNEEDED_TIME 10m Amount of time that Cluster Autoscaler must wait before scaling down an eligible node.
AUTOSCALER_MAX_NODE_PROVISION_TIME 15m Maximum amount of time Cluster Autoscaler waits for a node to be provisioned.
AUTOSCALER_MIN_SIZE_0 (required, all IaaSes) If not set, defaults to the value of WORKER_MACHINE_COUNT for clusters with a single machine deployment or WORKER_MACHINE_COUNT_0 for clusters with multiple machine deployments. Minimum number of worker nodes. Cluster Autoscaler does not attempt to scale down the nodes below this limit. For prod clusters on Amazon EC2, AUTOSCALER_MIN_SIZE_0 sets the minimum number of worker nodes in the first AZ.
AUTOSCALER_MAX_SIZE_0 (required, all IaaSes) If not set, defaults to the value of WORKER_MACHINE_COUNT for clusters with a single machine deployment or WORKER_MACHINE_COUNT_0 for clusters with multiple machine deployments. Maximum number of worker nodes. Cluster Autoscaler does not attempt to scale up the nodes beyond this limit. For prod clusters on Amazon EC2, AUTOSCALER_MAX_SIZE_0 sets the maximum number of worker nodes in the first AZ.
AUTOSCALER_MIN_SIZE_1 (required, use only for prod clusters on Amazon EC2) If not set, defaults to the value of WORKER_MACHINE_COUNT_1. Minimum number of worker nodes in the second AZ. Cluster Autoscaler does not attempt to scale down the nodes below this limit.
AUTOSCALER_MAX_SIZE_1 (required, use only for prod clusters on Amazon EC2) If not set, defaults to the value of WORKER_MACHINE_COUNT_1. Maximum number of worker nodes nodes in the second AZ. Cluster Autoscaler does not attempt to scale up the nodes beyond this limit.
AUTOSCALER_MIN_SIZE_2 (required, use only for prod clusters on Amazon EC2) If not set, defaults to the value of WORKER_MACHINE_COUNT_2. Minimum number of worker nodes in the third AZ. Cluster Autoscaler does not attempt to scale down the nodes below this limit.
AUTOSCALER_MAX_SIZE_2 (required, use only for prod clusters on Amazon EC2) If not set, defaults to the value of WORKER_MACHINE_COUNT_2 Maximum number of worker nodes in the third AZ. Cluster Autoscaler does not attempt to scale up the nodes beyond this limit.

Scale a Cluster Horizontally With the Tanzu Kubernetes Grid CLI

To horizontally scale a Tanzu Kubernetes cluster, use the tkg scale cluster command. You change the number of control plane nodes by specifying the --controlplane-machine-count option. You change the number of worker nodes by specifying the --worker-machine-count option.

NOTE: On clusters that run in vSphere with Tanzu, you can only run either 1 control plane node or 3 control plane nodes. You can scale up the number of control plane nodes from 1 to 3, but you cannot scale down the number from 3 to 1.

  • To scale a cluster that you originally deployed with 3 control plane nodes and 5 worker nodes to 5 and 10 nodes respectively, run the following command:

    tkg scale cluster cluster_name --controlplane-machine-count 5 --worker-machine-count 10

    If you initially deployed a cluster with --controlplane-machine-count 1 and then you scale it up to 3 control plane nodes, Tanzu Kubernetes Grid automatically enables stacked HA on the control plane.

  • If the cluster in running in a namespace other than the default namespace, you must specify the --namespace option to scale that cluster.

    tkg scale cluster cluster_name --controlplane-machine-count 5 --worker-machine-count 10 --namespace=my-namespace

IMPORTANT: Do not change context or edit the .kube-tkg/config file while Tanzu Kubernetes Grid operations are running.

Scale a Cluster Vertically With kubectl

To vertically scale a Tanzu Kubernetes cluster, follow the Changing Infrastructure Machine Templates procedure in The Cluster API Book, which changes the cluster's machine template.

The procedure downloads the cluster's existing machine template, with a kubectl get command that you can construct as follows:

kubectl get MACHINE-TEMPLATE-TYPE MACHINE-TEMPLATE-NAME -o yaml

Where:

  • MACHINE-TEMPLATE-TYPE is:
    • VsphereMachineTemplate on vSphere
    • AWSMachineTemplate on Amazon EC2
    • AzureMachineTemplate on Azure
  • MACHINE-TEMPLATE-NAME is the name of the machine template for the cluster nodes that you are scaling, which follows the form:
    • CLUSTER-NAME-control-plane for control plane nodes
    • CLUSTER-NAME-worker for worker nodes

For example:

kubectl get VsphereMachineTemplate monitoring-cluster-worker -o yaml
check-circle-line exclamation-circle-line close-line
Scroll to top icon