---
schema_version: "1"
id: a3db016f00803cf2fad3a7912cb469897e24416a740d2f46087787e038894e32
title: Autoscale and Add Flex Gateway Replicas to a Namespace
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.9/flex-gateway-k8-high-availability.md
canonical_url: https://docs.mulesoft.com/gateway/1.9/flex-gateway-k8-high-availability
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4b3a30ca8272b0e98aea78d07c6d57e961bdcf77d01e493883f507411d01d6f2
description: MuleSoft Documentation Site
release: "1.9"
latest: false
---
---
product: Omni Gateway
version: 1.9
---

# Autoscale and Add Flex Gateway Replicas to a Namespace

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

For high availability (HA) environments, horizontal scaling distributes load across multiple Flex
Gateway instances. By default, the Helm chart for Flex Gateway is configured with one replica. To
release more Flex Gateway replicas into a namespace, provide one of the following configurations:

- [Set a replica count](#replica-count): Set a fixed number of Flex Gateway replicas to create.

- [Configure autoscaling](#autoscale): Generate replicas automatically based on CPU, memory, and
  other settings.

Find the default Helm chart settings for Flex Gateway (flex-gateway) through one of the following
methods:

- Open the **flex-gateway** page in
  [ArtifactHUB](https://artifacthub.io/packages/helm/flex-gateway/flex-gateway)

- Run `helm show values <helm-repository-name>/<helm-chart-name>` from a terminal window, for
  example, `helm show values flex-gateway/flex-gateway`.

## Before You Begin

Ensure that the following prerequisites are in place:

- A Flex Gateway deployment or a registered Flex Gateway instance (gateway)

  For gateway registration and deployment processes, see
  [Setting Up Self-Managed Flex Gateway](https://docs.mulesoft.com/gateway/1.9/flex-gateway-set-up) or
  [Getting Started with Self-Managed Flex Gateway in a Kubernetes Cluster](https://docs.mulesoft.com/gateway/1.9/flex-gateway-k8-getting-started).

- A Kubernetes cluster for your Flex Gateway deployment

## Set a Replica Count

Configure and verify the number of replicas that you require. Note that new replicas replace
existing replicas. If a newer version of Flex Gateway is available, the command replaces your older
replica versions with the latest version.

The steps to take depend on whether a Helm chart is installed.

1.  If a Helm chart for your namespace is installed, run the following command:

    Syntax:

    helm -n <namespace> upgrade \\ <release-name> <helm-repository-name>/<helm-chart-name> \\
    --reuse-values \\ --set replicaCount=<number of replicas>

    Example:

    ```helm
    helm -n gateway upgrade \
    ingress flex-gateway/flex-gateway \
    --reuse-values \
    --set replicaCount=2
    ```

    When successful, the command prints output similar to this example:

    Release "ingress" has been upgraded. Happy Helming! NAME: ingress LAST DEPLOYED: Mon Apr 17
    15:00:09 2023 NAMESPACE: gateway STATUS: deployed REVISION: 27 TEST SUITE: None

2.  If the Helm chart is not installed, run the following command:

    Syntax:

    helm -n <namespace> \\ upgrade -i --create-namespace \\ <release-name>
    <helm-repository-name>/<helm-chart-name> \\ --set-file registration.content=<registration file>
    \\ --set replicaCount=<number of replicas>

    Example:

    ```helm
    helm -n gateway \
    upgrade -i --create-namespace \
    ingress flex-gateway/flex-gateway \
    --set-file registration.content=registration.yaml \
    --set replicaCount=2
    ```

    When successful, the command prints output similar to this example:

    Release "ingress" does not exist. Installing it now. NAME: ingress LAST DEPLOYED: Mon Apr 17
    15:32:50 2023 NAMESPACE: gateway STATUS: deployed REVISION: 1 TEST SUITE: None

3.  Verify creation of the replicas by running the following command:

    Syntax:

    kubectl get rs -n <namespace>

    Example:

    kubectl get rs -n gateway

    When successful, the command prints output similar to this example:

    NAME DESIRED CURRENT READY AGE ingress-5b7474b8f6 2 2 2 70s

## Configure Autoscaling

Horizontal Pod autoscaling generates Flex Gateway replicas automatically based on CPU, memory, and
other target and behavioral settings. For descriptions of these settings, see
[Autoscaling Parameters](#autoscaling-parameters).

### Update Your Helm Chart with an Autoscaling Configuration

To update your Helm chart with autoscaling parameters:

1.  Create a YAML file with your autoscaling configuration, modifying the settings to meet your
    requirements.

    Example:

    ```yaml
    autoscaling:
      enabled: true
    ```

    > [!NOTE] This configuration file is the minimum autoscaling configuration. To configure
    > autoscaling with more detail, see [Autoscaling Parameters](#autoscaling-parameters).

2.  If a Helm chart for your namespace is installed, run the following command to apply your
    autoscaling configuration:

    Syntax:

    helm -n <namespace> upgrade \\ <release-name> <helm-repository-name>/<helm-chart-name> \\
    --reuse-values \\ -f <your-autoscaling-configuration-yaml>

    Example:

    ```helm
    helm -n gateway upgrade \
    ingress flex-gateway/flex-gateway \
    --reuse-values \
    -f autoscaling.yaml
    ```

    When successful, the command prints output similar to this example:

    Release "ingress" has been upgraded. Happy Helming! NAME: ingress LAST DEPLOYED: Tue Apr 18
    15:46:38 2023 NAMESPACE: gateway STATUS: deployed REVISION: 33 TEST SUITE: None

3.  If the Helm chart is not installed, run the following command to apply the your autoscaling
    configuration:

    Syntax:

    helm -n <namespace> \\ upgrade -i --create-namespace \\ <release-name>
    <helm-repository-name>/<helm-chart-name> \\ --set-file registration.content=<registration file>
    \\ -f <your-autoscaling-configuration-yaml>

    Example:

    ```helm
    helm -n gateway \
    upgrade -i --create-namespace \
    ingress flex-gateway/flex-gateway \
    --set-file registration.content=registration.yaml \
    -f autoscaling.yaml
    ```

    When successful, the command prints output similar to this example:

    NAME: ingress LAST DEPLOYED: Tue Apr 18 15:50:29 2023 NAMESPACE: gateway STATUS: deployed
    REVISION: 1 TEST SUITE: None

4.  Verify your autoscaling configuration by running the following command:

    Syntax:

    ```kubectl
    kubectl get hpa -n <namespace>
    ```

    Example:

    ```kubectl
    kubectl get hpa -n gateway
    ```

    The command prints output similar to this example:

    NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE ingress Deployment/ingress 66%/50%, 5%/50% 2
    11 2 59s

### Autoscaling Parameters

To use autoscaling, enable Horizontal Pod Autoscaler (HPA), and configure other Helm chart settings
to define autoscaling behavior.

<table><colgroup><col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p><code>autoscaling.enabled</code></p></div></div></td><td><div><div><p>Boolean that indicates whether the Horizontal Pod Autoscaler (HPA) is enabled. Defaults to <code>false</code>.</p></div></div></td></tr><tr><td><div><div><p><code>autoscaling.minReplicas</code></p></div></div></td><td><div><div><p>The minimum number of replicas that the HPA scaler is allowed to create. Defaults to <code>2</code>.</p></div></div></td></tr><tr><td><div><div><p><code>autoscaling.maxReplicas</code></p></div></div></td><td><div><div><p>The maximum number of replicas that the HPA scaler is allowed to create. Defaults to <code>11</code>.</p></div></div></td></tr><tr><td><div><div><p><code>autoscaling.targetCPUUtilizationPercentage</code></p></div></div></td><td><div><div><p>A resource metric that sets the average CPU usage percentage of all deployed Pods. Defaults to <code>50</code>.</p></div></div></td></tr><tr><td><div><div><p><code>autoscaling.targetMemoryUtilizationPercentage</code></p></div></div></td><td><div><div><p>A string representing the average memory usage percentage of all deployed Pods. Defaults to <code>nil</code>.</p></div></div></td></tr><tr><td><div><div><p><code>autoscaling.behavior</code></p></div></div></td><td><div><div><p>A setting that supports the <code>HorizontalPodAutoscaler</code> (HPA) object in Kubernetes. HPA settings control autoscaling behavior, such as the number of application resources based on the rate of change to the workload.</p></div></div></td></tr><tr><td><div><div><p><code>autoscaling.behavior.scaleUp</code>, <code>autoscaling.behavior.scaleDown</code></p></div></div></td><td><div><div><p>Settings for autoscaling behavior when the HPA scaler increases (<code>scaleUp</code>) or decreases (<code>scaleDown</code>) the number of replicas. Define scaling behavior with nested parameters:</p></div><div><ul><li><p><code>selectPolicy</code>: If a metric of configured resources indicates that scaling is required, this setting determines when to scale Pods. This setting is necessary because Pods can contain different numbers of replicas. Valid values are <code>Disabled</code>, <code>Min</code>, and <code>Max</code>. Defaults to <code>Max</code>. The <code>Min</code> and <code>Max</code> values indicate whether to scale Pods with the lowest (<code>Min</code>) or highest (<code>Max</code>) number of replicas.</p></li><li><p><code>stabilizationWindowSeconds</code>: The minimum number of seconds to wait to rescale an application after a change to the workload. The goal is to prevent an overly aggressive or unstable response by HPA when scaling too frequently.</p></li><li><p><code>policies</code>: A list of policies that determine scaling behavior:</p><div><ul><li><p><code>type</code>: The type of value for a given policy, 'Percent' or 'Pods'.</p></li><li><p><code>value</code>: The value of the type for a given policy.</p></li><li><p><code>periodSeconds</code>: The number of seconds between scaling operations for a given policy.</p></li></ul></div></li></ul></div></div></td></tr></tbody></table>

For more information about autoscaling, see the
[Kubernetes documentation](https://kubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale/).
