From 73c1c9ae8065c6a47a46beb85981ac38005fb4e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20S=C3=A9journ=C3=A9?= <asejourne@takima.fr>
Date: Wed, 2 Aug 2023 11:58:27 +0200
Subject: [PATCH] =?UTF-8?q?reprise=20des=20yml=20pr=C3=A9c=C3=A9dents?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 api/api-config.yml                            |  6 ++
 api/api-deployment.yml                        | 50 ++++++++++++++++
 api/api-ingress.yml                           | 18 ++++++
 api/api-service.yml                           | 11 ++++
 pg-operator/operator.yml                      | 17 ++++++
 pg/database-service.yml                       | 11 ++++
 pg/database-stateful-set.yml                  | 60 +++++++++++++++++++
 pg/pg-config.yml                              |  7 +++
 pg/pg-credentials.yml                         |  8 +++
 pg/pg-pvc.yml                                 | 12 ++++
 .../{front-config.yaml => front-config.yml}   |  0
 ...t-deployment.yaml => front-deployment.yml} |  0
 .../{front-ingress.yaml => front-ingress.yml} |  0
 .../{front-service.yaml => front-service.yml} |  0
 14 files changed, 200 insertions(+)
 create mode 100644 api/api-config.yml
 create mode 100644 api/api-deployment.yml
 create mode 100644 api/api-ingress.yml
 create mode 100644 api/api-service.yml
 create mode 100644 pg-operator/operator.yml
 create mode 100644 pg/database-service.yml
 create mode 100644 pg/database-stateful-set.yml
 create mode 100644 pg/pg-config.yml
 create mode 100644 pg/pg-credentials.yml
 create mode 100644 pg/pg-pvc.yml
 rename templates/{front-config.yaml => front-config.yml} (100%)
 rename templates/{front-deployment.yaml => front-deployment.yml} (100%)
 rename templates/{front-ingress.yaml => front-ingress.yml} (100%)
 rename templates/{front-service.yaml => front-service.yml} (100%)

diff --git a/api/api-config.yml b/api/api-config.yml
new file mode 100644
index 0000000..ad003a7
--- /dev/null
+++ b/api/api-config.yml
@@ -0,0 +1,6 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: api-config
+data:
+  endpoint: database-service:5432
diff --git a/api/api-deployment.yml b/api/api-deployment.yml
new file mode 100644
index 0000000..a6a45d8
--- /dev/null
+++ b/api/api-deployment.yml
@@ -0,0 +1,50 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  labels:
+    app: api-deployment
+  name: api-deployment
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: api-deployment
+  strategy: {}
+  template:
+    metadata:
+      labels:
+        app: api-deployment
+    spec:
+      containers:
+        - image: registry.gitlab.com/takima-school/images/cdb/api:latest
+          name: simple-app
+          resources: 
+            limits:
+              memory: "720Mi"
+              cpu: "390m"
+          ports:
+            - containerPort: 8080
+          env:
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: database-config
+                  key: name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: db-secret
+                  key: user
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: db-secret
+                  key: password
+            - name: DB_ENDPOINT
+              valueFrom:
+                configMapKeyRef:
+                  name: api-config
+                  key: endpoint
+      imagePullSecrets:
+        - name: takima-school-registry
+status: {}
diff --git a/api/api-ingress.yml b/api/api-ingress.yml
new file mode 100644
index 0000000..3ff7ab1
--- /dev/null
+++ b/api/api-ingress.yml
@@ -0,0 +1,18 @@
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: nginx
+  name: api-ingress
+spec:
+  rules:
+    - host: api.asejourne.takima.school
+      http:
+        paths:
+          - backend:
+              service:
+                name: api-service
+                port:
+                  number: 80
+            path: /
+            pathType: Prefix
diff --git a/api/api-service.yml b/api/api-service.yml
new file mode 100644
index 0000000..3b52a4a
--- /dev/null
+++ b/api/api-service.yml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: api-service
+spec:
+  selector:
+    app: api-deployment
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
diff --git a/pg-operator/operator.yml b/pg-operator/operator.yml
new file mode 100644
index 0000000..593b428
--- /dev/null
+++ b/pg-operator/operator.yml
@@ -0,0 +1,17 @@
+apiVersion: "acid.zalan.do/v1"
+kind: postgresql
+metadata:
+  name: formation-cdb
+spec:
+  teamId: "formation"  # le team id doit matcher le préfixe dans le metadata.name, ici formation
+  volume:
+    size: 1Gi
+  numberOfInstances: 2
+  users:
+    cdb:  # database owner
+      - superuser
+      - createdb
+  databases:
+    cdb: cdb  # dbname: owner
+  postgresql:
+    version: "14"
diff --git a/pg/database-service.yml b/pg/database-service.yml
new file mode 100644
index 0000000..7d4b35c
--- /dev/null
+++ b/pg/database-service.yml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: database-service
+spec:
+  selector:
+    app: database-deployment
+  ports:
+    - protocol: TCP
+      port: 5432
+      targetPort: 5432
diff --git a/pg/database-stateful-set.yml b/pg/database-stateful-set.yml
new file mode 100644
index 0000000..d0ae1e4
--- /dev/null
+++ b/pg/database-stateful-set.yml
@@ -0,0 +1,60 @@
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  labels:
+    app: database-deployment
+  name: database-deployment
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: database-deployment
+  serviceName: database-service
+  template:
+    metadata:
+      labels:
+        app: database-deployment
+    spec:
+      containers:
+        - image: registry.takima.io/school/proxy/postgres:latest
+          volumeMounts:
+          - mountPath: /var/lib/postgresql/data
+            name: pg-data
+          name: simple-database
+          resources: 
+            limits:
+              memory: "512Mi"
+              cpu: "390m"
+          ports:
+            - containerPort: 5432
+          env:
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: database-config
+                  key: name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: db-secret
+                  key: user
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: db-secret
+                  key: password
+            - name: PGDATA
+              valueFrom:
+                configMapKeyRef:
+                  name: database-config
+                  key: db_path
+      imagePullSecrets:
+        - name: takima-school-registry
+  volumeClaimTemplates:
+  - metadata:
+      name: pg-data
+    spec:
+      accessModes: [ "ReadWriteOnce" ]
+      resources:
+        requests:
+          storage: 1Gi
diff --git a/pg/pg-config.yml b/pg/pg-config.yml
new file mode 100644
index 0000000..d5274fb
--- /dev/null
+++ b/pg/pg-config.yml
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: database-config
+data:
+  name: "cdb-db"
+  db_path: "/var/lib/postgresql/data/pgdata"
diff --git a/pg/pg-credentials.yml b/pg/pg-credentials.yml
new file mode 100644
index 0000000..642c1b0
--- /dev/null
+++ b/pg/pg-credentials.yml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: db-secret
+type: Opaque
+data:
+  user: ZGItdXNlcg==
+  password: ZGItcGFzc3dvcmQ=
\ No newline at end of file
diff --git a/pg/pg-pvc.yml b/pg/pg-pvc.yml
new file mode 100644
index 0000000..acc28fc
--- /dev/null
+++ b/pg/pg-pvc.yml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: pg-db
+spec:
+  storageClassName: gp2
+  accessModes:
+  - ReadWriteOnce
+  volumeMode: Filesystem
+  resources:
+    requests:
+      storage: 3Gi
\ No newline at end of file
diff --git a/templates/front-config.yaml b/templates/front-config.yml
similarity index 100%
rename from templates/front-config.yaml
rename to templates/front-config.yml
diff --git a/templates/front-deployment.yaml b/templates/front-deployment.yml
similarity index 100%
rename from templates/front-deployment.yaml
rename to templates/front-deployment.yml
diff --git a/templates/front-ingress.yaml b/templates/front-ingress.yml
similarity index 100%
rename from templates/front-ingress.yaml
rename to templates/front-ingress.yml
diff --git a/templates/front-service.yaml b/templates/front-service.yml
similarity index 100%
rename from templates/front-service.yaml
rename to templates/front-service.yml
-- 
GitLab