|
1 | 1 | # LoadBalancer |
| 2 | + |
| 3 | +A `LoadBalancer` resource is an L3(IP-based) load balancer service implementation provided by Ironcore. It provides an externally accessible IP address that sends traffic to the correct port on your cluster nodes. Ironcore LoadBalancer allows targeting multiple `NetworkInterfaces` and distributes traffic between them. This LoadBalancer supports dual stack IP addresses (IPv4/IPv6). |
| 4 | + |
| 5 | +## Example Network Resource |
| 6 | +An example of how to define a `LoadBalancer` resource in `Ironcore` |
| 7 | +``` |
| 8 | +apiVersion: networking.ironcore.dev/v1alpha1 |
| 9 | +kind: LoadBalancer |
| 10 | +metadata: |
| 11 | + namespace: default |
| 12 | + name: loadbalancer-sample |
| 13 | +spec: |
| 14 | + type: Public |
| 15 | + ipFamilies: [IPv4] |
| 16 | + networkRef: |
| 17 | + name: network-sample |
| 18 | + networkInterfaceSelector: |
| 19 | + matchLabels: |
| 20 | + app: web |
| 21 | + ports: |
| 22 | + - port: 80 |
| 23 | +
|
| 24 | +``` |
| 25 | +(`Note`: Refer to <a href="https://github.com/ironcore-dev/ironcore/tree/main/config/samples/e2e/loadbalancer-public">E2E Examples</a> for more detailed examples.) |
| 26 | + |
| 27 | +# Key Fields: |
| 28 | +- `type`(`string`): The type of `LoadBalancer`. Currently two types of `Loadbalancer` are supported: |
| 29 | + - `Public`: LoadBalancer that allocates public IP and routes a stable public IP. |
| 30 | + - `Internal`: LoadBalancer that allocates and routes network-internal, stable IPs. |
| 31 | +- `ipFamilies`(`list`): ipFamilies are the IP families the LoadBalancer should have(Supported values are `IPv4` and `IPv6`). |
| 32 | +- `ips`(`list`): The ips are the list of IPs to use. This can only be used when the type is LoadBalancerTypeInternal. |
| 33 | +- `networkRef`(`string`): networkRef is the Network this LoadBalancer should belong to. |
| 34 | +- `networkInterfaceSelector`(`labelSelector`): networkInterfaceSelector defines the NetworkInterfaces for which this LoadBalancer should be applied |
| 35 | +- `ports`(`list`): ports are the list of LoadBalancer ports should allow |
| 36 | + - `protocol`(`string`): protocol is the protocol the load balancer should allow. Supported protocols are `UDP`, `TCP`, and `SCTP`, if not specified defaults to TCP. |
| 37 | + - `port`(`int`): port is the port to allow. |
| 38 | + - `endPort`(`int`): endPort marks the end of the port range to allow. If unspecified, only a single port `port` will be allowed. |
| 39 | + |
| 40 | +# Reconciliation Process: |
| 41 | + |
| 42 | +- **NetworkInterfaces selection**: LoadBalancerController continuously watches for `LoadBalancer` resources and reconciles. LoadBalancer resource dynamically selects multiple target `NetworkInterfaces` via a `networkInterfaceSelector` LabelSelector from the spec. Once the referenced Network is in `Available` state, the Loadbalancer destination IP list and referencing `NetworkInterface` is prepared by iterating over selected NetworkIntrefaces status information. |
| 43 | + |
| 44 | +- **Preparing Routing State Object**: Once the destination list is available `LoadBalancerRouting` resource is created. `LoadBalancerRouting` describes `NetworkInterfaces` load balanced traffic is routed to. This object describes the state of the LoadBalancer and results of the LoadBalancer definition specifically `networkInterfaceSelector` and `networkRef`. |
| 45 | +Later this information is used at the Ironcore API level to describe the explicit targets in a pool traffic is routed to. |
| 46 | + |
| 47 | +Sample `LoadBalancerRouting` object(`Note`: it is created by LoadBalancerController) |
| 48 | +``` |
| 49 | +apiVersion: networking.ironcore.dev/v1alpha1 |
| 50 | +kind: LoadBalancerRouting |
| 51 | +metadata: |
| 52 | + namespace: default |
| 53 | + name: loadbalancer-sample # Same name as the load balancer it originates from. |
| 54 | +# networkRef references the exact network object the routing belongs to. |
| 55 | +networkRef: |
| 56 | + name: network-sample |
| 57 | +# destinations list the target network interface instances (including UID) for load balancing. |
| 58 | +destinations: |
| 59 | + - name: my-machine-interface-1 |
| 60 | + uid: 2020dcf9-e030-427e-b0fc-4fec2016e73a |
| 61 | + - name: my-machine-interface-2 |
| 62 | + uid: 2020dcf9-e030-427e-b0fc-4fec2016e73d |
| 63 | +``` |
| 64 | +**LoadBalancer status update**: The `LoadBalancerController` in ironcore-net takes care of allocating IPs for defined `ipFamilies` in the spec and updates them in its `status.ips`. |
0 commit comments