Configure sticky sessions for your load balancers
Reviewed on · View on GitHub
You can configure sticky sessions — stickiness — for your load balancers to ensure that all the requests from the same client are directed to the same backend VM (Virtual Machine) for the duration of the session.
Permissions
This action requires the following IAM (Identity and Access Management) permissions:
- compute.loadBalancer.update
- Console
- API
- Terraform
- From the left-hand side menu, click Network → Load Balancers to access the list of load balancers.
- Click the name of the load balancer for which you want to configure sticky sessions.
- In the "Policies" tab, click Create a policy.
- Configure the parameters of the stickiness policy.
- Click Create. The stickiness policy is created and associated with the load balancer.
Before you start: Make sure that your load balancer has a listener for the HTTP or HTTPS protocols, because sticky sessions can only be configured for these protocols.
The POST /compute/spaces/{spaceId}/loadBalancers/{id}/policies command creates a stickiness policy with sticky sessions whose lifetime is defined by that of the browser.
The created policy can only be used with HTTP or HTTPS listeners. If this policy is set up by a load balancer, the load balancer uses this cookie for all incoming requests in order to redirect them to the specified backend VM. If the cookie is not present, the load balancer sends the request to another server according to its load-balancing algorithm.
You can also create a stickiness policy with a sticky session lifetime matching that of a cookie generated by the application. Unlike the other type of policy, the lifetime of the special Load Balancer Unit (LBU) cookie follows that of the cookie generated by the application specified in the policy configuration. The load balancer inserts a new stickiness cookie only when the application response contains a new application cookie.
The session stops being sticky if the application cookie is deleted or expires, until a new application cookie is issued.
Request example: Configure sticky sessions for a load balancer
The Terraform documentation is available on the Numspot registry ↗.