Skip to content

Create a load balancer

This guide shows you how to create a TCP load balancer using the evroc CLI. For TLS termination and HTTP routing, see Create an HTTPS load balancer.

Creating a load balancer requires creating four types:

  • LoadBalancer
  • L4Route
  • BackendService
  • BackendPool

Create a backend pool by referencing the existing virtual machines you wish to place in the pool:

Terminal window
evroc loadbalancer backendpool create mybackendpool \
--backend-ref=myvm

Where the virtual machines are created by following the steps in Create a virtual machine.

--backend-ref can be specified multiple times to add multiple virtual machine to the backend pool.

Create a backend service referencing the backend pool, and specifying which port the virtual machines in the backend pool should listen on:

Terminal window
evroc loadbalancer backendservice create mybackendservice \
--backend-pool-ref=mybackendpool \
--port=80
  • --proxy-protocol - Whether to enable proxy protocol for connections
  • --ip-protocol-selection - Which backend IP address type to use. Valid values are IPv4 and IPv6. Defaults to IPv4.

Create an L4 route referencing the backend service:

Terminal window
evroc loadbalancer l4route create myl4route \
--backend-service-ref=mybackendservice

Create a load balancer:

Terminal window
evroc loadbalancer loadbalancer create myloadbalancer \
--public-ip-ref=mypubip

Where the public IP is created by following the steps in Manage public IPs.

Attaching the load balancer to a specific VPC

Section titled “Attaching the load balancer to a specific VPC”

By default, the load balancer is part of the default VPC and is deployed to every zone, attaching to the default subnet in each zone.

When creating a load balancer, you can specify which VPC and subnets it should be deployed to instead, using the --vpc and --subnet parameters:

Terminal window
evroc loadbalancer loadbalancer create myloadbalancer \
--public-ip-ref=mypubip \
--vpc=myvpc \
--subnet=a:mysubnet-a \
--subnet=b:mysubnet-b

Where we have:

  • --vpc - The VPC the load balancer attaches to
  • --subnet - A subnet to attach to in the form zone:subnet, where zone is one of a, b, or c, and subnet is the subnet to attach to in that zone

--vpc and --subnet must be provided together. The load balancer will only deploy to zones for which a subnet has been specified.

This configuration is immutable and cannot be modified once the load balancer has been created.

Add a listener to the load balancer referencing the L4 route:

Terminal window
evroc loadbalancer loadbalancer addlistener myloadbalancer \
--listener-name=mylistener \
--listener-port=80 \
--listener-route-ref=myl4route

TCP is the default listener protocol and accepts at most one --listener-route-ref. HTTP and HTTPS listeners accept up to 32 HTTP route references; repeat the flag or provide comma-separated references. For an example with a separate route per hostname, see Create an HTTPS load balancer.

Check that the load balancer was created successfully:

Terminal window
evroc loadbalancer loadbalancer list

Or:

Terminal window
evroc loadbalancer loadbalancer get myloadbalancer -o yaml

The load balancer is ready when the Ready status is True.