Configure balancing rules via the API
Published on 24 May 2023
Security & Identity (IAM):
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
Requirements:
- You have an account and are logged into the Scaleway console
- You have generated your API key
You can configure balancing rules via the Scaleway API by creating a backend. To do so, you need to customize the following parameters:
-
forward_port
— Load Balancer with forward user sessions to this port. For example, you can use port8080
on a backend, while your front-end port is80
. -
forward_port_algorithm
— A string value, specifying one of the following options:"roundrobin"
— New sessions are balanced equally between the backend servers."leastconn"
— This mode will take into account the number of active sessions, established to each of the servers, and will forward new ones to the server, which has the least."first"
— The first server with available slots will be chosen.
-
server_ip
- A list of IPv4 or IPv6 address of your servers to redirect the load to.export $LB_ID="<ID of your Load Balancer>"export $TOKEN="<Your secret API key>"curl -s -X POST "https://api.scaleway.com/lb/v1/zones/$ZONE/lbs/$LB_ID/backends" -H "accept: application/json" -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" \-d "{\"forward_port\":80,\"forward_port_algorithm\":\"roundrobin\",\"forward_protocol\":\"tcp\",\"health_check\":{\"check_delay\":2000,\"check_max_retries\":3,\"check_timeout\":1000,\"port\":80,\"tcp_config\":{}},\"name\":\"main backend\",\"send_proxy_v2\":false,\"server_ip\":[\"<REPLACE-BY-IP-OF-YOUR-SERVER1>\", \"<REPLACE-BY-IP-OF-YOUR-SERVER2>\"]}" | jq .
Save the ID of the backend for further use.
export $BACKEND_ID="<ID of your backend>"
To delete the backend, run the following command:
curl -H "X-Auth-Token: $TOKEN" -X DELETE "https://api.scaleway.com/lb/v1/zones/$ZONE/lbs/$LB_ID/backends/$BACKEND_ID"
More information is available in our Load Balancer API documentation