Skip to content

Commit 4fd9a4a

Browse files
committed
Kustomize apps
Signed-off-by: Stefan Prodan <[email protected]>
1 parent 46da5d5 commit 4fd9a4a

File tree

6 files changed

+65
-28
lines changed

6 files changed

+65
-28
lines changed

README.md

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# gitops-istio
22

3+
[![e2e](https://github.com/stefanprodan/gitops-istio/workflows/e2e/badge.svg)](https://github.com/stefanprodan/gitops-istio/actions)
4+
35
This guide walks you through setting up Istio on a Kubernetes cluster and
46
automating A/B testing and canary releases with GitOps pipelines.
57

@@ -22,10 +24,10 @@ Components:
2224
You'll need a Kubernetes cluster **v1.16** or newer with `LoadBalancer` support.
2325
For testing purposes you can use Minikube with four CPUs and 4GB of memory.
2426

25-
Install Flux CLI:
27+
Install Flux CLI and yq:
2628

2729
```bash
28-
brew install fluxcd/tap/flux
30+
brew install fluxcd/tap/flux yq
2931
```
3032

3133
Fork this repository and clone it:
@@ -37,13 +39,16 @@ cd gitops-istio
3739

3840
### Cluster bootstrap
3941

40-
Install Flux and its Helm Operator by specifying your fork URL:
42+
Install Flux by specifying your fork URL:
4143

4244
```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
4449
```
4550

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.
4752

4853
In order to sync your cluster state with git you need to copy the public key and create a deploy key with write
4954
access on your GitHub repository. On GitHub go to _Settings > Deploy keys_ click on _Add deploy key_,
@@ -72,7 +77,7 @@ metadata:
7277
namespace: istio-system
7378
name: istio-default
7479
spec:
75-
profile: default
80+
profile: demo
7681
components:
7782
pilot:
7883
k8s:
@@ -84,8 +89,6 @@ spec:
8489
8590
After modifying the Istio settings, you can push the change to git and Flux will apply it on the cluster.
8691
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.
8992
9093
### Workloads bootstrap
9194
@@ -144,26 +147,37 @@ A canary analysis is triggered by changes in any of the following objects:
144147

145148
For workloads that are not receiving constant traffic Flagger can be configured with a webhook,
146149
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).
148151

149152
![Flagger Canary Release](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png)
150153

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:
152167

153168
```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+
```
155173

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:
158175

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
164178
```
165179

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:
167181

168182
```bash
169183
$ 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
220234
```
221235
222236
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`.
224238

225239
Trigger a deployment by updating the frontend container image:
226240

227241
```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
230249
```
231250

232251
Flagger detects that the deployment revision changed and starts the A/B testing:
@@ -280,7 +299,7 @@ defines two metric checks:
280299
```
281300

282301
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).
284303

285304
During the canary analysis you can generate HTTP 500 errors and high latency to test Flagger's rollback.
286305

apps/backend/deployment.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spec:
2626
spec:
2727
containers:
2828
- name: backend
29-
image: stefanprodan/podinfo:3.1.0
29+
image: ghcr.io/stefanprodan/podinfo:5.0.0
3030
imagePullPolicy: IfNotPresent
3131
ports:
3232
- containerPort: 9898
@@ -36,8 +36,6 @@ spec:
3636
- ./podinfo
3737
- --port=9898
3838
- --level=info
39-
- --random-delay=false
40-
- --random-error=false
4139
env:
4240
- name: PODINFO_UI_COLOR
4341
value: "#34577c"

apps/backend/kustomization.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- canary.yaml
5+
- deployment.yaml
6+
- hpa.yaml
7+
images:
8+
- name: ghcr.io/stefanprodan/podinfo
9+
newName: ghcr.io/stefanprodan/podinfo
10+
newTag: 5.0.0

apps/frontend/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
spec:
2626
containers:
2727
- name: frontend
28-
image: stefanprodan/podinfo:3.1.0
28+
image: ghcr.io/stefanprodan/podinfo:5.0.0
2929
imagePullPolicy: IfNotPresent
3030
ports:
3131
- containerPort: 9898

apps/frontend/kustomization.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- canary.yaml
5+
- deployment.yaml
6+
- hpa.yaml
7+
images:
8+
- name: ghcr.io/stefanprodan/podinfo
9+
newName: ghcr.io/stefanprodan/podinfo
10+
newTag: 5.0.0

clusters/my-cluster/apps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: apps
55
namespace: flux-system
66
spec:
7-
interval: 10m0s
7+
interval: 30m0s
88
dependsOn:
99
- name: istio-system
1010
sourceRef:

0 commit comments

Comments
 (0)