my-homelab-configs/apps/progressive-lab/templates/workloads.tpl

107 lines
3.6 KiB
Smarty

apiVersion: v1
kind: ConfigMap
metadata:
name: progressive-lab-code
data:
backend.py: |
{{ .Files.Get "files/backend.py" | indent 4 }}
router.py: |
{{ .Files.Get "files/router.py" | indent 4 }}
---
{{- range $version := list "stable" "canary" }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: progressive-{{ $version }}
spec:
replicas: 1
strategy: {type: Recreate}
selector:
matchLabels: {app: progressive-{{ $version }}}
template:
metadata:
labels: {app: progressive-{{ $version }}}
annotations:
code-hash: {{ $.Files.Get "files/backend.py" | sha256sum | quote }}
spec:
automountServiceAccountToken: false
securityContext: {runAsNonRoot: true, runAsUser: 65532, runAsGroup: 65532, seccompProfile: {type: RuntimeDefault}}
containers:
- name: app
image: python:3.12-alpine
command: ["python", "-B", "/app/backend.py"]
env:
- {name: VERSION, value: {{ $version | quote }}}
- {name: DEMO_FAIL, value: {{ and (eq $version "canary") $.Values.canaryFailure | quote }}}
ports: [{name: http, containerPort: 8080}]
readinessProbe:
httpGet:
path: {{ if and (eq $version "canary") $.Values.badReadiness }}/unready{{ else }}/health{{ end }}
port: http
periodSeconds: 3
resources:
requests: {cpu: 10m, memory: 32Mi}
limits: {memory: 128Mi}
securityContext: {allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities: {drop: [ALL]}}
volumeMounts: [{name: code, mountPath: /app, readOnly: true}]
volumes: [{name: code, configMap: {name: progressive-lab-code}}]
---
apiVersion: v1
kind: Service
metadata:
name: progressive-{{ $version }}
spec:
selector: {app: progressive-{{ $version }}}
ports: [{name: http, port: 8080, targetPort: http}]
---
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: progressive-router
spec:
replicas: 1
selector:
matchLabels: {app: progressive-router}
template:
metadata:
labels: {app: progressive-router}
annotations:
code-hash: {{ .Files.Get "files/router.py" | sha256sum | quote }}
spec:
automountServiceAccountToken: false
securityContext: {runAsNonRoot: true, runAsUser: 65532, runAsGroup: 65532, seccompProfile: {type: RuntimeDefault}}
containers:
- name: router
image: python:3.12-alpine
command: ["python", "-B", "/app/router.py"]
env: [{name: CANARY_WEIGHT, value: {{ .Values.canaryWeight | quote }}}]
ports: [{name: http, containerPort: 8080}]
readinessProbe: {httpGet: {path: /health, port: http}}
resources:
requests: {cpu: 10m, memory: 32Mi}
limits: {memory: 128Mi}
securityContext: {allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities: {drop: [ALL]}}
volumeMounts: [{name: code, mountPath: /app, readOnly: true}]
volumes: [{name: code, configMap: {name: progressive-lab-code}}]
---
apiVersion: v1
kind: Service
metadata:
name: progressive-router
labels: {app: progressive-router}
spec:
selector: {app: progressive-router}
ports: [{name: http, port: 8080, targetPort: http}]
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: progressive-lab
namespace: monitoring
labels: {release: prometheus-stack}
spec:
namespaceSelector: {matchNames: [progressive-lab]}
selector: {matchLabels: {app: progressive-router}}
endpoints: [{port: http, path: /metrics, interval: 15s}]