Skip to content

Commit 32587b3

Browse files
committed
advanced_routing/weighted_routing support
1 parent 88b1ad3 commit 32587b3

20 files changed

+8219
-915
lines changed

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ linters:
1717
issues:
1818
exclude:
1919
- IpAddressType # AWS SDK GO are using IpAddressType, while go-lint requires IPAddressType :(
20-
- ClientId # AWS SDK GO are using ClientId, while go-lint requires ClientID :(
20+
- ClientId # AWS SDK GO are using ClientId, while go-lint requires ClientID :(
21+
- SourceIp
22+
- Http

docs/guide/ingress/annotation.md

Lines changed: 168 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ You can add kubernetes annotations to ingress and service objects to customize t
2424
|[alb.ingress.kubernetes.io/auth-type](#auth-type)|none\|oidc\|cognito|none|ingress,service|
2525
|[alb.ingress.kubernetes.io/backend-protocol](#backend-protocol)|HTTP \| HTTPS|HTTP|ingress,service|
2626
|[alb.ingress.kubernetes.io/certificate-arn](#certificate-arn)|stringList|N/A|ingress|
27+
|[alb.ingress.kubernetes.io/conditions.${conditions-name}](#conditions)|json|N/A|ingress|
2728
|[alb.ingress.kubernetes.io/healthcheck-interval-seconds](#healthcheck-interval-seconds)|integer|'15'|ingress,service|
2829
|[alb.ingress.kubernetes.io/healthcheck-path](#healthcheck-path)|string|/|ingress,service|
2930
|[alb.ingress.kubernetes.io/healthcheck-port](#healthcheck-port)|integer \| traffic-port|traffic-port|ingress,service|
@@ -112,25 +113,173 @@ Traffic Routing can be controlled with following annotations:
112113
The `action-name` in the annotation must match the serviceName in the ingress rules, and servicePort must be `use-annotation`.
113114

114115
!!!example
115-
- fixed 503 response
116-
```yaml
117-
apiVersion: extensions/v1beta1
118-
kind: Ingress
119-
metadata:
120-
namespace: default
121-
name: ingress
122-
annotations:
123-
kubernetes.io/ingress.class: alb
124-
alb.ingress.kubernetes.io/actions.response-503: '{"Type": "fixed-response", "FixedResponseConfig": {"ContentType":"text/plain", "StatusCode":"503", "MessageBody":"503 error text"}}'
125-
spec:
126-
rules:
127-
- http:
128-
paths:
129-
- path: /503
130-
backend:
131-
serviceName: response-503
132-
servicePort: use-annotation
133-
```
116+
- response-503: return fixed 503 response
117+
- redirect-to-eks: redirect to an external url
118+
- forward-single-tg: forward to an single targetGroup [**simplified schema**]
119+
- forward-multiple-tg: forward to multiple targetGroups with different weights and stickiness config [**advanced schema**]
120+
121+
```yaml
122+
apiVersion: extensions/v1beta1
123+
kind: Ingress
124+
metadata:
125+
namespace: default
126+
name: ingress
127+
annotations:
128+
kubernetes.io/ingress.class: alb
129+
alb.ingress.kubernetes.io/scheme: internet-facing
130+
alb.ingress.kubernetes.io/actions.response-503: >
131+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"503","MessageBody":"503 error text"}}
132+
alb.ingress.kubernetes.io/actions.redirect-to-eks: >
133+
{"Type":"redirect","RedirectConfig":{"Host":"aws.amazon.com","Path":"/eks/","Port":"443","Protocol":"HTTPS","Query":"k=v","StatusCode":"HTTP_302"}}
134+
alb.ingress.kubernetes.io/actions.forward-single-tg: >
135+
{"Type":"forward","TargetGroupArn": "arn-of-your-target-group"}
136+
alb.ingress.kubernetes.io/actions.forward-multiple-tg: >
137+
{"Type":"forward","ForwardConfig":{"TargetGroups":[{"TargetGroupArn":""arn-of-your-target-group","Weight":80},{"ServiceName":"service-1","ServicePort":"80","Weight":20}],"TargetGroupStickinessConfig":{"Enabled":true,"DurationSeconds":200}}}
138+
spec:
139+
rules:
140+
- http:
141+
paths:
142+
- path: /503
143+
backend:
144+
serviceName: response-503
145+
servicePort: use-annotation
146+
- path: /eks
147+
backend:
148+
serviceName: redirect-to-eks
149+
servicePort: use-annotation
150+
- path: /path1
151+
backend:
152+
serviceName: forward-single-tg
153+
servicePort: use-annotation
154+
- path: /path2
155+
backend:
156+
serviceName: forward-multiple-tg
157+
servicePort: use-annotation
158+
```
159+
160+
!!!note "use ARN in forward Action"
161+
ARN can be used in forward action(both simplified schema and advanced schema), it must be an targetGroup created outside of k8s, typically an targetGroup for legacy application.
162+
!!!note "use ServiceName/ServicePort in forward Action"
163+
ServiceName/ServicePort can be used in forward action(advanced schema only).
164+
165+
Limitation: [Auth related annotations](#authentication) on Service object won't be respected, it must be applied to Ingress object.
166+
167+
- <a name="conditions">`alb.ingress.kubernetes.io/conditions.${conditions-name}`</a> Provides a method for specifing routing conditions **in addition to original host/path condition on Ingress spec**.
168+
169+
The `conditions-name` in the annotation must match the serviceName in the ingress rules, and servicePort must be `use-annotation`.
170+
171+
!!!example
172+
- rule-path1:
173+
- Host is www.example.com OR anno.example.com
174+
- Path is /path1
175+
- rule-path2:
176+
- Host is www.example.com
177+
- Path is /path2 OR /anno/path2
178+
- rule-path3:
179+
- Host is www.example.com
180+
- Path is /path3
181+
- Http header HeaderName is HeaderValue1 OR HeaderValue2
182+
- rule-path4:
183+
- Host is www.example.com
184+
- Path is /path4
185+
- Http request method is GET OR HEAD
186+
- rule-path5:
187+
- Host is www.example.com
188+
- Path is /path5
189+
- Query string is paramA:valueA1 OR paramA:valueA2
190+
- rule-path6:
191+
- Host is www.example.com
192+
- Path is /path6
193+
- Source IP is192.168.0.0/16 OR 172.16.0.0/16
194+
- rule-path7:
195+
- Host is www.example.com
196+
- Path is /path6
197+
- Http header HeaderName is HeaderValue
198+
- Query string is paramA:valueA
199+
- Query string is paramB:valueB
200+
201+
```yaml
202+
apiVersion: extensions/v1beta1
203+
kind: Ingress
204+
metadata:
205+
namespace: default
206+
name: ingress
207+
annotations:
208+
kubernetes.io/ingress.class: alb
209+
alb.ingress.kubernetes.io/scheme: internet-facing
210+
alb.ingress.kubernetes.io/actions.rule-path1: >
211+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"Host is www.example.com OR anno.example.com"}}
212+
alb.ingress.kubernetes.io/conditions.rule-path1: >
213+
[{"Field":"host-header","HostHeaderConfig":{"Values":["anno.example.com"]}}]
214+
alb.ingress.kubernetes.io/actions.rule-path2: >
215+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"Path is /path2 OR /anno/path2"}}
216+
alb.ingress.kubernetes.io/conditions.rule-path2: >
217+
[{"Field":"path-pattern","PathPatternConfig":{"Values":["/anno/path2"]}}]
218+
alb.ingress.kubernetes.io/actions.rule-path3: >
219+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"Http header HeaderName is HeaderValue1 OR HeaderValue2"}}
220+
alb.ingress.kubernetes.io/conditions.rule-path3: >
221+
[{"Field":"http-header","HttpHeaderConfig":{"HttpHeaderName": "HeaderName", "Values":["HeaderValue1", "HeaderValue2"]}}]
222+
alb.ingress.kubernetes.io/actions.rule-path4: >
223+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"Http request method is GET OR HEAD"}}
224+
alb.ingress.kubernetes.io/conditions.rule-path4: >
225+
[{"Field":"http-request-method","HttpRequestMethodConfig":{"Values":["GET", "HEAD"]}}]
226+
alb.ingress.kubernetes.io/actions.rule-path5: >
227+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"Query string is paramA:valueA1 OR paramA:valueA2"}}
228+
alb.ingress.kubernetes.io/conditions.rule-path5: >
229+
[{"Field":"query-string","QueryStringConfig":{"Values":[{"Key":"paramA","Value":"valueA1"},{"Key":"paramA","Value":"valueA2"}]}}]
230+
alb.ingress.kubernetes.io/actions.rule-path6: >
231+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"Source IP is 192.168.0.0/16 OR 172.16.0.0/16"}}
232+
alb.ingress.kubernetes.io/conditions.rule-path6: >
233+
[{"Field":"source-ip","SourceIpConfig":{"Values":["192.168.0.0/16", "172.16.0.0/16"]}}]
234+
alb.ingress.kubernetes.io/actions.rule-path7: >
235+
{"Type":"fixed-response","FixedResponseConfig":{"ContentType":"text/plain","StatusCode":"200","MessageBody":"multiple conditions applies"}}
236+
alb.ingress.kubernetes.io/conditions.rule-path7: >
237+
[{"Field":"http-header","HttpHeaderConfig":{"HttpHeaderName": "HeaderName", "Values":["HeaderValue"]}},{"Field":"query-string","QueryStringConfig":{"Values":[{"Key":"paramA","Value":"valueA"}]}},{"Field":"query-string","QueryStringConfig":{"Values":[{"Key":"paramB","Value":"valueB"}]}}]
238+
spec:
239+
rules:
240+
- host: www.example.com
241+
http:
242+
paths:
243+
- path: /path1
244+
backend:
245+
serviceName: rule-path1
246+
servicePort: use-annotation
247+
- path: /path2
248+
backend:
249+
serviceName: rule-path2
250+
servicePort: use-annotation
251+
- path: /path3
252+
backend:
253+
serviceName: rule-path3
254+
servicePort: use-annotation
255+
- path: /path4
256+
backend:
257+
serviceName: rule-path4
258+
servicePort: use-annotation
259+
- path: /path5
260+
backend:
261+
serviceName: rule-path5
262+
servicePort: use-annotation
263+
- path: /path6
264+
backend:
265+
serviceName: rule-path6
266+
servicePort: use-annotation
267+
- path: /path7
268+
backend:
269+
serviceName: rule-path7
270+
servicePort: use-annotation
271+
```
272+
273+
!!!warning "limitations"
274+
General ALB limitations applies:
275+
276+
1. Each rule can optionally include up to one of each of the following conditions: host-header, http-request-method, path-pattern, and source-ip. Each rule can also optionally include one or more of each of the following conditions: http-header and query-string.
277+
278+
2. You can specify up to three match evaluations per condition.
279+
280+
3. You can specify up to five match evaluations per rule.
281+
282+
Refer [ALB documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#rule-condition-types) for more details.
134283

135284
## Access control
136285
Access control for LoadBalancer can be controlled with following annotations:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/kubernetes-sigs/aws-alb-ingress-controller
33
require (
44
github.com/appscode/jsonpatch v0.0.0-20190108182946-7c0e3b262f30 // indirect
55
github.com/aws/aws-k8s-tester/e2e/tester v0.0.0-20190907061006-260b0e114d90
6-
github.com/aws/aws-sdk-go v1.23.21
6+
github.com/aws/aws-sdk-go v1.27.3
77
github.com/blang/semver v3.5.1+incompatible
88
github.com/go-logr/glogr v0.1.0
99
github.com/go-logr/logr v0.1.0 // indirect
@@ -31,7 +31,7 @@ require (
3131
github.com/prometheus/common v0.4.0
3232
github.com/spf13/pflag v1.0.5
3333
github.com/stretchr/testify v1.4.0
34-
github.com/ticketmaster/aws-sdk-go-cache v0.0.0-20180926195306-58922816129c
34+
github.com/ticketmaster/aws-sdk-go-cache v0.0.0-20180926195306-58922816129c // indirect
3535
golang.org/x/oauth2 v0.0.0-20190212230446-3e8b2be13635 // indirect
3636
gopkg.in/inf.v0 v0.9.1 // indirect
3737
k8s.io/api v0.0.0-20181213150558-05914d821849

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ github.com/aws/aws-k8s-tester/e2e/tester v0.0.0-20190907061006-260b0e114d90/go.m
1616
github.com/aws/aws-sdk-go v1.15.39/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
1717
github.com/aws/aws-sdk-go v1.23.21 h1:eVJT2C99cAjZlBY8+CJovf6AwrSANzAcYNuxdCB+SPk=
1818
github.com/aws/aws-sdk-go v1.23.21/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
19+
github.com/aws/aws-sdk-go v1.25.43 h1:R5YqHQFIulYVfgRySz9hvBRTWBjudISa+r0C8XQ1ufg=
20+
github.com/aws/aws-sdk-go v1.25.43/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
21+
github.com/aws/aws-sdk-go v1.27.3 h1:CBWC7Yot0U6OU/uosUmq7tKJVBTq6HrhgW1Vjpt9SMw=
22+
github.com/aws/aws-sdk-go v1.27.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
1923
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
2024
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
2125
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@@ -380,6 +384,7 @@ golang.org/x/tools v0.0.0-20191010075000-0337d82405ff h1:XdBG6es/oFDr1HwaxkxgVve
380384
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
381385
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
382386
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
387+
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
383388
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
384389
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
385390
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

0 commit comments

Comments
 (0)