Sub topic 19
Gateway Load Balancer for network appliances
This chapter assumes you know EC2 instances, security groups, VPC subnets, route tables and Availability Zones. It also assumes you have read the earlier chapters on target groups, health checks and cross-zone load balancing. A Gateway Load Balancer (GWLB) is the third Elastic Load Balancing type. It differs from the Application and Network Load Balancers because it does not serve your application. It sends traffic through a fleet of network appliances, such as firewalls, intrusion detection systems and deep packet inspection tools.
The problem it solves
Suppose you must inspect all traffic entering and leaving a VPC with a third-party firewall. You could run one firewall instance and route everything through it. That instance becomes a single point of failure and a throughput limit. You could run several, but then you must split traffic between them without breaking connections, because a firewall needs to see both directions of a flow.
A GWLB handles this. It acts as a transparent bump in the wire. It distributes flows across healthy appliances, keeps both directions of a flow on the same appliance, and lets you scale the fleet with an Auto Scaling group.
How it works internally
A GWLB operates at layer 3 (the network layer) and forwards IP packets. It does not terminate connections or read HTTP. Three pieces make it work.
- GENEVE encapsulation. The GWLB wraps each original packet in a GENEVE header and sends it to an appliance on UDP port 6081. The appliance inspects the packet, then sends it back to the GWLB, which unwraps it and forwards it to its destination. The original source and destination addresses are preserved inside the tunnel.
- Flow stickiness. The GWLB hashes the 5-tuple (source IP, destination IP, protocol, source port, destination port) and sends every packet of a flow to the same appliance. Reverse-direction packets go to the same appliance too, so stateful inspection works.
- Gateway Load Balancer endpoints. A GWLB endpoint is a VPC endpoint of type GatewayLoadBalancer. It lets other VPCs, or other subnets in the same VPC, reach the GWLB through AWS PrivateLink. Route tables send traffic to the endpoint, and the endpoint hands it to the GWLB.
The target group for a GWLB uses protocol GENEVE and port 6081. Appliances must therefore understand GENEVE. Most commercial firewall vendors ship AMIs that do, and you can find them in AWS Marketplace.
Comparing the three load balancer types
| Feature | Application | Network | Gateway |
|---|---|---|---|
| Layer | 7 | 4 | 3 |
| Typical use | HTTP and HTTPS apps | TCP, UDP, TLS, very high throughput | Inline network appliances |
| Terminates connections | Yes | Yes (TCP, TLS) | No |
| Target protocol | HTTP, HTTPS | TCP, UDP, TLS | GENEVE |
| Path or host routing | Yes | No | No |
| Listener | Port and protocol | Port and protocol | None to configure; it accepts all IP traffic |
A GWLB has no ports or rules to configure. Its listener forwards all IP packets to one target group.
Creating a GWLB
The commands below create a GWLB, a GENEVE target group with a health check, and a listener. They also expose the load balancer as an endpoint service. Replace the IDs with your own.
GWLB_ARN=$(aws elbv2 create-load-balancer \
--name inspection-gwlb \
--type gateway \
--subnets subnet-aaaa1111 subnet-bbbb2222 \
--query 'LoadBalancers[0].LoadBalancerArn' --output text)
TG_ARN=$(aws elbv2 create-target-group \
--name inspection-tg \
--protocol GENEVE \
--port 6081 \
--vpc-id vpc-0123456789abcdef0 \
--target-type instance \
--health-check-protocol HTTP \
--health-check-port 80 \
--health-check-path /health \
--query 'TargetGroups[0].TargetGroupArn' --output text)
aws elbv2 create-listener \
--load-balancer-arn "$GWLB_ARN" \
--default-actions Type=forward,TargetGroupArn="$TG_ARN"
aws ec2 create-vpc-endpoint-service-configuration \
--gateway-load-balancer-arns "$GWLB_ARN" \
--no-acceptance-requiredNote the differences from the ALB commands earlier in this tutorial. There are no security groups on the load balancer, no protocol or port on the listener, and the health check does not have to use the GENEVE port. Many appliances expose a separate HTTP or TCP port for health checks.
In the consumer VPC you then create a GWLB endpoint in a dedicated subnet and update route tables to send traffic to it.
aws ec2 create-vpc-endpoint \
--vpc-endpoint-type GatewayLoadBalancer \
--vpc-id vpc-0fedcba9876543210 \
--service-name com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0 \
--subnet-ids subnet-cccc3333Routing and the common layout
Routing is where most GWLB deployments go wrong, so plan it carefully. A common pattern for inbound traffic uses an ingress route table on the internet gateway.
- Associate a route table with the internet gateway. It routes the application subnet's CIDR to the GWLB endpoint.
- The application subnet's route table sends
0.0.0.0/0to the GWLB endpoint, so return traffic is inspected too. - The endpoint subnet's route table sends
0.0.0.0/0to the internet gateway.
The endpoint subnet should contain only endpoints. Putting application instances in it can create routing loops.
Scaling the appliance fleet
Appliances are ordinary EC2 instances, so you can place them in an Auto Scaling group and attach the GENEVE target group, exactly as in the earlier chapter. Use --health-check-type ELB so the group replaces appliances that fail the GWLB health check.
Two settings deserve attention:
- Cross-zone load balancing is off by default for a GWLB. With it off, an endpoint in one AZ sends traffic only to appliances in that AZ. This keeps traffic local and avoids cross-AZ data charges, but you need appliances in every AZ where you have an endpoint.
- Target failover. The GWLB can rebalance existing flows when a target becomes unhealthy or is deregistered. You can choose
rebalanceorno_rebalancefor each of these cases in the target group attributes. Stateful appliances often drop rebalanced flows, because the new appliance has no state for them, so test this behavior with your vendor's software.
For scaling metrics, request count is not meaningful here. Use CPU utilization, or network throughput metrics such as NetworkIn and NetworkOut, whichever your appliance saturates first.
Common errors
- Targets unhealthy. Check that the appliance security group allows UDP 6081 from the GWLB subnets and allows the health check port.
- Traffic is black-holed. A route table points to an endpoint that is not available, or the appliance does not return packets to the GWLB.
- Large packets fail. GENEVE adds overhead, and the supported MTU is 8500 bytes. If appliances or paths use smaller MTUs, fragmentation or drops can occur.
- Asymmetric routing. Inbound and return paths use different endpoints, so one appliance sees only half of a flow.
Exercise
A team runs a firewall fleet behind a GWLB in two AZs with cross-zone load balancing off. One AZ has endpoints and appliances. The other AZ has an endpoint but no appliances. What happens to traffic through the second endpoint, and what are two ways to fix it?
Show answer
Traffic through the second endpoint has no healthy targets in its AZ, so it is dropped. Fix it by adding appliances in that AZ (for example, by adding its subnet to the Auto Scaling group), or by enabling cross-zone load balancing so the endpoint can use appliances in the other AZ, at the cost of cross-AZ data charges.
Exercise
Why does a GWLB target group use protocol GENEVE on port 6081 instead of HTTP on port 80?
Show answer
The GWLB forwards raw IP packets, not HTTP requests. It wraps each packet in a GENEVE tunnel header so the appliance receives the original packet unchanged, including its source and destination addresses. UDP port 6081 is the port GENEVE uses for this tunnel.