Skip to content

Commit 44dfe8b

Browse files
authored
add example of blue/green deployment (#2911)
* init draft of blue/green * revise
1 parent 1d584ab commit 44dfe8b

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Split Traffic
2+
3+
You can configure an Application Load Balancer (ALB) to split traffic from the same listener across multiple target groups using rules. This facilitates A/B testing, blue/green deployment, and traffic management without additional tools. The Load Balancer Controller (LBC) supports defining this behavior alongside the standard configuration of an Ingress resource.
4+
5+
More specifically, the ALB supports weighted target groups and advanced request routing.
6+
7+
**Weighted target group**
8+
Multiple target groups can be attached to the same forward action of a listener rule and specify a weight for each group. It allows developers to control how to distribute traffic to multiple versions of their application. For example, when you define a rule having two target groups with weights of 8 and 2, the load balancer will route 80 percent of the traffic to the first target group and 20 percent to the other.
9+
10+
**Advanced request routing**
11+
In addition to the weighted target group, AWS announced the advanced request routing feature in 2019. Advanced request routing gives developers the ability to write rules (and route traffic) based on standard and custom HTTP headers and methods, the request path, the query string, and the source IP address. This new feature simplifies the application architecture by eliminating the need for a proxy fleet for routing, blocks unwanted traffic at the load balancer, and enables the implementation of A/B testing.
12+
13+
## Overview
14+
The ALB is configured to split traffic using annotations on the ingress resrouces. More specifically, the [ingress annotation](../../../guide/ingress/annotations.md#actions) `alb.ingress.kubernetes.io/actions.${service-name}` configures custom actions on the listener.
15+
16+
The body of the annotation is a JSON document that identifies an action type, and configures it. The supported [actions](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#rule-action-types) are `redirect`, `forward`, and `fixed-response`.
17+
18+
With forward action, multiple target groups with different weights can be defined in the annotation. The LBC provisions the target groups and configures the listener rules as per the annotation to direct the traffic.
19+
20+
Importantly:
21+
* The `action-name` in the annotation must match the service name in the Ingress rules. For example, the annotation `alb.ingress.kubernetes.io/actions.blue-green` matches the service name `blue-green` referenced in the Ingress rules.
22+
* The `servicePort` of the service in the Ingress rules must be `use-annotation`.
23+
24+
### Example
25+
26+
The following ingress resource configures the ALB to forward all traffic to hello-kubernetes-v1 service (weight: 100 vs. 0).
27+
28+
Note that the annotation name includes `blue-green`, which matches the service name referenced in the ingress rules.
29+
30+
The [annotation reference](../../../guide/ingress/annotations.md#actions) includes further examples of the JSON configuration for different actions.
31+
32+
```
33+
apiVersion: networking.k8s.io/v1
34+
kind: Ingress
35+
metadata:
36+
name: "hello-kubernetes"
37+
namespace: "hello-kubernetes"
38+
annotations:
39+
kubernetes.io/ingress.class: alb
40+
alb.ingress.kubernetes.io/scheme: internet-facing
41+
alb.ingress.kubernetes.io/target-type: ip
42+
alb.ingress.kubernetes.io/actions.blue-green: |
43+
{
44+
"type":"forward",
45+
"forwardConfig":{
46+
"targetGroups":[
47+
{
48+
"serviceName":"hello-kubernetes-v1",
49+
"servicePort":"80",
50+
"weight":100
51+
},
52+
{
53+
"serviceName":"hello-kubernetes-v2",
54+
"servicePort":"80",
55+
"weight":0
56+
}
57+
]
58+
}
59+
}
60+
labels:
61+
app: hello-kubernetes
62+
spec:
63+
rules:
64+
- http:
65+
paths:
66+
- path: /
67+
pathType: Prefix
68+
backend:
69+
service:
70+
name: blue-green
71+
port:
72+
name: use-annotation
73+
```
74+
75+
76+

0 commit comments

Comments
 (0)