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:
LoadBalancerL4RouteBackendServiceBackendPool
Create a backend pool
Section titled “Create a backend pool”Create a backend pool by referencing the existing virtual machines you wish to place in the pool:
evroc loadbalancer backendpool create mybackendpool \ --backend-ref=myvmWhere 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
Section titled “Create a backend service”Create a backend service referencing the backend pool, and specifying which port the virtual machines in the backend pool should listen on:
evroc loadbalancer backendservice create mybackendservice \ --backend-pool-ref=mybackendpool \ --port=80Additional CLI parameters
Section titled “Additional CLI parameters”--proxy-protocol- Whether to enable proxy protocol for connections--ip-protocol-selection- Which backend IP address type to use. Valid values areIPv4andIPv6. Defaults toIPv4.
Create an L4 route
Section titled “Create an L4 route”Create an L4 route referencing the backend service:
evroc loadbalancer l4route create myl4route \ --backend-service-ref=mybackendserviceCreate the load balancer
Section titled “Create the load balancer”Create a load balancer:
evroc loadbalancer loadbalancer create myloadbalancer \ --public-ip-ref=mypubipWhere 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:
evroc loadbalancer loadbalancer create myloadbalancer \ --public-ip-ref=mypubip \ --vpc=myvpc \ --subnet=a:mysubnet-a \ --subnet=b:mysubnet-bWhere we have:
--vpc- The VPC the load balancer attaches to--subnet- A subnet to attach to in the formzone:subnet, wherezoneis one ofa,b, orc, 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
Section titled “Add a listener to the load balancer”Add a listener to the load balancer referencing the L4 route:
evroc loadbalancer loadbalancer addlistener myloadbalancer \ --listener-name=mylistener \ --listener-port=80 \ --listener-route-ref=myl4routeTCP 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.
Verify the load balancer
Section titled “Verify the load balancer”Check that the load balancer was created successfully:
evroc loadbalancer loadbalancer listOr:
evroc loadbalancer loadbalancer get myloadbalancer -o yamlThe load balancer is ready when the Ready status is True.