Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shared LoadBalancerIP for multiple Services #6480

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions docs/service-loadbalancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,69 @@ spec:
type: LoadBalancer
```

By default, Antrea doesn't allocate a single IP to multiple Services. Before
Antrea v2.1, if multiple Services requested the same IP, only one of them would
get the IP assigned. Starting with Antrea v2.1, to share an IP between multiple
Services, you can annotate the Services with
`service.antrea.io/allow-shared-load-balancer-ip: true` when requesting a
particular IP. Note that the IP will only be shared between Services having the
annotation. If not all Services are annotated, the IP may either be allocated
to one of the unannotated Services or shared between the annotated Services,
depending on the order in which they are processed. The annotation only takes
effect during the IP allocation phase. Once the IP has been allocated, removing
this annotation from a Service will not result in the IP being reclaimed from
it or other Services.

For example, the following two Services will share an IP:

```yaml
apiVersion: v1
kind: Service
metadata:
name: my-service-1
annotations:
service.antrea.io/external-ip-pool: "service-external-ip-pool"
antoninbas marked this conversation as resolved.
Show resolved Hide resolved
service.antrea.io/allow-shared-load-balancer-ip: "true"
spec:
selector:
app: MyApp1
loadBalancerIP: "10.10.0.2"
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
---
apiVersion: v1
kind: Service
metadata:
name: my-service-2
annotations:
service.antrea.io/external-ip-pool: "service-external-ip-pool"
service.antrea.io/allow-shared-load-balancer-ip: "true"
spec:
selector:
app: MyApp2
loadBalancerIP: "10.10.0.2"
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer
```

Note that sharing a LoadBalancer IP between multiple Services only works under
the following conditions:

* The Services use different ports.
* The Services use the `Cluster` external traffic policy. Sharing a
LoadBalancer IP between Services using the `Local` external traffic policy
can also work if they have identical Endpoints. However, in such cases, it
may be preferable to consolidate the Services into a single Service.

Otherwise, the datapath may not work even though the IP is allocated to the
Services successfully.

#### Validate Service external IP

Once Antrea allocates an external IP for a Service of type LoadBalancer, it
Expand Down
3 changes: 3 additions & 0 deletions pkg/agent/types/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (
// ServiceExternalIPPoolAnnotationKey is the key of the Service annotation that specifies the Service's desired external IP pool.
ServiceExternalIPPoolAnnotationKey string = "service.antrea.io/external-ip-pool"

// ServiceAllowSharedIPAnnotationKey is the key of the Service annotation that specifies whether the Service is allowed to use a shared LoadBalancer IP.
ServiceAllowSharedIPAnnotationKey string = "service.antrea.io/allow-shared-load-balancer-ip"

// ServiceLoadBalancerModeAnnotationKey is the key of the Service annotation that specifies the Service's load balancer mode.
ServiceLoadBalancerModeAnnotationKey string = "service.antrea.io/load-balancer-mode"

Expand Down
Loading
Loading