|
| 1 | +## Gateway Chaining |
| 2 | + |
| 3 | +### Introduction |
| 4 | + |
| 5 | +Gateway chaining involves forwarding traffic from one gateway listener directly to another gateway listener. |
| 6 | +Specifically, the LBC allows you to configure an NLB gateway listener and point it to an ALB gateway listener. |
| 7 | +Under the hood, this is implemented by using [ALB target of NLB](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/application-load-balancer-target.html). |
| 8 | + |
| 9 | + |
| 10 | +Using a chaining setup provides multiple benefits: |
| 11 | + |
| 12 | +- You can use the HTTP request-based routing features of the Application Load Balancer in combination with features that the Network Load Balancer supports. |
| 13 | +- Use of endpoint services (AWS PrivateLink) |
| 14 | +- Static IP for Application Load Balancer. |
| 15 | +- Serve TCP and HTTP traffic from a single endpoint. |
| 16 | + |
| 17 | +### Set up |
| 18 | + |
| 19 | +This guide will walk you through setting up a chained Gateway. |
| 20 | + |
| 21 | + |
| 22 | +#### ALB Setup |
| 23 | + |
| 24 | +In the YAML below, we set up an ALB Gateway with an HTTP listener on port 80 and an HTTPS listener on port 443. These listeners forward traffic to |
| 25 | +an arbitrary backend service. It's important to note that the ALB Gateway is configured as an internal load balancer. Clients |
| 26 | +that wish to connect to the ALB Gateway must do so via the NLB Gateway we will set up next. While it's possible |
| 27 | +to use an internet-facing ALB Gateway where clients could communicate directly, in a chained |
| 28 | +setup the NLB Gateway always uses private IP addresses to communicate with the ALB Gateway. |
| 29 | + |
| 30 | +```yaml |
| 31 | +# alb-gatewayclass.yaml |
| 32 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 33 | +kind: GatewayClass |
| 34 | +metadata: |
| 35 | + name: aws-alb-gateway-class |
| 36 | +spec: |
| 37 | + controllerName: gateway.k8s.aws/alb |
| 38 | +--- |
| 39 | +# my-alb-gateway.yaml |
| 40 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 41 | +kind: Gateway |
| 42 | +metadata: |
| 43 | + name: my-alb-gateway |
| 44 | + namespace: example-ns |
| 45 | +spec: |
| 46 | + gatewayClassName: aws-alb-gateway-class |
| 47 | + infrastructure: |
| 48 | + parametersRef: |
| 49 | + kind: LoadBalancerConfiguration |
| 50 | + name: alb-lb-config |
| 51 | + group: gateway.k8s.aws |
| 52 | + listeners: |
| 53 | + - name: http |
| 54 | + protocol: HTTP |
| 55 | + port: 80 |
| 56 | + allowedRoutes: |
| 57 | + namespaces: |
| 58 | + from: Same |
| 59 | + - name: https |
| 60 | + protocol: HTTPS |
| 61 | + port: 443 |
| 62 | + allowedRoutes: |
| 63 | + namespaces: |
| 64 | + from: Same |
| 65 | +--- |
| 66 | +# lbconfig.yaml |
| 67 | +apiVersion: gateway.k8s.aws/v1beta1 |
| 68 | +kind: LoadBalancerConfiguration |
| 69 | +metadata: |
| 70 | + name: alb-lb-config |
| 71 | + namespace: example-ns |
| 72 | +spec: |
| 73 | + listenerConfigurations: |
| 74 | + - protocolPort: HTTPS:443 |
| 75 | + defaultCertificate: <my cert arn> |
| 76 | +--- |
| 77 | +# httproute.yaml |
| 78 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 79 | +kind: HTTPRoute |
| 80 | +metadata: |
| 81 | + name: my-http-app-route |
| 82 | + namespace: example-ns |
| 83 | +spec: |
| 84 | + parentRefs: |
| 85 | + - group: gateway.networking.k8s.io |
| 86 | + kind: Gateway |
| 87 | + name: my-alb-gateway |
| 88 | + sectionName: http |
| 89 | + - group: gateway.networking.k8s.io |
| 90 | + kind: Gateway |
| 91 | + name: my-alb-gateway |
| 92 | + sectionName: https |
| 93 | + rules: |
| 94 | + - backendRefs: |
| 95 | + - name: echoserver |
| 96 | + port: 80 |
| 97 | +``` |
| 98 | +
|
| 99 | +#### NLB Setup |
| 100 | +
|
| 101 | +In the YAML below, we set up an NLB Gateway with TCP listeners on ports 80 and 443. These listeners forward traffic to |
| 102 | +the ALB Gateway configured above. The NLB Gateway is configured as internet-facing to allow external clients |
| 103 | +to connect. The NLB will route traffic to the internal ALB using private IP addresses. |
| 104 | +
|
| 105 | +```yaml |
| 106 | +# nlb-gatewayclass.yaml |
| 107 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 108 | +kind: GatewayClass |
| 109 | +metadata: |
| 110 | + name: aws-nlb-gateway-class |
| 111 | +spec: |
| 112 | + controllerName: gateway.k8s.aws/nlb |
| 113 | +--- |
| 114 | +# my-nlb-gateway.yaml |
| 115 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 116 | +kind: Gateway |
| 117 | +metadata: |
| 118 | + name: my-tcp-gateway |
| 119 | + namespace: example-ns |
| 120 | +spec: |
| 121 | + gatewayClassName: aws-nlb-gateway-class |
| 122 | + infrastructure: |
| 123 | + parametersRef: |
| 124 | + group: gateway.k8s.aws |
| 125 | + kind: LoadBalancerConfiguration |
| 126 | + name: nlb-lb-config |
| 127 | + listeners: |
| 128 | + - name: unsecure |
| 129 | + protocol: TCP |
| 130 | + port: 80 |
| 131 | + allowedRoutes: |
| 132 | + namespaces: |
| 133 | + from: Same |
| 134 | + - name: secure |
| 135 | + protocol: TCP |
| 136 | + port: 443 |
| 137 | + allowedRoutes: |
| 138 | + namespaces: |
| 139 | + from: Same |
| 140 | +--- |
| 141 | +# lbconfig.yaml |
| 142 | +apiVersion: gateway.k8s.aws/v1beta1 |
| 143 | +kind: LoadBalancerConfiguration |
| 144 | +metadata: |
| 145 | + name: nlb-lb-config |
| 146 | + namespace: example-ns |
| 147 | +spec: |
| 148 | + scheme: internet-facing |
| 149 | +--- |
| 150 | +# my-unsecure-tcproute.yaml |
| 151 | +apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 152 | +kind: TCPRoute |
| 153 | +metadata: |
| 154 | + name: my-unsecure-app-route |
| 155 | + namespace: example-ns |
| 156 | +spec: |
| 157 | + parentRefs: |
| 158 | + - group: gateway.networking.k8s.io |
| 159 | + kind: Gateway |
| 160 | + name: my-tcp-gateway |
| 161 | + sectionName: unsecure |
| 162 | + rules: |
| 163 | + - backendRefs: |
| 164 | + - name: my-alb-gateway |
| 165 | + kind: Gateway |
| 166 | + port: 80 |
| 167 | +--- |
| 168 | +# my-secure-tcproute.yaml |
| 169 | +apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 170 | +kind: TCPRoute |
| 171 | +metadata: |
| 172 | + name: my-secure-app-route |
| 173 | + namespace: example-ns |
| 174 | +spec: |
| 175 | + parentRefs: |
| 176 | + - group: gateway.networking.k8s.io |
| 177 | + kind: Gateway |
| 178 | + name: my-tcp-gateway |
| 179 | + sectionName: secure |
| 180 | + rules: |
| 181 | + - backendRefs: |
| 182 | + - name: my-alb-gateway |
| 183 | + kind: Gateway |
| 184 | + port: 443 |
| 185 | +--- |
| 186 | +# tg-configuration.yaml |
| 187 | +apiVersion: gateway.k8s.aws/v1beta1 |
| 188 | +kind: TargetGroupConfiguration |
| 189 | +metadata: |
| 190 | + name: example-tg-config |
| 191 | + namespace: example-ns |
| 192 | +spec: |
| 193 | + targetReference: |
| 194 | + name: my-alb-gateway |
| 195 | + kind: Gateway |
| 196 | + routeConfigurations: |
| 197 | + - routeIdentifier: |
| 198 | + kind: TCPRoute |
| 199 | + namespace: example-ns |
| 200 | + name: my-unsecure-app-route |
| 201 | + targetGroupProps: |
| 202 | + healthCheckConfig: |
| 203 | + healthCheckProtocol: HTTP |
| 204 | + - routeIdentifier: |
| 205 | + kind: TCPRoute |
| 206 | + namespace: example-ns |
| 207 | + name: my-secure-app-route |
| 208 | + targetGroupProps: |
| 209 | + healthCheckConfig: |
| 210 | + healthCheckProtocol: HTTPS |
| 211 | +``` |
| 212 | +
|
| 213 | +#### Customizing the ALB Gateway target settings |
| 214 | +
|
| 215 | +Customizing the ALB Gateway, in the context as a target, works exactly the same way as customizing a Target Group |
| 216 | +based on a Kubernetes Service. The only caveat is that target groups of type ALB do not support attribute customization, |
| 217 | +this is an AWS limitation and not one imposed within the controller. For more information about customization, see the |
| 218 | +[TargetGroupConfiguration CRD documentation](./targetgroupconfig.md). |
| 219 | +
|
| 220 | +In the example presented above, we have customized the target group that points to the ALB listener port on 443. In our example, |
| 221 | +this is required when forwarding traffic from the NLB to the ALB on listener port 443 as the ALB listener is expecting HTTPS traffic; even |
| 222 | +for health check traffic. |
| 223 | +
|
| 224 | +```yaml |
| 225 | +apiVersion: gateway.k8s.aws/v1beta1 |
| 226 | +kind: TargetGroupConfiguration |
| 227 | +metadata: |
| 228 | + name: example-tg-config |
| 229 | + namespace: example-ns |
| 230 | +spec: |
| 231 | + targetReference: |
| 232 | + name: my-alb-gateway |
| 233 | + kind: Gateway |
| 234 | + routeConfigurations: |
| 235 | + - routeIdentifier: |
| 236 | + kind: TCPRoute |
| 237 | + namespace: example-ns |
| 238 | + name: my-unsecure-app-route |
| 239 | + targetGroupProps: |
| 240 | + healthCheckConfig: |
| 241 | + healthCheckProtocol: HTTP |
| 242 | + - routeIdentifier: |
| 243 | + kind: TCPRoute |
| 244 | + namespace: example-ns |
| 245 | + name: my-secure-app-route |
| 246 | + targetGroupProps: |
| 247 | + healthCheckConfig: |
| 248 | + healthCheckProtocol: HTTPS |
| 249 | +``` |
| 250 | +
|
| 251 | +#### Cross namespace access |
| 252 | +
|
| 253 | +Chained Gateways support [Reference Grants](https://gateway-api.sigs.k8s.io/api-types/referencegrant/) to support chaining |
| 254 | +Gateways in different namespaces. The Reference Grant must exist within the namespace of the ALB Gateway. The same semantics used |
| 255 | +for routes and reference grants apply to Gateway-based reference grants. |
| 256 | +
|
| 257 | +```yaml |
| 258 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 259 | +kind: ReferenceGrant |
| 260 | +metadata: |
| 261 | + name: example-reference-grant |
| 262 | + namespace: alb-gw-ns |
| 263 | +spec: |
| 264 | + from: |
| 265 | + - group: gateway.networking.k8s.io |
| 266 | + kind: TCPRoute |
| 267 | + namespace: nlb-gw-ns |
| 268 | + to: |
| 269 | + - group: gateway.networking.k8s.io |
| 270 | + kind: Gateway |
| 271 | +``` |
| 272 | +
|
| 273 | +In this example, we are establishing a reference grant that allows TCPRoutes from the `nlb-gw-ns` namespace |
| 274 | +to attach any ALB Gateway in the `alb-gw-ns` namespace. |
0 commit comments