# 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](https://helm.sh/docs/intro/quickstart/#install-helm) is installed on your system.
* [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) is installed on your system.
* You know the name and namespace of your Connectware installation. See [Obtaining the name, namespace, and version of your Connectware installation](/2-1-2/documentation/connectware-on-kubernetes/connectware-helm-chart.md#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 ${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 ${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 ${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 ${NAMESPACE} -o name | xargs -I % kubectl exec % -- vmq-admin cluster show
```

{% endcode %}

## Scaling Down the Broker Cluster to Zero

#### Prerequisites

* [Helm version 3](https://helm.sh/docs/intro/quickstart/#install-helm) is installed on your system.
* [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) is installed on your system.
* You know the name and namespace of your Connectware installation. See [Obtaining the name, namespace, and version of your Connectware installation](/2-1-2/documentation/connectware-on-kubernetes/connectware-helm-chart.md#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 ${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 ${NAMESPACE} --replicas 0
```

{% endcode %}

3. Verify that all broker pods have been terminated:

{% code lineNumbers="true" %}

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

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cybus.io/2-1-2/documentation/cybusmq/mqtt-broker-storage-volumes-in-kubernetes/scaling-the-broker-cluster.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
