Skip to content

Latest commit

 

History

History
80 lines (55 loc) · 3.03 KB

File metadata and controls

80 lines (55 loc) · 3.03 KB
title Session Affinity in Azure Container Apps
description How to set session affinity (sticky sessions) in Azure Container Apps.
services container-apps
author craigshoemaker
ms.service azure-container-apps
ms.topic how-to
ms.date 05/29/2025
ms.author cshoe
zone_pivot_groups arm-portal

Session Affinity in Azure Container Apps

Session affinity, also known as sticky sessions, is a feature that allows you to route all requests from a client to the same replica. This feature is useful for stateful applications that require a consistent connection to the same replica.

Session stickiness is enforced using HTTP cookies. This feature is available in single revision mode when HTTP ingress is enabled. A client might be routed to a new replica if the previous replica is no longer available.

If your app doesn't require session affinity, we recommend that you don't enable it. With session affinity disabled, ingress distributes requests more evenly across replicas improving the performance of your app.

Note

Session affinity is only supported when your app is in single revision mode and the ingress type is HTTP.

Configure session affinity

::: zone pivot="azure-resource-manager"

Session affinity is configured by setting the affinity property in the ingress.stickySessions configuration section. The following example shows how to configure session affinity for a container app:

{
  ...
  "configuration": {
      "ingress": {
          "external": true,
          "targetPort": 80,
          "transport": "auto",
          "stickySessions": {
              "affinity": "sticky"
          }
      }
  }
}

::: zone-end

::: zone pivot="azure-portal"

You can enable session affinity when you create your container app via the Azure portal. To enable session affinity:

  1. Start at the Azure portal home page, search for Container Apps in the top search bar.

  2. Select Container Apps in the search results and select the Create button.

  3. In the Basics and Container tabs, provide all required values in each section, and then select the Ingress tab.

  4. In the Application ingress settings section, set Ingress to Enabled. Once enabled, the Session affinity setting becomes available.

  5. For Session affinity select Enabled.

:::image type="content" source="media/ingress/screenshot-session-affinity.png" alt-text="Screenshot of the session affinity setting in Create Container App page.":::

You can also enable or disable session affinity after your container app is created. To enable session affinity:

  1. Go to your app in the portal.
  2. Select Ingress.
  3. You can enable or disable Session affinity by selecting or deselecting Enabled.
  4. Select Save.

:::image type="content" source="media/ingress/screenshot-ingress-session-affinity.png" alt-text="Screenshot of session affinity session on Ingress page.":::

::: zone-end

Next steps

[!div class="nextstepaction"] Configure ingress