Skip to main content

Load Balancers

Before you start

Prepare your environment for this section:

~$prepare-environment exposing/load-balancer

This will make the following changes to your lab environment:

  • Creates an IAM role required by the AWS Load Balancer Controller

You can view the Terraform that applies these changes here.

Kubernetes uses services to expose pods outside of a cluster. One of the most popular ways to use services in AWS is with the LoadBalancer type. With a simple YAML file declaring your service name, port, and label selector, the cloud controller will provision a load balancer for you automatically.

apiVersion: v1
kind: Service
metadata:
name: search-svc # the name of our service
spec:
type: LoadBalancer
selector:
app: SearchApp # pods are deployed with the label app=SearchApp
ports:
- port: 80

This is great because of how simple it is to put a load balancer in front of your application. The service spec has been extended over the years with annotations and additional configuration. A second option is to use an ingress rule and an ingress controller to route external traffic into Kubernetes pods.

An internet-facing Network Load Balancer with a TCP listener on port 80, forwarding to a NodePort on each registered EC2 worker node, where kube-proxy relays the connection to a ui Pod

In this chapter we'll demonstrate how to expose an application running in the EKS cluster to the Internet using a layer 4 Network Load Balancer.