copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2020-06-29 |
load balancer, public, listener, back-end, front-end, pool, round-robin, weighted, connections, methods, policies, APIs, access, ports, vpc, vpc network |
vpc |
{:shortdesc: .shortdesc} {:new_window: target="_blank"} {:codeblock: .codeblock} {:pre: .pre} {:screen: .screen} {:term: .term} {:tip: .tip} {:note: .note} {:important: .important} {:deprecated: .deprecated} {:external: target="_blank" .external} {:generic: data-hd-programlang="generic"} {:download: .download} {:DomainName: data-hd-keyref="DomainName"}
{: #nlbaas-apis}
For detailed information on APIs available for network load balancers in your VPC environment, see the load balancers section in the VPC API reference. {: shortdesc}
The following example illustrates using the API to create a small network load balancer in front of two VPC virtual server instances (192.168.100.5
and 192.168.100.6
) running a web application that listens on port 80. The load balancer has a front-end listener, which allows secure access to the web application by using HTTPS. You can use the API to get details of the load balancer after it is created, and to delete the load balancer.
The example steps that follow skip the prerequisite steps of using the IBM Cloud UI, CLI, or API to provision a VPC, subnets, and instances.
You can also create a load balancer using the UI or CLI. For instructions, see Creating a load balancer using the IBM Cloud console or the CLI reference. {: tip}
{: #step-1-create-a-load-balancer-nlb}
bash
curl -H "Authorization: $iam_token" -X POST
"$api_endpoint/v1/load_balancers?version=$api_version&generation=2" \
-d '{
"name": "example-balancer",
"is_public": true,
"profile": {
"name": "network-small"
},
"listeners": [
{
"certificate_instance": {
"crn": "crn:v1:staging:public:cloudcerts:us-south:a/123456:b8877ea4-b8eg-467e-912a-da1eb7f031cg:certificate:43219c4c97d013fb2a95b21dddde1234"
},
"port": 443,
"protocol": "tcp",
"default_pool": {
"name": "example-pool"
}
}
],
"pools": [
{
"algorithm": "round_robin",
"health_monitor": {
"delay": 5,
"max_retries": 2,
"timeout": 2,
"type": "tcp",
"url_path": "/"
},
"name": "example-pool",
"protocol": "tcp",
"session_persistence": {
"cookie_name": "string",
"type": "source_ip"
},
"members": [
{
"port": 80,
"target": {
"address": "192.168.100.5"
},
"weight": 50
},
{
"port": 80,
"target": {
"address": "192.168.100.6"
},
"weight": 50
}
]
}
],
"subnets": [
{
"id": "7ec87131-1c7e-4990-b4f0-a26f2e61f98e"
}
]
}'
{: codeblock}
Sample output:
{
"created_at": "2018-07-12T23:17:07.5985381Z",
"crn": "crn:v1:staging:public:is:us-south:a/123456::load-balancer:dd754295-e9e0-4c9d-bf6c-58fbc59e5727",
"hostname": "ac34687d.lb.appdomain.cloud",
"href": "https://us-south.iaas.cloud.ibm.com/v1/load_balancers/dd754295-e9e0-4c9d-bf6c-58fbc59e5727",
"id": "0738-dd754295-e9e0-4c9d-bf6c-58fbc59e5727",
"is_public": true,
"profile": {
"name": "network-small",
"family": "network"
},
"listeners": [
{
"id": "0738-70294e14-4e61-11e8-bcf4-0242ac110004",
"href": "https://us-south.iaas.cloud.ibm.com/v1/load_balancers/dd754295-e9e0-4c9d-bf6c-58fbc59e5727/listeners/70294e14-4e61-11e8-bcf4-0242ac110004"
}
],
"name": "example-balancer",
"operating_status": "offline",
"pools": [
{
"id": "0738-70294e14-4e61-11e8-bcf4-0242ac110004",
"href": "https://us-south.iaas.cloud.ibm.com/v1/load_balancers/dd754295-e9e0-4c9d-bf6c-58fbc59e5727/pools/70294e14-4e61-11e8-bcf4-0242ac110004",
"name": "example-pool"
}
],
"provisioning_status": "create_pending",
"resource_group": {
"id": "56969d60-43e9-465c-883c-b9f7363e78e8"
},
"subnets": [
{
"id": "0738-7ec86020-1c6e-4889-b3f0-a15f2e50f87e",
"href": "https://us-south.iaas.cloud.ibm.com/v1/subnets/7ec86020-1c6e-4889-b3f0-a15f2e50f87e",
"name": "example-subnet"
}
]
}
{: screen}
Save the ID of the load balancer to use in the next steps. For example, save it in the variable lbid
.
lbid=0738-dd754295-e9e0-4c9d-bf6c-58fbc59e5727
{: tip}
curl -H "Authorization: $iam_token" -X GET "$api_endpoint/v1/load_balancers/$lbid?version=$api_version&generation=2"
{: pre}
Allow some time for provisioning. When the load balancer is ready, it is set to online
and active
status, as shown in the following sample output:
{
"id": "0738-dd754295-e9e0-4c9d-bf6c-58fbc59e5727",
"crn": "crn:v1:staging:public:is:us-south:a/123456::load-balancer:dd754295-e9e0-4c9d-bf6c-58fbc59e5727",
"href": "https://us-south.iaas.cloud.ibm.com/v1/load_balancers/dd754295-e9e0-4c9d-bf6c-58fbc59e5727",
"name": "example-balancer",
"created_at": "2018-07-13T22:22:24.489Z",
"hostname": "dd754295-e9e0-4c9d-bf6c-58fbc59e5727.lb.appdomain.cloud",
"is_public": true,
"profile": {
"name": "network-small",
"family": "network"
},
"listeners": [
{
"id": "0738-70294e14-4e61-11e8-bcf4-0242ac110004",
"href": "https://us-south.iaas.cloud.ibm.com/v1/load_balancers/dd754295-e9e0-4c9d-bf6c-58fbc59e5727/listeners/70294e14-4e61-11e8-bcf4-0242ac110004"
}
],
"operating_status": "online",
"pools": [
{
"id": "0738-70294e14-4e61-11e8-bcf4-0242ac110004",
"href": "https://us-south.iaas.cloud.ibm.com/v1/load_balancers/dd754295-e9e0-4c9d-bf6c-58fbc59e5727/pools/70294e14-4e61-11e8-bcf4-0242ac110004",
"name": "example-pool"
}
],
"private_ips": [
{
"address": "192.168.10.5"
},
{
"address": "192.168.10.6"
}
],
"provisioning_status": "active",
"public_ips": [
{
"address": "169.11.111.115"
},
{
"address": "169.11.111.116"
}
],
"resource_group": {
"id": "0738-56969d60-43e9-465c-883c-b9f7363e78e8"
},
"subnets": [
{
"id": "0738-7ec86020-1c6e-4889-b3f0-a15f2e50f87e",
"href": "https://us-south.iaas.cloud.ibm.com/v1/subnets/7ec86020-1c6e-4889-b3f0-a15f2e50f87e",
"name": "example-subnet"
}
]
}
{: screen}
Run the following command to delete the load balancer.
curl -H "Authorization: $iam_token" -X DELETE "$api_endpoint/v1/load_balancers/$lbid?version=$api_version&generation=2"
{: pre}