Skip to content

Load balancing

To have an application accessible from the internet you need a load balancer that can route traffic to the application.

The load balancer set up for your environment is {Environment}-public.

Step 1: Add and configure the load-balancing package

repo-iac/environments/dev/
ok pkg add load-balancing-alb load-balancing-alb-main
cd load-balancing-alb-main

We chose main here because we have just one load balancer. If you have multiple load balancers, you can replace main with something more descriptive (for instance "payments", "catalog", "orders").

Update package-config.yml with your preferences. The Name field should be main (or whatever you chose above) to avoid confusion:

repo-iac/environments/dev/load-balancing-alb-main/package-config.yml
# ...
Name: "main"
# ...

Step 2: Install the package

repo-iac/environments/dev/load-balancing-alb-main/
ok pkg install

Step 3: Initialize and apply the load-balancing stacks

ALB are separated into two stacks when creating them.

The first stack is the data stack, which contains data-related resources, this must be applied first.

The second stack is the alb stack, which contains the load balancing set up, route53, etc.

repo-iac/environments/dev/load-balancing-alb-main-data/
terraform init
terraform apply
repo-iac/environments/dev/load-balancing-alb-main/
terraform init
terraform apply

Step 4: Verify

Run the following command:

aws elbv2 describe-load-balancers | jq '.LoadBalancers[].LoadBalancerName'

The output list should contain the name of the load balancer you just created.

Login to the AWS console and navigate to EC2. Select Load Balancers in the left-hand menu.

The list should contain the name of the load balancer you just created.


Next step

Set up IAM.