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
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"
}
}
}
}
You can enable session affinity when you create your container app via the Azure portal. To enable session affinity:
- On the Create Container App page, select the App settings tab.
- In the Application ingress settings section, select Enabled for the Session affinity setting.
You can also enable or disable session affinity after your container app is created. To enable session affinity:
- Go to your app in the portal.
- Select Ingress.
- You can enable or disable Session affinity by selecting or deselecting Enabled.
- Select Save.