From 19e5143324b710eb3e258c485d19e30702a1e4e7 Mon Sep 17 00:00:00 2001
From: abourliatoux <abourliatoux@takima.fr>
Date: Fri, 9 Feb 2024 16:04:22 +0100
Subject: [PATCH] add solution

---
 .../day-3/step-1 => step-1}/.gitignore        |   0
 step-1/Chart.yaml                             |  26 +++++
 step-1/templates/api/api-config.yaml          |  14 +++
 step-1/templates/api/api-deployment.yaml      |  83 ++++++++++++++
 step-1/templates/api/api-ingress.yaml         |  26 +++++
 step-1/templates/api/api-service.yaml         |  13 +++
 step-1/templates/db/pg-config.yaml            |   6 ++
 step-1/templates/db/pg-credentials.yaml       |   8 ++
 step-1/templates/db/pg-deployment.yaml        |  34 ++++++
 step-1/templates/db/pg-service.yaml           |  13 +++
 step-1/templates/front/front-config.yaml      |  14 +++
 .../templates/front}/front-deployment.yaml    |   0
 .../templates/front}/front-ingress.yaml       |   0
 .../templates/front}/front-service.yaml       |   0
 .../day-3/step-1 => step-1}/values.yaml       |  17 ++-
 step-2-bonus/.gitignore                       |   1 +
 .../day-3/step-1 => step-2-bonus}/Chart.yaml  |   0
 step-2-bonus/templates/_helpers.tpl           | 101 ++++++++++++++++++
 step-2-bonus/templates/api-config.yaml        |  10 ++
 step-2-bonus/templates/api-deployment.yaml    |  79 ++++++++++++++
 step-2-bonus/templates/api-ingress.yaml       |  25 +++++
 step-2-bonus/templates/api-service.yaml       |  13 +++
 .../templates/front-config.yaml               |   2 +-
 step-2-bonus/templates/front-deployment.yaml  |  67 ++++++++++++
 step-2-bonus/templates/front-ingress.yaml     |  27 +++++
 step-2-bonus/templates/front-service.yaml     |  13 +++
 step-2-bonus/templates/pg-config.yaml         |  10 ++
 step-2-bonus/templates/pg-credentials.yaml    |  11 ++
 step-2-bonus/templates/pg-deployment.yaml     |  52 +++++++++
 step-2-bonus/templates/pg-pvc.yaml            |  15 +++
 step-2-bonus/templates/pg-service.yaml        |  12 +++
 step-2-bonus/values.prod.yaml                 |  40 +++++++
 step-2-bonus/values.staging.yaml              |  40 +++++++
 step-2-bonus/values.yaml                      |  48 +++++++++
 34 files changed, 817 insertions(+), 3 deletions(-)
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1 => step-1}/.gitignore (100%)
 create mode 100644 step-1/Chart.yaml
 create mode 100644 step-1/templates/api/api-config.yaml
 create mode 100644 step-1/templates/api/api-deployment.yaml
 create mode 100644 step-1/templates/api/api-ingress.yaml
 create mode 100644 step-1/templates/api/api-service.yaml
 create mode 100644 step-1/templates/db/pg-config.yaml
 create mode 100644 step-1/templates/db/pg-credentials.yaml
 create mode 100644 step-1/templates/db/pg-deployment.yaml
 create mode 100644 step-1/templates/db/pg-service.yaml
 create mode 100644 step-1/templates/front/front-config.yaml
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates => step-1/templates/front}/front-deployment.yaml (100%)
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates => step-1/templates/front}/front-ingress.yaml (100%)
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates => step-1/templates/front}/front-service.yaml (100%)
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1 => step-1}/values.yaml (52%)
 create mode 100644 step-2-bonus/.gitignore
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1 => step-2-bonus}/Chart.yaml (100%)
 create mode 100644 step-2-bonus/templates/_helpers.tpl
 create mode 100644 step-2-bonus/templates/api-config.yaml
 create mode 100644 step-2-bonus/templates/api-deployment.yaml
 create mode 100644 step-2-bonus/templates/api-ingress.yaml
 create mode 100644 step-2-bonus/templates/api-service.yaml
 rename {k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1 => step-2-bonus}/templates/front-config.yaml (89%)
 create mode 100644 step-2-bonus/templates/front-deployment.yaml
 create mode 100644 step-2-bonus/templates/front-ingress.yaml
 create mode 100644 step-2-bonus/templates/front-service.yaml
 create mode 100644 step-2-bonus/templates/pg-config.yaml
 create mode 100644 step-2-bonus/templates/pg-credentials.yaml
 create mode 100644 step-2-bonus/templates/pg-deployment.yaml
 create mode 100644 step-2-bonus/templates/pg-pvc.yaml
 create mode 100644 step-2-bonus/templates/pg-service.yaml
 create mode 100644 step-2-bonus/values.prod.yaml
 create mode 100644 step-2-bonus/values.staging.yaml
 create mode 100644 step-2-bonus/values.yaml

diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/.gitignore b/step-1/.gitignore
similarity index 100%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/.gitignore
rename to step-1/.gitignore
diff --git a/step-1/Chart.yaml b/step-1/Chart.yaml
new file mode 100644
index 0000000..b78e1c3
--- /dev/null
+++ b/step-1/Chart.yaml
@@ -0,0 +1,26 @@
+apiVersion: v2
+name: cdb
+description: All applications in the cdb ecosystem
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+# Versions are expected to follow Semantic Versioning (https://semver.org/)
+version: 0.1.1
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application. Versions are not expected to
+# follow Semantic Versioning. They should reflect the version the application is using.
+appVersion: snapshot
+maintainers:
+- name: takiformation
+  email: takiformation@takima.school
diff --git a/step-1/templates/api/api-config.yaml b/step-1/templates/api/api-config.yaml
new file mode 100644
index 0000000..194e355
--- /dev/null
+++ b/step-1/templates/api/api-config.yaml
@@ -0,0 +1,14 @@
+{{- if .Values.api.enabled }}  
+  {{- $apiUrl := "" }}  
+  {{- if .Values.api.ingress.tlsEnabled }}  
+    {{- $apiUrl = printf "https://%s" .Values.api.ingress.host | quote }}  
+  {{- else }}  
+    {{- $apiUrl = printf "http://%s" .Values.api.ingress.host | quote }}  
+  {{- end }}  
+apiVersion: v1  
+kind: ConfigMap  
+metadata:  
+  name: {{ .Values.name }}-api  
+data:  
+  API_URL: {{ $apiUrl }}  
+{{- end }}api
\ No newline at end of file
diff --git a/step-1/templates/api/api-deployment.yaml b/step-1/templates/api/api-deployment.yaml
new file mode 100644
index 0000000..dce4c69
--- /dev/null
+++ b/step-1/templates/api/api-deployment.yaml
@@ -0,0 +1,83 @@
+{{- if .Values.api.enabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Values.name }}-api
+  labels:
+    app: api
+spec:
+  replicas: {{ .Values.api.replicaCount }}
+  selector:
+    matchLabels:
+      app: api
+  template:
+    metadata:
+      labels:
+        app: api
+    spec:
+      imagePullSecrets:
+        - name: takima-school-registry
+      securityContext:
+        runAsUser: 101
+        runAsGroup: 101
+
+      containers:
+      - name: api
+        image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag }}
+        imagePullPolicy: Always
+        ports:
+          - containerPort: 8080
+        resources:
+          requests:
+            memory: "32M"
+            cpu: "0.1"
+          limits:
+            memory: "128M"
+            cpu: "1"
+        startupProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          initialDelaySeconds: 3
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+        livenessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 3
+          successThreshold: 1
+          failureThreshold: 3
+        readinessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 3
+        securityContext:
+          allowPrivilegeEscalation: false
+        env:
+          - name: API_URL
+            valueFrom:
+              configMapKeyRef:
+                name: {{ .Values.name }}-api
+                key: API_URL
+          - name: DB_ENDPOINT
+            valueFrom:
+              configMapKeyRef:
+                name: {{ .Values.name }}-pg
+                key: DB_ENDPOINT
+          - name: POSTGRES_USER
+            valueFrom:
+              secretKeyRef:
+                name: {{ .Values.name }}-secret
+                key: POSTGRES_USER
+          - name: PG_PASSWORD
+            valueFrom:
+              secretKeyRef:
+                name: {{ .Values.name }}-secret
+                key: POSTGRES_PASSWORD
+
+{{- end }}
\ No newline at end of file
diff --git a/step-1/templates/api/api-ingress.yaml b/step-1/templates/api/api-ingress.yaml
new file mode 100644
index 0000000..58b8ed6
--- /dev/null
+++ b/step-1/templates/api/api-ingress.yaml
@@ -0,0 +1,26 @@
+{{- if .Values.api.enabled }}
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+   kubernetes.io/ingress.class: nginx
+ name: {{ .Values.name }}-api
+spec:
+  rules:
+  - host: {{ .Values.api.ingress.host }}
+    http:
+      paths:
+      - backend:
+          service:
+            name: {{ .Values.name }}-api
+            port:
+              number: 80
+        path: /
+        pathType: Prefix
+  {{- if .Values.api.ingress.tlsEnabled }}
+  tls:
+  - hosts:
+      - {{ .Values.api.ingress.host }}
+    secretName: app-wildcard
+  {{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/step-1/templates/api/api-service.yaml b/step-1/templates/api/api-service.yaml
new file mode 100644
index 0000000..78d141c
--- /dev/null
+++ b/step-1/templates/api/api-service.yaml
@@ -0,0 +1,13 @@
+{{- if .Values.api.enabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Values.name }}-api
+spec:
+  selector:
+    app: api
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
+{{- end }}
\ No newline at end of file
diff --git a/step-1/templates/db/pg-config.yaml b/step-1/templates/db/pg-config.yaml
new file mode 100644
index 0000000..e77e834
--- /dev/null
+++ b/step-1/templates/db/pg-config.yaml
@@ -0,0 +1,6 @@
+pgVersion: v1
+kind: ConfigMap  
+metadata:  
+  name: {{ .Values.name }}-pg
+data:
+  DB_ENDPOINT: {{ .Values.pg.endpoint }}
\ No newline at end of file
diff --git a/step-1/templates/db/pg-credentials.yaml b/step-1/templates/db/pg-credentials.yaml
new file mode 100644
index 0000000..32d88db
--- /dev/null
+++ b/step-1/templates/db/pg-credentials.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: {{ .Values.name }}-secret
+type: Opaque
+data:
+  POSTGRES_USER: dXNlcg==
+  POSTGRES_PASSWORD: dGVzdDEyMyo=
\ No newline at end of file
diff --git a/step-1/templates/db/pg-deployment.yaml b/step-1/templates/db/pg-deployment.yaml
new file mode 100644
index 0000000..862565c
--- /dev/null
+++ b/step-1/templates/db/pg-deployment.yaml
@@ -0,0 +1,34 @@
+{{- if .Values.pg.enabled }}
+pgVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Values.name }}-pg
+  labels:
+    app: pg
+spec:
+  replicas: {{ .Values.pg.replicaCount }}
+  selector:
+    matchLabels:
+      app: pg
+  template:
+    metadata:
+      labels:
+        app: pg
+    spec:
+      imagePullSecrets:
+        - name: takima-school-registry
+
+      containers:
+      - name: pg
+        image: {{ .Values.pg.image.repository }}:{{ .Values.pg.image.tag }}
+        imagePullPolicy: Always
+        ports:
+          - containerPort: 8080
+        
+        env: 
+          - name: API_URL
+            valueFrom:
+              configMapKeyRef:
+                name: {{ .Values.name }}-pg
+                key: API_URL
+{{- end }}
\ No newline at end of file
diff --git a/step-1/templates/db/pg-service.yaml b/step-1/templates/db/pg-service.yaml
new file mode 100644
index 0000000..f979cbb
--- /dev/null
+++ b/step-1/templates/db/pg-service.yaml
@@ -0,0 +1,13 @@
+{{- if .Values.pg.enabled }}
+pgVersion: v1
+kind: Service
+metadata:
+  name: {{ .Values.name }}-pg
+spec:
+  selector:
+    app: pg
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
+{{- end }}
\ No newline at end of file
diff --git a/step-1/templates/front/front-config.yaml b/step-1/templates/front/front-config.yaml
new file mode 100644
index 0000000..b1a9f30
--- /dev/null
+++ b/step-1/templates/front/front-config.yaml
@@ -0,0 +1,14 @@
+{{- if .Values.front.enabled }}  
+  {{- $apiUrl := "" }}  
+  {{- if .Values.api.ingress.tlsEnabled }}  
+    {{- $apiUrl = printf "https://%s" .Values.front.ingress.host | quote }}
+  {{- else }}  
+    {{- $apiUrl = printf "http://%s" .Values.front.ingress.host | quote }}
+  {{- end }}  
+apiVersion: v1  
+kind: ConfigMap  
+metadata:  
+  name: {{ .Values.name }}-front  
+data:  
+  API_URL: {{ $apiUrl }}  
+{{- end }}
\ No newline at end of file
diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-deployment.yaml b/step-1/templates/front/front-deployment.yaml
similarity index 100%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-deployment.yaml
rename to step-1/templates/front/front-deployment.yaml
diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-ingress.yaml b/step-1/templates/front/front-ingress.yaml
similarity index 100%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-ingress.yaml
rename to step-1/templates/front/front-ingress.yaml
diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-service.yaml b/step-1/templates/front/front-service.yaml
similarity index 100%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-service.yaml
rename to step-1/templates/front/front-service.yaml
diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/values.yaml b/step-1/values.yaml
similarity index 52%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/values.yaml
rename to step-1/values.yaml
index 9ab42ef..9aee2c0 100644
--- a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/values.yaml
+++ b/step-1/values.yaml
@@ -7,7 +7,12 @@ name: cdb
 api:
   ingress:
     tlsEnabled: false
-    host: api.to-replace.takima.school
+    host: computer-database-api.takima.school
+  replicaCount: 1
+  enabled: true
+  image:
+    repository: registry.gitlab.com/takima-school/images/cdb/api
+    tag: latest
 
 front:
   enabled: true
@@ -17,4 +22,12 @@ front:
   replicaCount: 1
   ingress:
     tlsEnabled: false
-    host: www.to-replace.takima.school
\ No newline at end of file
+    host: front.abourliatoux.takima.school
+
+pg:
+  enabled: true
+  image:
+    repository: postgres
+    tag: 13.3
+  replicaCount: 1
+  endpoint: cdb-service:5432
\ No newline at end of file
diff --git a/step-2-bonus/.gitignore b/step-2-bonus/.gitignore
new file mode 100644
index 0000000..7773828
--- /dev/null
+++ b/step-2-bonus/.gitignore
@@ -0,0 +1 @@
+dist/
\ No newline at end of file
diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/Chart.yaml b/step-2-bonus/Chart.yaml
similarity index 100%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/Chart.yaml
rename to step-2-bonus/Chart.yaml
diff --git a/step-2-bonus/templates/_helpers.tpl b/step-2-bonus/templates/_helpers.tpl
new file mode 100644
index 0000000..a5a0106
--- /dev/null
+++ b/step-2-bonus/templates/_helpers.tpl
@@ -0,0 +1,101 @@
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "AppCtx.chartName" -}}
+{{- default .Chart.Name | trunc 24 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "AppCtx.chartNameVersion" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 30 chars in order to leave room for suffixes (because some Kubernetes name fields are limited to 63 chars by the DNS naming spec).
+*/}}
+{{- define "AppCtx.name" }}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- printf "%s" $name | trunc 30 | trimSuffix "-"}}
+{{- end }}
+
+{{/*
+Create the API name
+*/}}
+{{- define "AppCtx.apiName" }}
+{{- printf "%s-api" (include "AppCtx.name" .) | trunc 63  }}
+{{- end }}
+
+{{/*
+Create the Front name
+*/}}
+{{- define "AppCtx.frontName" }}
+{{- printf "%s-front" (include "AppCtx.name" .) | trunc 63  }}
+{{- end }}
+
+{{/*
+Create the DB name
+*/}}
+{{- define "AppCtx.dbName" }}
+{{- printf "%s-db" (include "AppCtx.name" .) | trunc 63 }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "AppCtx.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "AppCtx.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "AppCtx.labels" -}}
+helm.sh/chart: {{ include "AppCtx.chartName" . }}
+{{ include "AppCtx.selectorLabels" . }}
+app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{- define "AppCtx.apiSelectorLabels" -}}
+{{ include "AppCtx.selectorLabels" . }}
+app.kubernetes.io/component: api
+{{- end }}
+
+{{- define "AppCtx.apiLabels" -}}
+{{ include "AppCtx.apiSelectorLabels" . }}
+app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+app/language: java
+app/version: {{ .Values.api.image.tag }}
+{{- end }}
+
+
+{{- define "AppCtx.frontSelectorLabels" -}}
+{{ include "AppCtx.selectorLabels" . }}
+app.kubernetes.io/component: front
+{{- end }}
+
+{{- define "AppCtx.frontLabels" -}}
+{{ include "AppCtx.frontSelectorLabels" . }}
+app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+app/language: javascript
+app/version: {{ .Values.front.image.tag }}
+{{- end }}
+
+{{- define "AppCtx.dbSelectorLabels" -}}
+{{ include "AppCtx.selectorLabels" . }}
+app.kubernetes.io/component: db
+{{- end }}
+
+{{- define "AppCtx.dbLabels" -}}
+{{ include "AppCtx.dbSelectorLabels" . }}
+app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+app/language: postgresql
+app/version: {{ .Values.db.image.tag }}
+{{- end }}
diff --git a/step-2-bonus/templates/api-config.yaml b/step-2-bonus/templates/api-config.yaml
new file mode 100644
index 0000000..39d56d6
--- /dev/null
+++ b/step-2-bonus/templates/api-config.yaml
@@ -0,0 +1,10 @@
+{{- if .Values.api.enabled }}  
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ template "AppCtx.apiName" . }}
+  labels: {{ include "AppCtx.apiLabels" . | nindent 4 }}
+data:
+  DB_ENDPOINT: "{{ template "AppCtx.dbName" . }}:5432"
+  DB_NAME: {{ .Values.db.name }}
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/api-deployment.yaml b/step-2-bonus/templates/api-deployment.yaml
new file mode 100644
index 0000000..baf0af5
--- /dev/null
+++ b/step-2-bonus/templates/api-deployment.yaml
@@ -0,0 +1,79 @@
+{{- if .Values.api.enabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ template "AppCtx.apiName" . }}
+  labels: {{ include "AppCtx.apiLabels" . | nindent 4 }}
+spec:
+  replicas: {{ .Values.api.replicaCount }}
+  selector:
+    matchLabels: {{ include "AppCtx.apiSelectorLabels" . | nindent 8 }}
+  template:
+    metadata:
+      labels: {{ include "AppCtx.apiLabels" . | nindent 10 }}
+      annotations:
+        checksum/config: {{ include (print $.Template.BasePath "/api-config.yaml") . | sha256sum }}
+    spec:
+      securityContext:
+        runAsUser: 1001
+        runAsGroup: 1001
+      imagePullSecrets:
+        - name: takima-school-registry
+      containers:
+      - name: api
+        image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag }}
+        resources:
+          requests:
+            memory: {{ .Values.api.requests.memory }}
+            cpu: {{ .Values.api.requests.cpu }}
+          limits:
+            memory: {{ .Values.api.limits.memory }}
+            cpu: {{ .Values.api.limits.cpu }}
+        startupProbe:
+          httpGet:
+            path: /actuator/health
+            port: 8080
+          initialDelaySeconds: {{ .Values.api.startupProbe.initialDelaySeconds }}
+          periodSeconds: {{ .Values.api.startupProbe.periodSeconds }}
+          successThreshold: 1
+          failureThreshold: {{ .Values.api.startupProbe.failureThreshold }}
+        livenessProbe:
+          httpGet:
+            path: /actuator/health/liveness
+            port: 8080
+          periodSeconds: 3
+          successThreshold: 1
+          failureThreshold: 3
+        readinessProbe:
+          httpGet:
+            path: /actuator/health/readiness
+            port: 8080
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 3        
+        securityContext:
+          allowPrivilegeEscalation: false
+        ports:
+        - containerPort: 8080
+        env: 
+          - name: DB_ENDPOINT
+            valueFrom:
+              configMapKeyRef:
+                name: {{ template "AppCtx.apiName" . }}
+                key: DB_ENDPOINT
+          - name: POSTGRES_DB
+            valueFrom:
+              configMapKeyRef:
+                name: {{ template "AppCtx.apiName" . }}
+                key: DB_NAME
+          - name: POSTGRES_USER
+            valueFrom:
+              secretKeyRef:
+                name: {{ template "AppCtx.dbName" . }}-credentials  # Nom du secret
+                key: pg_username     # nom de la clef dans le config map
+          - name: POSTGRES_PASSWORD
+            valueFrom:
+              secretKeyRef:
+                name: {{ template "AppCtx.dbName" . }}-credentials  # Nom du secret
+                key: pg_password 
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/api-ingress.yaml b/step-2-bonus/templates/api-ingress.yaml
new file mode 100644
index 0000000..1ccd700
--- /dev/null
+++ b/step-2-bonus/templates/api-ingress.yaml
@@ -0,0 +1,25 @@
+{{- if .Values.api.enabled }}
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+   kubernetes.io/ingress.class: nginx
+ name: {{ template "AppCtx.apiName" . }}
+ labels: {{ include "AppCtx.apiLabels" . | nindent 4 }}
+spec:
+  rules:
+  - host: {{ .Values.api.ingress.host }}
+    http:
+      paths:
+      - backend:
+          service:
+            name: {{ template "AppCtx.apiName" . }}
+            port:
+              number: 80
+        path: /
+        pathType: Prefix
+  tls:
+  - hosts:
+     - {{ .Values.api.ingress.host }}
+    secretName: app-wildcard
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/api-service.yaml b/step-2-bonus/templates/api-service.yaml
new file mode 100644
index 0000000..0f55be5
--- /dev/null
+++ b/step-2-bonus/templates/api-service.yaml
@@ -0,0 +1,13 @@
+{{- if .Values.api.enabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ template "AppCtx.apiName" . }}
+  labels: {{ include "AppCtx.apiLabels" . | nindent 8 }}
+spec:
+  selector: {{ include "AppCtx.apiSelectorLabels" . | nindent 4 }}
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
+{{- end }}
\ No newline at end of file
diff --git a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-config.yaml b/step-2-bonus/templates/front-config.yaml
similarity index 89%
rename from k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-config.yaml
rename to step-2-bonus/templates/front-config.yaml
index da89df7..5d5fd45 100644
--- a/k8s-trainees-main-boilerplate-day-3-step-1/boilerplate/day-3/step-1/templates/front-config.yaml
+++ b/step-2-bonus/templates/front-config.yaml
@@ -8,7 +8,7 @@
 apiVersion: v1  
 kind: ConfigMap  
 metadata:  
-  name: {{ .Values.name }}-front  
+  name: {{ template "AppCtx.frontName" . }}
 data:  
   API_URL: {{ $apiUrl }}  
 {{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/front-deployment.yaml b/step-2-bonus/templates/front-deployment.yaml
new file mode 100644
index 0000000..6e98e4b
--- /dev/null
+++ b/step-2-bonus/templates/front-deployment.yaml
@@ -0,0 +1,67 @@
+{{- if .Values.front.enabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ template "AppCtx.frontName" . }}
+  labels: {{ include "AppCtx.frontLabels" . | nindent 4 }}
+spec:
+  replicas: {{ .Values.front.replicaCount }}
+  selector:
+    matchLabels: {{ include "AppCtx.frontSelectorLabels" . | nindent 8 }}
+  template:
+    metadata:
+      labels: {{ include "AppCtx.frontLabels" . | nindent 10 }}
+      annotations:
+        checksum/config: {{ include (print $.Template.BasePath "/front-config.yaml") . | sha256sum }}
+    spec:
+      imagePullSecrets:
+        - name: takima-school-registry
+      securityContext:
+        runAsUser: 101
+        runAsGroup: 101
+
+      containers:
+      - name: front
+        image: {{ .Values.front.image.repository }}:{{ .Values.front.image.tag }}
+        imagePullPolicy: Always
+        ports:
+          - containerPort: 8080
+        resources:
+          requests:
+            memory: "32M"
+            cpu: "0.1"
+          limits:
+            memory: "128M"
+            cpu: "1"
+        startupProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          initialDelaySeconds: 3
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+        livenessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 3
+          successThreshold: 1
+          failureThreshold: 3
+        readinessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 3
+        securityContext:
+          allowPrivilegeEscalation: false
+        
+        env: 
+          - name: API_URL
+            valueFrom:
+              configMapKeyRef:
+                name: {{ template "AppCtx.frontName" . }}
+                key: API_URL
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/front-ingress.yaml b/step-2-bonus/templates/front-ingress.yaml
new file mode 100644
index 0000000..e0d9a44
--- /dev/null
+++ b/step-2-bonus/templates/front-ingress.yaml
@@ -0,0 +1,27 @@
+{{- if .Values.front.enabled }}
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+   kubernetes.io/ingress.class: nginx
+ name: {{ template "AppCtx.frontName" . }}
+ labels: {{ include "AppCtx.frontLabels" . | nindent 4 }}
+spec:
+  rules:
+  - host: {{ .Values.front.ingress.host }}
+    http:
+      paths:
+      - backend:
+          service:
+            name: {{ template "AppCtx.frontName" . }}
+            port:
+              number: 80
+        path: /
+        pathType: Prefix
+  {{- if .Values.front.ingress.tlsEnabled }}
+  tls:
+  - hosts:
+      - {{ .Values.front.ingress.host }}
+    secretName: app-wildcard
+  {{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/front-service.yaml b/step-2-bonus/templates/front-service.yaml
new file mode 100644
index 0000000..29c8200
--- /dev/null
+++ b/step-2-bonus/templates/front-service.yaml
@@ -0,0 +1,13 @@
+{{- if .Values.front.enabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ template "AppCtx.frontName" . }}
+  labels: {{ include "AppCtx.frontLabels" . | nindent 8 }}
+spec:
+  selector: {{ include "AppCtx.frontSelectorLabels" . | nindent 4 }}
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/pg-config.yaml b/step-2-bonus/templates/pg-config.yaml
new file mode 100644
index 0000000..9704903
--- /dev/null
+++ b/step-2-bonus/templates/pg-config.yaml
@@ -0,0 +1,10 @@
+{{- if .Values.db.enabled }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ template "AppCtx.dbName" . }}
+  labels: {{ include "AppCtx.dbLabels" . | nindent 4 }}
+data:
+  db_name: {{ .Values.db.name }}
+  db_path: "/var/lib/postgresql/data/pgdata"
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/pg-credentials.yaml b/step-2-bonus/templates/pg-credentials.yaml
new file mode 100644
index 0000000..69b2d6e
--- /dev/null
+++ b/step-2-bonus/templates/pg-credentials.yaml
@@ -0,0 +1,11 @@
+{{- if .Values.db.enabled }}
+apiVersion: v1
+kind: Secret
+metadata:
+  name: {{ template "AppCtx.dbName" . }}-credentials
+  labels: {{ include "AppCtx.dbLabels" . | nindent 4 }}
+type: Opaque
+data:
+  pg_username: YWRtaW4=   # user: admin
+  pg_password: dGVzdDEyMyo=  # pwd: test123*
+{{- end }}
\ No newline at end of file
diff --git a/step-2-bonus/templates/pg-deployment.yaml b/step-2-bonus/templates/pg-deployment.yaml
new file mode 100644
index 0000000..c4fd65a
--- /dev/null
+++ b/step-2-bonus/templates/pg-deployment.yaml
@@ -0,0 +1,52 @@
+{{- if .Values.db.enabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ template "AppCtx.dbName" . }}
+  labels: {{ include "AppCtx.dbLabels" . | nindent 4 }}
+spec:
+  replicas: 1
+  selector:
+    matchLabels: {{ include "AppCtx.dbSelectorLabels" . | nindent 8 }}
+  template:
+    metadata:
+      labels: {{ include "AppCtx.dbLabels" . | nindent 10 }}
+      annotations:
+        checksum/config: {{ include (print $.Template.BasePath "/front-config.yaml") . | sha256sum }}
+    spec:
+      containers:
+      - name: postgres
+        image: {{ .Values.db.image.repository }}:{{ .Values.db.image.tag }}
+        ports:
+        - containerPort: 80
+        env:
+          - name: POSTGRES_DB
+            valueFrom:
+              configMapKeyRef:
+                name: {{ template "AppCtx.dbName" . }}  # Nom du configmap
+                key: db_name     # nom de la clef dans le config map contenant le nom de la DB
+          - name: PGDATA
+            valueFrom:
+              configMapKeyRef:
+                name: {{ template "AppCtx.dbName" . }}  # Nom du configmap
+                key: db_path     # nom de la clef dans le configMap contenant path ou installer la db dans le volume persistant
+          - name: POSTGRES_USER
+            valueFrom:
+              secretKeyRef:
+                name: {{ template "AppCtx.dbName" . }}-credentials  # Nom du secret
+                key: pg_username     # nom de la clef dans le secret
+          - name: POSTGRES_PASSWORD
+            valueFrom:
+              secretKeyRef:
+                name: {{ template "AppCtx.dbName" . }}-credentials  # Nom du secret
+                key: pg_password     # nom de la clef dans le secret contenant le password
+        volumeMounts:
+        - mountPath: /var/lib/postgresql/data
+          name: pg-data
+      imagePullSecrets:
+      - name: takima-school-registry
+      volumes:
+      - name: pg-data
+        persistentVolumeClaim:
+          claimName: {{ template "AppCtx.dbName" . }}
+{{- end }}
diff --git a/step-2-bonus/templates/pg-pvc.yaml b/step-2-bonus/templates/pg-pvc.yaml
new file mode 100644
index 0000000..1ba7294
--- /dev/null
+++ b/step-2-bonus/templates/pg-pvc.yaml
@@ -0,0 +1,15 @@
+{{- if .Values.db.enabled }}
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: {{ template "AppCtx.dbName" . }}
+  labels: {{ include "AppCtx.dbLabels" . | nindent 4 }}
+spec:
+  accessModes:
+    - ReadWriteOnce
+  volumeMode: Filesystem
+  resources:
+    requests:
+      storage: {{ .Values.db.pvc.size }}
+  storageClassName: {{ .Values.db.pvc.storageClass }}
+{{- end }}
diff --git a/step-2-bonus/templates/pg-service.yaml b/step-2-bonus/templates/pg-service.yaml
new file mode 100644
index 0000000..547fd0c
--- /dev/null
+++ b/step-2-bonus/templates/pg-service.yaml
@@ -0,0 +1,12 @@
+{{- if .Values.db.enabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ template "AppCtx.dbName" . }}
+  labels: {{ include "AppCtx.dbLabels" . | nindent 4 }}
+spec:
+  selector: {{ include "AppCtx.dbSelectorLabels" . | nindent 4 }}
+  type: ClusterIP
+  ports:
+   - port: 5432
+{{- end}}
diff --git a/step-2-bonus/values.prod.yaml b/step-2-bonus/values.prod.yaml
new file mode 100644
index 0000000..f4a7a0b
--- /dev/null
+++ b/step-2-bonus/values.prod.yaml
@@ -0,0 +1,40 @@
+# Default values for CDB app.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+nameOverride: mycdb-prod
+
+api:
+  image:
+    tag: latest
+  replicaCount: 2
+  requests:
+    memory: "192M"
+    cpu: "0.2"
+  limits:
+    memory: "256M"
+    cpu: "1"
+  startupProbe:
+    initialDelaySeconds: 20
+    periodSeconds: 3
+    failureThreshold: 5
+  ingress:
+    tlsEnabled: true
+    host: api.replace-me.takima.school
+
+front:
+  image:
+    tag: latest
+  replicaCount: 1
+  ingress:
+    tlsEnabled: true
+    host: www.replace-me.takima.school
+
+db:
+  image:
+    tag: latest
+  pvc:
+    storageClass: gp2
+    size: 512Mi
+  credentials:
+    user: cdb
+    pwd: cdb123
\ No newline at end of file
diff --git a/step-2-bonus/values.staging.yaml b/step-2-bonus/values.staging.yaml
new file mode 100644
index 0000000..d67ee29
--- /dev/null
+++ b/step-2-bonus/values.staging.yaml
@@ -0,0 +1,40 @@
+# Default values for CDB app.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+nameOverride: mycdb-staging
+
+api:
+  image:
+    tag: latest
+  replicaCount: 1
+  requests:
+    memory: "128M"
+    cpu: "0.1"
+  limits:
+    memory: "256M"
+    cpu: "1"
+  startupProbe:
+    initialDelaySeconds: 20
+    periodSeconds: 3
+    failureThreshold: 5
+  ingress:
+    tlsEnabled: true
+    host: api-staging.to-replace.takima.school
+
+front:
+  image:
+    tag: latest
+  replicaCount: 1
+  ingress:
+    tlsEnabled: true
+    host: www-staging.to-replace.takima.school
+
+db:
+  image:
+    tag: latest
+  pvc:
+    storageClass: gp2
+    size: 512Mi
+  credentials:
+    user: cdb
+    pwd: cdb123
\ No newline at end of file
diff --git a/step-2-bonus/values.yaml b/step-2-bonus/values.yaml
new file mode 100644
index 0000000..3cd9bfd
--- /dev/null
+++ b/step-2-bonus/values.yaml
@@ -0,0 +1,48 @@
+# Default values for CDB app.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+nameOverride: mycdb
+
+api:
+  enabled: true
+  image:
+    repository: registry.gitlab.com/takima-school/images/cdb/api
+    tag: latest
+  replicaCount: 1
+  requests:
+    memory: "192M"
+    cpu: "0.2"
+  limits:
+    memory: "256M"
+    cpu: "1"
+  startupProbe:
+    initialDelaySeconds: 30
+    periodSeconds: 3
+    failureThreshold: 5
+  ingress:
+    tlsEnabled: false
+    host: api.to-replace.takima.school
+
+front:
+  enabled: true
+  image:
+    repository: registry.gitlab.com/takima-school/images/cdb/www
+    tag: latest
+  replicaCount: 1
+  ingress:
+    tlsEnabled: false
+    host: www.to-replace.takima.school
+
+db:
+  enabled: true
+  name: cdb-db
+  image:
+    repository: registry.takima.io/school/proxy/postgres
+    tag: latest
+  pvc:
+    storageClass: gp2
+    size: 512Mi
+  credentials:
+    user: cdb
+    pwd: cdb123
+
-- 
GitLab