Tutorials

Manage backends

In your load balancer configuration, a backend defines a pool of servers to load balance.

You can manage backends programmatically by calling the API endpoint /services/haproxy/configuration/backends.

Note

The version parameter in DELETE, POST, and PUT requests must match the system’s current version. The examples in this section use a GET request to /v2/services/haproxy/configuration/version to retrieve the version and populate the CFGVER environment variable for the URL version parameter.

List backends Jump to heading

To get a list of backends, make a GET request to the backends endpoint:

bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends"
bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends"
output
json
{
"_version":2,
"data":[{
"name":"webservers"
}]
}
output
json
{
"_version":2,
"data":[{
"name":"webservers"
}]
}

List a specific backend Jump to heading

To get information about a specific backend, add its name to the end of the URL path. Below, we get information about the backend named webservers:

bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/webservers"
bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/webservers"
output
json
{
"_version":3,
"data":{
"balance":{
"algorithm":"roundrobin"
},
"default_server":{
"alpn":"h2",
"check":"enabled",
"check_alpn":"h2",
"maxconn":30,
"proxy-v2-options":null,
"weight":100},
"mode":"http",
"name":"webservers"
}
}
}
output
json
{
"_version":3,
"data":{
"balance":{
"algorithm":"roundrobin"
},
"default_server":{
"alpn":"h2",
"check":"enabled",
"check_alpn":"h2",
"maxconn":30,
"proxy-v2-options":null,
"weight":100},
"mode":"http",
"name":"webservers"
}
}
}

Add a backend Jump to heading

To add a backend, make a POST request to the backends endpoint. Send the fields to set in the body of the request. Below, we create a new backend named myservers:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X POST \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myservers",
"mode":"http",
"balance": {
"algorithm":"roundrobin"
},
"default_server": {
"alpn": "h2",
"check": "enabled",
"check_alpn": "h2",
"maxconn": 30,
"weight": 100
}
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends?version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X POST \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myservers",
"mode":"http",
"balance": {
"algorithm":"roundrobin"
},
"default_server": {
"alpn": "h2",
"check": "enabled",
"check_alpn": "h2",
"maxconn": 30,
"weight": 100
}
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends?version=$CFGVER"

Replace a backend Jump to heading

To make changes to a backend, you must replace it entirely. To replace an existing backend, make a PUT request to the backends endpoint, passing the name of the backend at the end of the URL path:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X PUT \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myservers",
"mode":"http",
"balance": {
"algorithm":"roundrobin"
},
"default_server": {
"alpn": "h2",
"check": "enabled",
"check_alpn": "h2",
"maxconn": 30,
"weight": 50
}
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/myservers?version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X PUT \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myservers",
"mode":"http",
"balance": {
"algorithm":"roundrobin"
},
"default_server": {
"alpn": "h2",
"check": "enabled",
"check_alpn": "h2",
"maxconn": 30,
"weight": 50
}
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/myservers?version=$CFGVER"

Delete a backend Jump to heading

To delete a backend, use the DELETE method:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X DELETE \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/myservers?version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X DELETE \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/myservers?version=$CFGVER"

If this page was useful, please, Leave the feedback.