From 2104fbea8bef2f39e60ecb346260bac8b6f7a2fb Mon Sep 17 00:00:00 2001
From: Florentin Labelle <florentin.labelle@student-cs.fr>
Date: Mon, 6 Jun 2022 12:17:00 +0200
Subject: [PATCH] Add solutions with secrets

---
 README.md                                     | 13 ++--
 solutions/3./3.3/deployment_back.yaml         |  2 +-
 solutions/3./3.4/deployment_back.yaml         | 59 +++++++++++++++++++
 solutions/3./3.4/secret.yaml                  | 10 ++++
 solutions/3./{3.4 => 3.5}/service_back.yaml   |  0
 solutions/3./{3.4 => 3.5}/service_front.yaml  |  0
 solutions/3./{3.5 => 3.6}/certificate.yaml    |  0
 .../3./{3.5 => 3.6}/ingressroute_back.yaml    |  0
 .../3./{3.5 => 3.6}/ingressroute_front.yaml   |  0
 solutions/3./{3.6 => 3.7}/vroum/Chart.yaml    |  0
 .../vroum/templates/certificate.yaml          |  0
 .../vroum/templates/deployment_back.yaml      | 20 +++++--
 .../vroum/templates/deployment_front.yaml     |  0
 .../vroum/templates/ingressroute_back.yaml    |  0
 .../vroum/templates/ingressroute_front.yaml   |  0
 solutions/3./3.7/vroum/templates/secret.yaml  | 10 ++++
 .../vroum/templates/service_back.yaml         |  0
 .../vroum/templates/service_front.yaml        |  0
 solutions/3./{3.6 => 3.7}/vroum/values.yaml   |  0
 19 files changed, 105 insertions(+), 9 deletions(-)
 create mode 100644 solutions/3./3.4/deployment_back.yaml
 create mode 100644 solutions/3./3.4/secret.yaml
 rename solutions/3./{3.4 => 3.5}/service_back.yaml (100%)
 rename solutions/3./{3.4 => 3.5}/service_front.yaml (100%)
 rename solutions/3./{3.5 => 3.6}/certificate.yaml (100%)
 rename solutions/3./{3.5 => 3.6}/ingressroute_back.yaml (100%)
 rename solutions/3./{3.5 => 3.6}/ingressroute_front.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/Chart.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/templates/certificate.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/templates/deployment_back.yaml (71%)
 rename solutions/3./{3.6 => 3.7}/vroum/templates/deployment_front.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/templates/ingressroute_back.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/templates/ingressroute_front.yaml (100%)
 create mode 100644 solutions/3./3.7/vroum/templates/secret.yaml
 rename solutions/3./{3.6 => 3.7}/vroum/templates/service_back.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/templates/service_front.yaml (100%)
 rename solutions/3./{3.6 => 3.7}/vroum/values.yaml (100%)

diff --git a/README.md b/README.md
index 6757456..711d1c5 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,12 @@ L'objectif est de déployer un site complexe par petits groupes de 2 ou 3 et d'e
 
 ## 0. Installer le nécessaire
 
-Il va falloir mettre en place quelque utilitaires de base pour pouvoir réaliser cette formation:
+Pour commencer tu peux cloner ce repo et ses dépendences:
+```bash
+git clone --recurse-submodules git@gitlab.viarezo.fr:ViaRezo/Kubernetes/formation-kubernetes
+``` 
+
+Il va ensuite falloir mettre en place quelque utilitaires de base pour pouvoir réaliser cette formation:
 
 - [`docker`](https://docs.docker.com/get-docker/)
 - [`kubectl`](https://kubernetes.io/docs/tasks/tools/#kubectl)
@@ -310,7 +315,7 @@ Un **secret** n'est en soit pas plus secret qu'une autre resource, il obéit sim
 
 Pensez bien à tester votre déploiement avec le **secret**.
 
-### 3.4 Service
+### 3.5 Service
 Un service est une entitée qui permet aux pods de communiquer entre eux au sein du cluster, Il s'occupe notamment du load balancing entre les différents réplicats des pods.
 Le template d'un service est le suivant :
 ``` yaml
@@ -330,7 +335,7 @@ Le **selector** est particulièrement important, il permet de _séléctionner_ l
 
 Le **targetPort** correspond au port que vous avez choisi d'exposer dans votre déploiement (le champs _containerPort_), et le **port** correspond au port sur lequel vous aimeriez bien joindre ce **service** (pour les service http c'est donc souvent 80).
 
-### 3.5 Exposer un service vers l'exterieur
+### 3.6 Exposer un service vers l'exterieur
 Avec notre service nous avons exposé notre app au sein du cluster. Maintenant nous allons l'exposer vers le moooooooonde. Pour cela nous allons mettre en place des Ingress. Un **Ingress** est un proxy qui en fonction du nom de domaine de la requête redirige vers le service adapté. Ici, à ViaRézo, nous utilisons des IngressRoutes gérés par l'**IngressController** Traefik. Traefik est un logiciel qui s'occupe de gérer toutes les routes décrites dans des **IngressRoutes**.  
 
 Pour les noms de domaine, il faut créer une entrée A sur le DNS qui redirige vers traefik. Cette partie a déja été faite pour vous, prenez juste un nom de domaine en ``.kube.test.viarezo.fr`` 
@@ -406,7 +411,7 @@ Vous pouvez le faire avec la commande suivante.
 kubeclt delete -f le_dossier_qui_contient_tous_mes_manifestes
 ```
 
-### 3.6 Helm le ansible de kubernetes
+### 3.7 Helm le ansible de kubernetes
 C'est bien sympatique tout ça mais si on veut changer le nom de l'application (vroum en vroum-vroum par exemple), il faut le changer à au moins une dizaine d'endroite et c'est loooong. Heureusement Helm est là pour nous aider à faire un peu de templating. 
 Helm permet de templatiser les fichiers kubernetes. Une application Helm s'appelle une chart. 
 Une chart s'organise comme suit: 
diff --git a/solutions/3./3.3/deployment_back.yaml b/solutions/3./3.3/deployment_back.yaml
index a9517e7..bdd5065 100644
--- a/solutions/3./3.3/deployment_back.yaml
+++ b/solutions/3./3.3/deployment_back.yaml
@@ -42,6 +42,6 @@ spec:
           - name: "DATABASE_PASSWORD"
             value: "password"
           - name: "DATABASE_HOST"
-            value: 10.244.1.19
+            value: <ip de mon pod mysql>
           - name: "SALT"
             value: "verylongstring"
diff --git a/solutions/3./3.4/deployment_back.yaml b/solutions/3./3.4/deployment_back.yaml
new file mode 100644
index 0000000..7b5b4ee
--- /dev/null
+++ b/solutions/3./3.4/deployment_back.yaml
@@ -0,0 +1,59 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: vroum-back
+spec:
+  selector:
+    matchLabels:
+      app: vroum
+      tier: backend
+  template:
+    metadata:
+      labels:
+        app: vroum
+        tier: backend
+    spec:
+      containers:
+        - name: main
+          image: registry.viarezo.fr/formation-kube/back:florentin
+          resources:
+            limits:
+              memory: "128Mi"
+              cpu: "500m"
+          ports:
+            - containerPort: 8000
+          env:
+            - name: "BACK_ROOT"
+              value: https://vroum.kube.test.viarezo.fr/api
+            - name: "FRONT_ROOT"
+              value: https://vroum.kube.test.viarezo.fr
+            - name: "CLIENT_ID"
+              valueFrom:
+                secretKeyRef:
+                  name: vroum-back
+                  key: client_id
+            - name: "CLIENT_SECRET"
+              valueFrom:
+                secretKeyRef:
+                  name: vroum-back
+                  key: client_secret
+            - name: "PRODUCTION"
+              value: "TRUE"
+            - name: "ALLOWED_HOSTS"
+              value: "vroum.kube.test.viarezo.fr"
+            - name: "DATABASE_NAME"
+              value: "vroum"
+            - name: "DATABASE_USER"
+              value: "vroum"
+            - name: "DATABASE_PASSWORD"
+              valueFrom:
+                secretKeyRef:
+                  name: vroum-back
+                  key: database_password
+            - name: "DATABASE_HOST"
+              value: <ip de mon pod mysql>
+            - name: "SALT"
+              valueFrom:
+                secretKeyRef:
+                  name: vroum-back
+                  key: salt
diff --git a/solutions/3./3.4/secret.yaml b/solutions/3./3.4/secret.yaml
new file mode 100644
index 0000000..37e6061
--- /dev/null
+++ b/solutions/3./3.4/secret.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: vroum-back
+type: Opaque
+data:
+  client_id: "client_id"
+  client_secret: "client_secret"
+  salt: "verylongstring"
+  database_password: "password"
diff --git a/solutions/3./3.4/service_back.yaml b/solutions/3./3.5/service_back.yaml
similarity index 100%
rename from solutions/3./3.4/service_back.yaml
rename to solutions/3./3.5/service_back.yaml
diff --git a/solutions/3./3.4/service_front.yaml b/solutions/3./3.5/service_front.yaml
similarity index 100%
rename from solutions/3./3.4/service_front.yaml
rename to solutions/3./3.5/service_front.yaml
diff --git a/solutions/3./3.5/certificate.yaml b/solutions/3./3.6/certificate.yaml
similarity index 100%
rename from solutions/3./3.5/certificate.yaml
rename to solutions/3./3.6/certificate.yaml
diff --git a/solutions/3./3.5/ingressroute_back.yaml b/solutions/3./3.6/ingressroute_back.yaml
similarity index 100%
rename from solutions/3./3.5/ingressroute_back.yaml
rename to solutions/3./3.6/ingressroute_back.yaml
diff --git a/solutions/3./3.5/ingressroute_front.yaml b/solutions/3./3.6/ingressroute_front.yaml
similarity index 100%
rename from solutions/3./3.5/ingressroute_front.yaml
rename to solutions/3./3.6/ingressroute_front.yaml
diff --git a/solutions/3./3.6/vroum/Chart.yaml b/solutions/3./3.7/vroum/Chart.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/Chart.yaml
rename to solutions/3./3.7/vroum/Chart.yaml
diff --git a/solutions/3./3.6/vroum/templates/certificate.yaml b/solutions/3./3.7/vroum/templates/certificate.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/templates/certificate.yaml
rename to solutions/3./3.7/vroum/templates/certificate.yaml
diff --git a/solutions/3./3.6/vroum/templates/deployment_back.yaml b/solutions/3./3.7/vroum/templates/deployment_back.yaml
similarity index 71%
rename from solutions/3./3.6/vroum/templates/deployment_back.yaml
rename to solutions/3./3.7/vroum/templates/deployment_back.yaml
index dedbfd8..15abffe 100644
--- a/solutions/3./3.6/vroum/templates/deployment_back.yaml
+++ b/solutions/3./3.7/vroum/templates/deployment_back.yaml
@@ -28,9 +28,15 @@ spec:
           - name: "FRONT_ROOT"
             value: https://{{ .Values.domain }}
           - name: "CLIENT_ID"
-            value: client_id
+            valueFrom:
+              secretKeyRef:
+                name: vroum-back
+                key: client_id
           - name: "CLIENT_SECRET"
-            value: client_secret
+            valueFrom:
+              secretKeyRef:
+                name: vroum-back
+                key: client_secret
           - name: "PRODUCTION"
             value: "TRUE"
           - name: "ALLOWED_HOSTS"
@@ -40,8 +46,14 @@ spec:
           - name: "DATABASE_USER"
             value: {{ .Values.mysql.user }}
           - name: "DATABASE_PASSWORD"
-            value: {{ .Values.mysql.password }}
+            valueFrom:
+              secretKeyRef:
+                name: vroum-back
+                key: database_password
           - name: "DATABASE_HOST"
             value: {{ .Values.mysql.host }}
           - name: "SALT"
-            value: "verylongstring"
+            valueFrom:
+              secretKeyRef:
+                name: vroum-back
+                key: salt
diff --git a/solutions/3./3.6/vroum/templates/deployment_front.yaml b/solutions/3./3.7/vroum/templates/deployment_front.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/templates/deployment_front.yaml
rename to solutions/3./3.7/vroum/templates/deployment_front.yaml
diff --git a/solutions/3./3.6/vroum/templates/ingressroute_back.yaml b/solutions/3./3.7/vroum/templates/ingressroute_back.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/templates/ingressroute_back.yaml
rename to solutions/3./3.7/vroum/templates/ingressroute_back.yaml
diff --git a/solutions/3./3.6/vroum/templates/ingressroute_front.yaml b/solutions/3./3.7/vroum/templates/ingressroute_front.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/templates/ingressroute_front.yaml
rename to solutions/3./3.7/vroum/templates/ingressroute_front.yaml
diff --git a/solutions/3./3.7/vroum/templates/secret.yaml b/solutions/3./3.7/vroum/templates/secret.yaml
new file mode 100644
index 0000000..a18d6ce
--- /dev/null
+++ b/solutions/3./3.7/vroum/templates/secret.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: {{ .Chart.Name }}-back
+type: Opaque
+data:
+  client_id: "client_id"
+  client_secret: "client_secret"
+  salt: "verylongstring"
+  database_password: "password"
diff --git a/solutions/3./3.6/vroum/templates/service_back.yaml b/solutions/3./3.7/vroum/templates/service_back.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/templates/service_back.yaml
rename to solutions/3./3.7/vroum/templates/service_back.yaml
diff --git a/solutions/3./3.6/vroum/templates/service_front.yaml b/solutions/3./3.7/vroum/templates/service_front.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/templates/service_front.yaml
rename to solutions/3./3.7/vroum/templates/service_front.yaml
diff --git a/solutions/3./3.6/vroum/values.yaml b/solutions/3./3.7/vroum/values.yaml
similarity index 100%
rename from solutions/3./3.6/vroum/values.yaml
rename to solutions/3./3.7/vroum/values.yaml
-- 
GitLab