From e61e7654dc862a6926c4d6b14265934fba24428b Mon Sep 17 00:00:00 2001 From: Magnus Andersson Date: Thu, 7 Nov 2024 10:59:04 +0100 Subject: [PATCH] Add postgres deployment for element --- k8s/postgres/postgres-deployment.yaml | 75 +++++++++++++++++++++++++++ k8s/postgres/postgres-namespace.yaml | 7 +++ k8s/postgres/postgres-pvc.yaml | 13 +++++ k8s/postgres/postgres-service.yaml | 14 +++++ 4 files changed, 109 insertions(+) create mode 100644 k8s/postgres/postgres-deployment.yaml create mode 100644 k8s/postgres/postgres-namespace.yaml create mode 100644 k8s/postgres/postgres-pvc.yaml create mode 100644 k8s/postgres/postgres-service.yaml diff --git a/k8s/postgres/postgres-deployment.yaml b/k8s/postgres/postgres-deployment.yaml new file mode 100644 index 0000000..63c88d1 --- /dev/null +++ b/k8s/postgres/postgres-deployment.yaml @@ -0,0 +1,75 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres + namespace: postgres + labels: + k8s-app: postgres +spec: + replicas: 1 + selector: + matchLabels: + k8s-app: postgres + template: + metadata: + labels: + k8s-app: postgres + spec: + containers: + - name: postgresql + image: postgres:17.0-bookworm + env: + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-secret + key: postgres-password + volumeMounts: + - name: postgres-data + mountPath: /var/lib/postgresql/data + - name: sharemem + mountPath: /dev/shm + ports: + - containerPort: 5432 + name: postgres + protocol: TCP + resources: + requests: + memory: "2Gi" + cpu: "500m" + limits: + memory: "4Gi" + cpu: "2000m" + livenessProbe: + exec: + command: + - /bin/bash + - -c + - exec pg_isready -U postgres -h 127.0.0.1 -p 5432 + failureThreshold: 6 + initialDelaySeconds: 20 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - /bin/bash + - -c + - exec pg_isready -U postgres -h 127.0.0.1 -p 5432 + failureThreshold: 6 + initialDelaySeconds: 20 + periodSeconds: 10 + successThreshold: 2 + timeoutSeconds: 5 + + volumes: + - name: postgres-data + persistentVolumeClaim: + claimName: postgres-pvc + readOnly: false + - emptyDir: + medium: Memory + sizeLimit: 1Gi + name: sharemem diff --git a/k8s/postgres/postgres-namespace.yaml b/k8s/postgres/postgres-namespace.yaml new file mode 100644 index 0000000..61badd5 --- /dev/null +++ b/k8s/postgres/postgres-namespace.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: postgres + labels: + usage: postgres-btsystem diff --git a/k8s/postgres/postgres-pvc.yaml b/k8s/postgres/postgres-pvc.yaml new file mode 100644 index 0000000..e2918f8 --- /dev/null +++ b/k8s/postgres/postgres-pvc.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres-pvc + namespace: postgres +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 20Gi + storageClassName: rook-cephfs diff --git a/k8s/postgres/postgres-service.yaml b/k8s/postgres/postgres-service.yaml new file mode 100644 index 0000000..05d3e50 --- /dev/null +++ b/k8s/postgres/postgres-service.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres + namespace: postgres +spec: + selector: + k8s-app: postgres + ports: + - name: postgres + protocol: TCP + port: 5432 + targetPort: 5432