Skip to content

Commit bb856b6

Browse files
authored
add guide on using a self managed (or existing) load balancer (#2765)
* init draft * fixup and test * revise * revise
1 parent 3b25a4b commit bb856b6

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Externally Managed Load Balancers
3+
---
4+
5+
## Motivation
6+
7+
The load balancer controller (LBC) generally creates and destroys [AWS Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/index.html) in response to Kubernetes resources.
8+
9+
However, some cluster operators may prefer to manually manage AWS Load Balancers. This supports use cases like:
10+
- Preventing acciential release of key IP addresses.
11+
- Supporting load balancers where the Kubernetes cluster is one of multiple targets.
12+
- Complying with organizational requirements on provisioning load balancers, for security or cost reasons.
13+
14+
## Solution Overview
15+
16+
Use the TargetGroupBinding CRD to sync a Kubernetes service with the targets of a load balancer.
17+
18+
First, a load balancer is manually created directly with AWS. This guide uses a network load balancer, but an application load balancer may be similarly configured.
19+
20+
Second, A [listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html) and a [target group](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html) are then added to the load balancer.
21+
22+
Third, a TargetGroupBinding CRD is created in a cluster. The CRD includes references to a Kubernetes service and the [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of the Load Balancer Target Group. The CRD configures the LBC to watch the service and automatically update the target group with the appropriate pod VPC IP addresses.
23+
24+
## Prerequisites
25+
26+
Install:
27+
- [Load Balancer Controller Installed](../../../deploy/installation.md) on Cluster
28+
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
29+
- [Kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)
30+
31+
Have this information available:
32+
- Cluster [VPC](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) Information
33+
- ID of EKS Cluster
34+
- Subnet IDs
35+
- This information is avilable in the "Networking" section of the EKS Cluster Console.
36+
- Port and Protocol of Target [Kubernetes Service](https://kubernetes.io/docs/concepts/services-networking/service/)
37+
38+
## Configure Load Balancer
39+
40+
**Create Load Balancer: (optional)**
41+
42+
1. Use the [create\-load\-balancer](https://docs.aws.amazon.com/cli/latest/reference/elbv2/create-load-balancer.html) command to create an IPv4 load balancer, specifying a public subnet for each Availability Zone in which you have instances.
43+
44+
You can specify only one subnet per Availability Zone.
45+
46+
```
47+
aws elbv2 create-load-balancer --name my-load-balancer --type network --subnets subnet-0e3f5cac72EXAMPLE
48+
```
49+
50+
**Important:** The output includes the ARN of the load balancer. This value is needed to configure the LBC.
51+
52+
Example:
53+
54+
```
55+
arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/net/my-load-balancer/1234567890123456
56+
```
57+
58+
59+
1. Use the [create\-target\-group](https://docs.aws.amazon.com/cli/latest/reference/elbv2/create-target-group.html) command to create an IPv4 target group, specifying the same VPC of your EKS cluster.
60+
61+
```
62+
aws elbv2 create-target-group --name my-targets --protocol TCP --port 80 --vpc-id vpc-0598c7d356EXAMPLE
63+
```
64+
65+
The output includes the ARN of the target group, with this format:
66+
67+
```
68+
arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/1234567890123456
69+
```
70+
71+
1. Use the [create\-listener](https://docs.aws.amazon.com/cli/latest/reference/elbv2/create-listener.html) command to create a listener for your load balancer with a default rule that forwards requests to your target group. The listener port and protocol must match the Kubernetes service. However, TLS termination is permitted. [[double check it works in this configuration?]]
72+
73+
```
74+
aws elbv2 create-listener --load-balancer-arn loadbalancer-arn --protocol TCP --port 80 \
75+
--default-actions Type=forward,TargetGroupArn=targetgroup-arn
76+
```
77+
78+
## Create TargetGroupBinding CRD
79+
80+
1. Create the [TargetGroupBinding CRD](/guide/targetgroupbinding/targetgroupbinding.md)
81+
82+
Insert the ARN of the Target Group, as created above.
83+
84+
Insert the name and port of the target Kubernetes service.
85+
86+
```yaml
87+
apiVersion: elbv2.k8s.aws/v1beta1
88+
kind: TargetGroupBinding
89+
metadata:
90+
name: my-tgb
91+
spec:
92+
serviceRef:
93+
name: awesome-service # route traffic to the awesome-service
94+
port: 80
95+
targetGroupARN: arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/1234567890123456
96+
```
97+
2. Apply the CRD
98+
99+
Apply the TargetGroupBinding CRD CRD file to your Cluster.
100+
101+
`kubectl apply -f my-tgb.yaml`
102+
103+
## Verify
104+
105+
Wait approximately 30 seconds for the LBC to update the load balancer.
106+
107+
[View all target groups](https://console.aws.amazon.com/ec2/v2/home#TargetGroups:) in the AWS console.
108+
109+
Find the target group by the ARN noted above, and verify the appropriate instances from the cluster have been added.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ nav:
3232
- SSL Redirect: guide/tasks/ssl_redirect.md
3333
- Use Cases:
3434
- NLB TLS Termiation: guide/use_cases/nlb_tls_termination/index.md
35+
- Externally Managed Load Balancer: guide/use_cases/self_managed_lb/index.md
3536
- Examples:
3637
- EchoServer: examples/echo_server.md
3738
- gRPCServer: examples/grpc_server.md

0 commit comments

Comments
 (0)