NavigationContentFooter
Suggest an edit

Configure balancing rules via the API

Published on 27 November 2023

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • A valid 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 port 8080 on a backend, while your front-end port is 80.

  • 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

Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway