1
1
# gitops-istio
2
2
3
+ [ ![ e2e] ( https://github.com/stefanprodan/gitops-istio/workflows/e2e/badge.svg )] ( https://github.com/stefanprodan/gitops-istio/actions )
4
+
3
5
This guide walks you through setting up Istio on a Kubernetes cluster and
4
6
automating A/B testing and canary releases with GitOps pipelines.
5
7
@@ -22,10 +24,10 @@ Components:
22
24
You'll need a Kubernetes cluster ** v1.16** or newer with ` LoadBalancer ` support.
23
25
For testing purposes you can use Minikube with four CPUs and 4GB of memory.
24
26
25
- Install Flux CLI:
27
+ Install Flux CLI and yq :
26
28
27
29
``` bash
28
- brew install fluxcd/tap/flux
30
+ brew install fluxcd/tap/flux yq
29
31
```
30
32
31
33
Fork this repository and clone it:
@@ -37,13 +39,16 @@ cd gitops-istio
37
39
38
40
### Cluster bootstrap
39
41
40
- Install Flux and its Helm Operator by specifying your fork URL:
42
+ Install Flux by specifying your fork URL:
41
43
42
44
``` bash
43
- ./scripts/flux-init.sh
[email protected] :
< YOUR-USERNAME
> /gitops-istio
45
+ flux bootstrap git \
46
+ --url=ssh://
[email protected] /
< YOUR-USERNAME
> /gitops-istio \
47
+ --branch=main \
48
+ --path=clusters/my-cluster
44
49
```
45
50
46
- At startup , Flux generates a SSH key and logs the public key. The above command will print the public key.
51
+ At bootstrap , Flux generates an SSH key and logs the public key. The above command will print the public key.
47
52
48
53
In order to sync your cluster state with git you need to copy the public key and create a deploy key with write
49
54
access on your GitHub repository. On GitHub go to _ Settings > Deploy keys_ click on _ Add deploy key_ ,
@@ -72,7 +77,7 @@ metadata:
72
77
namespace : istio-system
73
78
name : istio-default
74
79
spec :
75
- profile : default
80
+ profile : demo
76
81
components :
77
82
pilot :
78
83
k8s :
84
89
85
90
After modifying the Istio settings, you can push the change to git and Flux will apply it on the cluster.
86
91
The Istio operator will reconfigure the Istio control plane according to your changes.
87
- It can take a couple of minutes for Flux to sync and apply the changes, to speed up the apply
88
- you can use ` flux reconcile ks flux-system --with-source` to trigger a git sync.
89
92
90
93
### Workloads bootstrap
91
94
@@ -144,26 +147,37 @@ A canary analysis is triggered by changes in any of the following objects:
144
147
145
148
For workloads that are not receiving constant traffic Flagger can be configured with a webhook,
146
149
that when called, will start a load test for the target workload. The canary configuration can be found
147
- at [prod /backend/canary.yaml](https://github.com/stefanprodan/gitops-istio/blob/master/prod /backend/canary.yaml).
150
+ at [ apps /backend/canary.yaml] ( https://github.com/stefanprodan/gitops-istio/blob/main/apps /backend/canary.yaml ) .
148
151
149
152
![ Flagger Canary Release] ( https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png )
150
153
151
- Trigger a canary deployment for the backend app by updating the container image :
154
+ Pull the changes from GitHub:
155
+
156
+ ``` sh
157
+ git pull origin main
158
+ ```
159
+
160
+ To trigger a canary deployment for the backend app, bump the container image:
161
+
162
+ ``` bash
163
+ yq e ' .images[0].newTag="5.0.1"' -i ./apps/backend/kustomization.yaml
164
+ ```
165
+
166
+ Commit and push changes:
152
167
153
168
``` bash
154
- $ export FLUX_FORWARD_NAMESPACE=flux
169
+ git add -A && \
170
+ git commit -m " backend 5.0.1" && \
171
+ git push origin main
172
+ ```
155
173
156
- $ fluxctl release --workload=prod:deployment/backend \
157
- --update-image=stefanprodan/podinfo:3.1.1
174
+ Tell Flux to pull the changes or wait one minute for Flux to detect the changes:
158
175
159
- Submitting release ...
160
- WORKLOAD STATUS UPDATES
161
- prod:deployment/backend success backend: stefanprodan/podinfo:3.1.0 -> 3.1.1
162
- Commit pushed: ccb4ae7
163
- Commit applied: ccb4ae7
176
+ ``` bash
177
+ flux reconcile kustomization flux-system --with-source
164
178
```
165
179
166
- Flagger detects that the deployment revision changed and starts a new rollout :
180
+ After a couple of seconds, Flagger detects that the deployment revision changed and starts a new rollout:
167
181
168
182
``` bash
169
183
$ kubectl -n prod describe canary backend
@@ -220,13 +234,18 @@ You can enable A/B testing by specifying the HTTP match conditions and the numbe
220
234
` ` `
221
235
222
236
The above configuration will run an analysis for two minutes targeting Firefox users and those that
223
- have an insider cookie. The frontend configuration can be found at `prod /frontend/canary.yaml`.
237
+ have an insider cookie. The frontend configuration can be found at ` apps /frontend/canary.yaml`.
224
238
225
239
Trigger a deployment by updating the frontend container image :
226
240
227
241
` ` ` bash
228
- $ fluxctl release --workload=prod:deployment/frontend \
229
- --update-image=stefanprodan/podinfo:3.1.1
242
+ yq e '.images[0].newTag="5.0.1"' -i ./apps/frontend/kustomization.yaml
243
+
244
+ git add -A && \
245
+ git commit -m "backend 5.0.1" && \
246
+ git push origin main
247
+
248
+ flux reconcile source git flux-system
230
249
` ` `
231
250
232
251
Flagger detects that the deployment revision changed and starts the A/B testing :
@@ -280,7 +299,7 @@ defines two metric checks:
280
299
` ` `
281
300
282
301
The Prometheus queries used for checking the error rate and latency are located at
283
- [flagger/istio -metrics.yaml](https://github.com/stefanprodan/gitops-istio/blob/master/flagger/ istio-metrics.yaml).
302
+ [flagger-metrics.yaml](https://github.com/stefanprodan/gitops-istio/blob/main/ istio/gateway/flagger -metrics.yaml).
284
303
285
304
During the canary analysis you can generate HTTP 500 errors and high latency to test Flagger's rollback.
286
305
0 commit comments