Skip to content

Commit ed47249

Browse files
committed
add: lab14 solution
1 parent 6f6bef4 commit ed47249

8 files changed

Lines changed: 1040 additions & 0 deletions

File tree

k8s/ROLLOUTS.md

Lines changed: 816 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{{- if and .Values.rollout.enabled .Values.rollout.analysis.enabled }}
2+
apiVersion: argoproj.io/v1alpha1
3+
kind: AnalysisTemplate
4+
metadata:
5+
name: {{ include "devops-python-app.fullname" . }}-health-check
6+
labels:
7+
{{- include "devops-python-app.labels" . | nindent 4 }}
8+
spec:
9+
metrics:
10+
- name: health-check
11+
interval: 10s
12+
count: 5
13+
successCondition: result == "ok"
14+
failureLimit: 3
15+
provider:
16+
web:
17+
url: http://{{ include "devops-python-app.fullname" . }}-service.{{ .Release.Namespace }}.svc.cluster.local/health
18+
jsonPath: "{$.status}"
19+
timeoutSeconds: 5
20+
- name: canary-health
21+
interval: 15s
22+
count: 3
23+
successCondition: result == "ok"
24+
failureLimit: 2
25+
provider:
26+
web:
27+
url: http://{{ include "devops-python-app.fullname" . }}-service-preview.{{ .Release.Namespace }}.svc.cluster.local/health
28+
jsonPath: "{$.status}"
29+
timeoutSeconds: 5
30+
---
31+
apiVersion: argoproj.io/v1alpha1
32+
kind: AnalysisTemplate
33+
metadata:
34+
name: {{ include "devops-python-app.fullname" . }}-error-rate
35+
labels:
36+
{{- include "devops-python-app.labels" . | nindent 4 }}
37+
spec:
38+
metrics:
39+
- name: error-rate
40+
interval: 30s
41+
count: 3
42+
successCondition: default(result, 0) < 0.05
43+
failureLimit: 2
44+
provider:
45+
prometheus:
46+
address: "http://prometheus-server.monitoring.svc.cluster.local:9090"
47+
query: |
48+
sum(rate(http_requests_total{status=~"5.*"}[1m])) /
49+
sum(rate(http_requests_total[1m]))
50+
{{- end }}

k8s/devops-python-app/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if not .Values.rollout.enabled }}
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
@@ -94,3 +95,4 @@ spec:
9495
claimName: {{ include "devops-python-app.pvcName" . }}
9596
{{- end }}
9697
{{- end }}
98+
{{- end }}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{{- if .Values.rollout.enabled }}
2+
apiVersion: argoproj.io/v1alpha1
3+
kind: Rollout
4+
metadata:
5+
name: {{ include "devops-python-app.fullname" . }}
6+
labels:
7+
{{- include "devops-python-app.labels" . | nindent 4 }}
8+
spec:
9+
replicas: {{ .Values.replicaCount }}
10+
revisionHistoryLimit: {{ .Values.rollout.revisionHistoryLimit }}
11+
selector:
12+
matchLabels:
13+
{{- include "devops-python-app.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
labels:
17+
{{- include "devops-python-app.selectorLabels" . | nindent 8 }}
18+
app.kubernetes.io/component: api
19+
{{- if or .Values.configMap.file.enabled .Values.configMap.env.enabled .Values.vault.enabled }}
20+
annotations:
21+
{{- if .Values.configMap.file.enabled }}
22+
checksum/config-file: {{ .Files.Get "files/config.json" | sha256sum }}
23+
{{- end }}
24+
{{- if .Values.configMap.env.enabled }}
25+
checksum/config-env: {{ printf "%s|%s|%s" .Values.appConfig.appEnv .Values.appConfig.logLevel (toYaml .Values.configMap.env.data) | sha256sum }}
26+
{{- end }}
27+
{{- if .Values.vault.enabled }}
28+
vault.hashicorp.com/agent-inject: "true"
29+
vault.hashicorp.com/role: {{ .Values.vault.role | quote }}
30+
{{ printf "vault.hashicorp.com/agent-inject-secret-%s" .Values.vault.fileName | quote }}: {{ .Values.vault.secretPath | quote }}
31+
{{ printf "vault.hashicorp.com/secret-volume-path-%s" .Values.vault.fileName | quote }}: {{ .Values.vault.mountPath | quote }}
32+
{{ printf "vault.hashicorp.com/agent-inject-command-%s" .Values.vault.fileName | quote }}: {{ .Values.vault.injectCommand | quote }}
33+
{{ printf "vault.hashicorp.com/agent-inject-template-%s" .Values.vault.fileName | quote }}: |
34+
{{ .Values.vault.template | nindent 10 }}
35+
{{- end }}
36+
{{- end }}
37+
spec:
38+
serviceAccountName: {{ include "devops-python-app.serviceAccountName" . }}
39+
containers:
40+
- name: {{ include "devops-python-app.name" . }}
41+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
42+
imagePullPolicy: {{ .Values.image.pullPolicy }}
43+
ports:
44+
- name: http
45+
containerPort: {{ .Values.container.port }}
46+
protocol: TCP
47+
env:
48+
{{- include "devops-python-app.commonEnv" . | nindent 12 }}
49+
{{- with .Values.extraEnv }}
50+
{{- toYaml . | nindent 12 }}
51+
{{- end }}
52+
{{- if or .Values.secret.enabled .Values.configMap.env.enabled }}
53+
envFrom:
54+
{{- if .Values.secret.enabled }}
55+
- secretRef:
56+
name: {{ include "devops-python-app.secretName" . }}
57+
{{- end }}
58+
{{- if .Values.configMap.env.enabled }}
59+
- configMapRef:
60+
name: {{ include "devops-python-app.configEnvConfigMapName" . }}
61+
{{- end }}
62+
{{- end }}
63+
{{- if or .Values.configMap.file.enabled .Values.persistence.enabled }}
64+
volumeMounts:
65+
{{- if .Values.configMap.file.enabled }}
66+
- name: app-config
67+
mountPath: {{ .Values.configMap.file.mountPath }}
68+
readOnly: true
69+
{{- end }}
70+
{{- if .Values.persistence.enabled }}
71+
- name: app-data
72+
mountPath: {{ .Values.persistence.mountPath }}
73+
{{- end }}
74+
{{- end }}
75+
resources:
76+
{{- toYaml .Values.resources | nindent 12 }}
77+
readinessProbe:
78+
{{- toYaml .Values.readinessProbe | nindent 12 }}
79+
livenessProbe:
80+
{{- toYaml .Values.livenessProbe | nindent 12 }}
81+
{{- if or .Values.configMap.file.enabled .Values.persistence.enabled }}
82+
volumes:
83+
{{- if .Values.configMap.file.enabled }}
84+
- name: app-config
85+
configMap:
86+
name: {{ include "devops-python-app.configFileConfigMapName" . }}
87+
{{- end }}
88+
{{- if .Values.persistence.enabled }}
89+
- name: app-data
90+
persistentVolumeClaim:
91+
claimName: {{ include "devops-python-app.pvcName" . }}
92+
{{- end }}
93+
{{- end }}
94+
strategy:
95+
{{- if eq .Values.rollout.strategy "canary" }}
96+
canary:
97+
{{- if .Values.rollout.canary.useAnalysis }}
98+
steps:
99+
- setWeight: 20
100+
- analysis:
101+
templates:
102+
- templateName: {{ include "devops-python-app.fullname" . }}-health-check
103+
- setWeight: 50
104+
- pause: { duration: 30s }
105+
- analysis:
106+
templates:
107+
- templateName: {{ include "devops-python-app.fullname" . }}-health-check
108+
- setWeight: 100
109+
{{- else }}
110+
steps:
111+
{{- toYaml .Values.rollout.canary.steps | nindent 8 }}
112+
{{- end }}
113+
{{- else if eq .Values.rollout.strategy "blueGreen" }}
114+
blueGreen:
115+
activeService: {{ include "devops-python-app.fullname" . }}-service
116+
previewService: {{ include "devops-python-app.fullname" . }}-service-preview
117+
autoPromotionEnabled: {{ .Values.rollout.blueGreen.autoPromotionEnabled }}
118+
{{- if .Values.rollout.blueGreen.autoPromotionSeconds }}
119+
autoPromotionSeconds: {{ .Values.rollout.blueGreen.autoPromotionSeconds }}
120+
{{- end }}
121+
{{- end }}
122+
{{- end }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{- if and .Values.rollout.enabled (eq .Values.rollout.strategy "blueGreen") }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ include "devops-python-app.fullname" . }}-service-preview
6+
labels:
7+
{{- include "devops-python-app.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: service-preview
9+
spec:
10+
type: {{ .Values.service.type }}
11+
selector:
12+
{{- include "devops-python-app.selectorLabels" . | nindent 4 }}
13+
ports:
14+
- name: http
15+
protocol: TCP
16+
port: {{ .Values.service.port }}
17+
targetPort: {{ .Values.service.targetPort }}
18+
{{- end }}

k8s/devops-python-app/values-dev.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
replicaCount: 1
22

3+
rollout:
4+
strategy: canary
5+
blueGreen:
6+
autoPromotionEnabled: false
7+
38
image:
49
tag: latest
510

k8s/devops-python-app/values-prod.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
replicaCount: 3
22

3+
rollout:
4+
strategy: canary
5+
blueGreen:
6+
autoPromotionEnabled: false
7+
38
image:
49
tag: "1.0.0"
510

k8s/devops-python-app/values.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ livenessProbe:
101101
failureThreshold: 3
102102
successThreshold: 1
103103

104+
rollout:
105+
enabled: true
106+
revisionHistoryLimit: 3
107+
strategy: canary
108+
canary:
109+
steps:
110+
- setWeight: 20
111+
- pause: {}
112+
- setWeight: 40
113+
- pause: { duration: 30s }
114+
- setWeight: 60
115+
- pause: { duration: 30s }
116+
- setWeight: 80
117+
- pause: { duration: 30s }
118+
- setWeight: 100
119+
useAnalysis: false
120+
blueGreen:
121+
autoPromotionEnabled: false
122+
autoPromotionSeconds: null
123+
analysis:
124+
enabled: false
125+
104126
hooks:
105127
enabled: true
106128
image: busybox:1.36

0 commit comments

Comments
 (0)