|
| 1 | +# Network Load Balancer |
| 2 | +AWS Load Balancer Controller supports Network Load Balancer (NLB) with instance or IP targets through Kubernetes service of type `LoadBalancer` with proper annotations. |
| 3 | + |
| 4 | +### Instance mode |
| 5 | +Instance target mode supports pods running on AWS EC2 instances. In this mode, AWS NLB sends traffic to the instances and the `kube-proxy` on the individual worker nodes forward it to the pods through one or more worker nodes in the Kubernetes cluster. |
| 6 | +### IP mode |
| 7 | +IP target mode supports pods running on AWS EC2 instances and AWS Fargate. In this mode, the AWS NLB targets traffic directly to the Kubernetes pods behind the service, eliminating the need for an extra network hop through the worker nodes in the Kubernetes cluster. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | +* AWS LoadBalancer Controller >= v2.2.0 |
| 11 | +* Kubernetes >= v1.16 for Service type `NodePort` |
| 12 | +* Kubernetes >= v1.20 or EKS >= 1.16 or the following patch releases for Service type `LoadBalancer` |
| 13 | + - 1.18.18+ for 1.18 |
| 14 | + - 1.19.10+ for 1.19 |
| 15 | +* Pods have native AWS VPC networking configured, see [Amazon VPC CNI plugin](https://github.com/aws/amazon-vpc-cni-k8s) |
| 16 | + |
| 17 | +!!!note "secure by default" |
| 18 | + Starting v2.2.0 release, the AWS Load balancer controller provisions an internal NLB by default. To create an internet-facing load balancer, apply the following annotation to your service: |
| 19 | + |
| 20 | + ``` |
| 21 | + service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing |
| 22 | + ``` |
| 23 | + |
| 24 | + For backwards compatibility, if this annotation is not specified, existing NLB will continue to use the scheme configured on the AWS resource. |
| 25 | + |
| 26 | +## Configuration |
| 27 | +The service resources of type `LoadBalancer` also get reconciled by the kubernetes controller built into the cloudprovider component of the `kube-controller-manager` or the `cloud-controller-manager` aka the `in-tree` controller. The AWS in-tree controller |
| 28 | +ignores those services resources that have the `service.beta.kubernetes.io/aws-load-balancer-type` annotation as `external`. The AWS Load balancer controller support for NLB is based on the in-tree cloud controller ignoring the service resources, so it is very important |
| 29 | +to apply the following annotation on the service resource during creation: |
| 30 | + |
| 31 | +```yaml |
| 32 | +service.beta.kubernetes.io/aws-load-balancer-type: "external" |
| 33 | +``` |
| 34 | +This `external` value to the above annotation causes the in-tree controller to not process the service resource and thus pass it on to the external controller. |
| 35 | + |
| 36 | +!!!warning "annotation modification" |
| 37 | + Do not modify or add the `service.beta.kubernetes.io/aws-load-balancer-type` annotation on an existing service object. If you need to make changes, for example from classic to NLB or NLB managed |
| 38 | + by the in-tree controller to the one managed by the AWS Load balancer controller, delete the kubernetes service first and then create again with the correct annotation. If you modify the annotation after service creation |
| 39 | + you will end up with leaked AWS load balancer resources. |
| 40 | + |
| 41 | +### IP mode |
| 42 | +NLB IP mode is determined based on the `service.beta.kubernetes.io/aws-load-balancer-nlb-target-type` annotation. If the annotation value is `ip`, then NLB will be provisioned in IP mode. Here is the manifest snippet: |
| 43 | +```yaml |
| 44 | + metadata: |
| 45 | + name: my-service |
| 46 | + annotations: |
| 47 | + service.beta.kubernetes.io/aws-load-balancer-type: "external" |
| 48 | + service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip" |
| 49 | +``` |
| 50 | + |
| 51 | +!!!note "backwards compatibility" |
| 52 | + For backwards compatibility, controller still supports the `nlb-ip` as the type annotation. For example, if you specify |
| 53 | + |
| 54 | + ``` |
| 55 | + service.beta.kubernetes.io/aws-load-balancer-type: nlb-ip |
| 56 | + ``` |
| 57 | +
|
| 58 | + the controller will provision NLB in IP mode. With this, the `service.beta.kubernetes.io/aws-load-balancer-nlb-target-type` annotation gets ignored. |
| 59 | + |
| 60 | +### Instance mode |
| 61 | +Similar to the IP mode, the instance mode is based on the annotation `service.beta.kubernetes.io/aws-load-balancer-type` value `instance`. Here is a sample manifest snippet: |
| 62 | + |
| 63 | +```yaml |
| 64 | + metadata: |
| 65 | + name: my-service |
| 66 | + annotations: |
| 67 | + service.beta.kubernetes.io/aws-load-balancer-type: "external" |
| 68 | + service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "instance" |
| 69 | +``` |
| 70 | + |
| 71 | +## Protocols |
| 72 | +Support is available for both TCP and UDP protocols. In case of TCP, NLB in IP mode does not pass the client source IP address to the pods. You can configure [NLB proxy protocol v2](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html#proxy-protocol) via [annotation](https://kubernetes.io/docs/concepts/services-networking/service/#proxy-protocol-support-on-aws) if you need the client source IP address. |
| 73 | + |
| 74 | +to enable proxy protocol v2, apply the following annotation to your service: |
| 75 | +```yaml |
| 76 | +service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*" |
| 77 | +``` |
| 78 | + |
| 79 | +## Subnet tagging requirements |
| 80 | +See [Subnet Discovery](https://kubernetes-sigs.github.io/aws-load-balancer-controller/guide/controller/subnet_discovery/) for details on configuring ELB for public or private placement. |
| 81 | + |
| 82 | + |
| 83 | +## Security group |
| 84 | +NLB does not currently support a managed security group. For ingress access, the controller will resolve the security group for the ENI corresponding to the endpoint pod for IP mode, and the security group of the worker nodes for instance mode. If there is a single security group attached to the the ENI or the instance, it gets used. In case of multiple security groups, the controller expects to find only one security group tagged with the Kubernetes cluster id. Controller will update the ingress rules on the security groups as per the service spec. |
0 commit comments