# Scaling the Broker Cluster

Scaling the broker cluster allows you to adjust the number of broker replicas in your Kubernetes deployment, either by adding (scaling up) or removing (scaling down) broker nodes.

## Scaling the Broker Cluster Up or Down

#### Prerequisites

* Helm version 3 is installed on your system.
* The Kubernetes command-line tool kubectl is configured and has access to the target installation.
* You know the name and namespace of your Connectware installation. See [Obtaining the name, namespace, and version of your Connectware installation](https://docs.cybus.io/2-0-6/connectware-on-kubernetes/connectware-helm-chart#obtaining-the-name-namespace-and-version-of-your-connectware-installation).

#### Procedure

1. Check how many replicas are currently set for the broker StatefulSet:

{% code lineNumbers="true" %}

```bash
kubectl get sts broker -n ${CONNECTWARE_NAMESPACE}
```

{% endcode %}

**Example output**

```
NAME     READY   AGE
broker   3/3     6m52s
```

2. Scale the StatefulSet to the desired number of replicas.

* To scale up (add brokers), increase the replica count. For example, to scale up from 2 to 3 replicas:

{% code lineNumbers="true" %}

```bash
kubectl scale sts broker -n ${CONNECTWARE_NAMESPACE} --replicas 3
```

{% endcode %}

* To scale down (remove brokers), decrease the replica count. For example, to scale down from 3 to 2 replicas:

{% code lineNumbers="true" %}

```bash
kubectl scale sts broker -n ${CONNECTWARE_NAMESPACE} --replicas 2
```

{% endcode %}

4. Verify that all broker nodes have formed a healthy cluster:

{% code lineNumbers="true" %}

```bash
kubectl get pod -lapp=broker -n ${CONNECTWARE_NAMESPACE} -o name | xargs -I % kubectl exec % -- vmq-admin cluster show
```

{% endcode %}

## Scaling Down the Broker Cluster to Zero

#### Prerequisites

* Helm version 3 is installed on your system.
* The Kubernetes command-line tool kubectl is configured and has access to the target installation.
* You know the name and namespace of your Connectware installation. See [Obtaining the name, namespace, and version of your Connectware installation](https://docs.cybus.io/2-0-6/connectware-on-kubernetes/connectware-helm-chart#obtaining-the-name-namespace-and-version-of-your-connectware-installation).

#### Procedure

1. Check how many replicas are currently set for the broker StatefulSet:

{% code lineNumbers="true" %}

```bash
kubectl get sts broker -n ${CONNECTWARE_NAMESPACE}
```

{% endcode %}

**Example output**

```
NAME     READY   AGE
broker   3/3     6m52s
```

2. Set the number of broker replicas to zero to remove all broker pods:

{% code lineNumbers="true" %}

```bash
kubectl scale sts broker -n ${CONNECTWARE_NAMESPACE} --replicas 0
```

{% endcode %}

3. Verify that all broker pods have been terminated:

{% code lineNumbers="true" %}

```bash
kubectl get pods -n ${CONNECTWARE_NAMESPACE} -l app=broker
```

{% endcode %}
