|
| 1 | +# MultiCluster Target Groups |
| 2 | + |
| 3 | +The LB controller assumes full control over configured Target Groups. This means when a Target Group is registered with the controller, it will deregister any targets that are not currently in the cluster. |
| 4 | +By enabling MultiCluster support, Target Groups can be associated to multiple Kubernetes clusters or support arbitrary targets from other sources. |
| 5 | + |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +MultiCluster mode is supported in a couple different ways. Be sure that every cluster that is associated with a Target Group has one of these methods |
| 10 | +enabled to ensure the Target Group is recognized as MultiCluster enabled! It is recommended to use fresh resources when using MutliCluster mode, there is short period of time |
| 11 | +when the feature needs to generate a snapshot of the cluster state in order to support the mode. This data is stored into a ConfigMap which resides in the same namespace |
| 12 | +as your load balancer resources. The ConfigMap stores the current snapshot of the managed targets, it can be found under `aws-lbc-targets-$TARGET_GROUP_BINDING_NAME` |
| 13 | + |
| 14 | + |
| 15 | +ALB, specify this annotation in the ingress or service: |
| 16 | + |
| 17 | +`alb.ingress.kubernetes.io/multi-cluster-target-group: "true"` |
| 18 | + |
| 19 | +NLB, specify this annotation in your service: |
| 20 | + |
| 21 | +`service.beta.kubernetes.io/aws-load-balancer-multi-cluster-target-group: "true"` |
| 22 | + |
| 23 | + |
| 24 | +For Out-of-Band TargetGroupBindings, specify this field in the spec: |
| 25 | + |
| 26 | +`multiClusterTargetGroup: true` |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +### Example |
| 31 | + |
| 32 | +We will be setting up an echoserver in two clusters in order to demonstrate MultiCluster mode. See the full echoserver example in the 'Examples' tab. |
| 33 | + |
| 34 | +The following ingress configures the Target Group Binding as MultiCluster. We will take the created Target Group and share it in a second cluster. |
| 35 | + |
| 36 | +``` |
| 37 | +apiVersion: networking.k8s.io/v1 |
| 38 | +kind: Ingress |
| 39 | +metadata: |
| 40 | + name: echoserver |
| 41 | + namespace: echoserver |
| 42 | + annotations: |
| 43 | + alb.ingress.kubernetes.io/multi-cluster-target-group: "true" |
| 44 | + alb.ingress.kubernetes.io/scheme: internet-facing |
| 45 | + alb.ingress.kubernetes.io/tags: Environment=dev,Team=test |
| 46 | +spec: |
| 47 | + ingressClassName: alb |
| 48 | + rules: |
| 49 | + - http: |
| 50 | + paths: |
| 51 | + - path: / |
| 52 | + pathType: Exact |
| 53 | + backend: |
| 54 | + service: |
| 55 | + name: echoserver |
| 56 | + port: |
| 57 | + number: 80 |
| 58 | +``` |
| 59 | + |
| 60 | +Verify that MultiCluster is enabled by verifying that the created Target Group Binding is marked as MultiCluster. |
| 61 | + |
| 62 | +``` |
| 63 | +kubectl -n echoserver get targetgroupbinding k8s-echoserv-echoserv-cc0122e143 -o yaml |
| 64 | +apiVersion: elbv2.k8s.aws/v1beta1 |
| 65 | +kind: TargetGroupBinding |
| 66 | +metadata: |
| 67 | + annotations: |
| 68 | + elbv2.k8s.aws/checkpoint: cKay81gadoTtBSg6uVVginqtmCVG-1ApTvYN4YLD37U/_4kBy3Yg64qrXzjvIb2LlC3O__ex1qjozynsqHXmPgo |
| 69 | + elbv2.k8s.aws/checkpoint-timestamp: "1729021572" |
| 70 | + creationTimestamp: "2024-10-15T19:46:06Z" |
| 71 | + finalizers: |
| 72 | + - elbv2.k8s.aws/resources |
| 73 | + generation: 1 |
| 74 | + labels: |
| 75 | + ingress.k8s.aws/stack-name: echoserver |
| 76 | + ingress.k8s.aws/stack-namespace: echoserver |
| 77 | + name: k8s-echoserv-echoserv-cc0122e143 |
| 78 | + namespace: echoserver |
| 79 | + resourceVersion: "79121011" |
| 80 | + uid: 9ceaa2ea-14bb-44a5-abb0-69c7d2aac52c |
| 81 | +spec: |
| 82 | + ipAddressType: ipv4 |
| 83 | + multiClusterTargetGroup: true <<< HERE |
| 84 | + networking: |
| 85 | + ingress: |
| 86 | + - from: |
| 87 | + - securityGroup: |
| 88 | + groupID: sg-06a2bd7d790ac1d2e |
| 89 | + ports: |
| 90 | + - port: 32197 |
| 91 | + protocol: TCP |
| 92 | + serviceRef: |
| 93 | + name: echoserver |
| 94 | + port: 80 |
| 95 | + targetGroupARN: arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-echoserv-cc0122e143/6816b87346280ee7 |
| 96 | + targetType: instance |
| 97 | + vpcID: vpc-0a7ef5bd8943067a8 |
| 98 | +``` |
| 99 | + |
| 100 | +In another cluster, you can now register that Target Group ARN in a Target Group Binding. |
| 101 | + |
| 102 | +``` |
| 103 | +apiVersion: elbv2.k8s.aws/v1beta1 |
| 104 | +kind: TargetGroupBinding |
| 105 | +metadata: |
| 106 | + name: MyTargetGroupBinding |
| 107 | + namespace: echoserver |
| 108 | +spec: |
| 109 | + serviceRef: |
| 110 | + name: echoserver |
| 111 | + port: 80 |
| 112 | + multiClusterTargetGroup: true |
| 113 | + targetType: instance |
| 114 | + ipAddressType: ipv4 |
| 115 | + networking: |
| 116 | + ingress: |
| 117 | + - from: |
| 118 | + - securityGroup: |
| 119 | + groupID: $SG_FROM_ABOVE |
| 120 | + ports: |
| 121 | + - port: 32197 |
| 122 | + protocol: TCP |
| 123 | + targetGroupARN: $TG_FROM_ABOVE |
| 124 | +``` |
| 125 | + |
| 126 | +The configured TargetGroup should have targets from both clusters available to service traffic. |
| 127 | + |
| 128 | + |
0 commit comments