92 lines
3.4 KiB
YAML
92 lines
3.4 KiB
YAML
{{- if .Values.postgresql.enabled }}
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: {{ template "postgresql.fullname" . }}
|
|
labels:
|
|
{{- include "gitea.labels" . | nindent 4 }}
|
|
app.kubernetes.io/component: database
|
|
spec:
|
|
serviceName: {{ template "postgresql.serviceName" . }}
|
|
replicas: 1 # Un seul pod pour une base simple
|
|
selector:
|
|
matchLabels:
|
|
{{- include "postgresql.selectorLabels" . | nindent 6 }}
|
|
app.kubernetes.io/component: database
|
|
template:
|
|
metadata:
|
|
labels:
|
|
{{- include "postgresql.selectorLabels" . | nindent 8 }}
|
|
app.kubernetes.io/component: database
|
|
spec:
|
|
terminationGracePeriodSeconds: 10
|
|
containers:
|
|
- name: postgresql
|
|
image: "{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}"
|
|
imagePullPolicy: {{ .Values.postgresql.image.pullPolicy }}
|
|
ports:
|
|
- name: postgresql
|
|
containerPort: {{ .Values.postgresql.service.port }}
|
|
protocol: TCP
|
|
env:
|
|
- name: POSTGRES_DB
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: {{ template "postgresql.secretName" . }}
|
|
key: database
|
|
- name: POSTGRES_USER
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: {{ template "postgresql.secretName" . }}
|
|
key: username
|
|
- name: POSTGRES_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: {{ template "postgresql.secretName" . }}
|
|
key: password
|
|
# PGDATA est important pour indiquer où stocker les données
|
|
- name: PGDATA
|
|
value: {{ .Values.postgresql.persistence.mountPath }}/pgdata
|
|
{{- if .Values.postgresql.persistence.enabled }}
|
|
volumeMounts:
|
|
- name: postgresql-data
|
|
mountPath: {{ .Values.postgresql.persistence.mountPath }}
|
|
{{- end }}
|
|
# Ajouter des Liveness/Readiness Probes est recommandé en production
|
|
livenessProbe:
|
|
exec:
|
|
command: ["pg_isready", "-U", "$(POSTGRES_USER)", "-d", "$(POSTGRES_DB)", "-h", "127.0.0.1", "-p", "{{ .Values.postgresql.service.port }}"]
|
|
initialDelaySeconds: 30
|
|
periodSeconds: 10
|
|
timeoutSeconds: 5
|
|
failureThreshold: 6
|
|
readinessProbe:
|
|
exec:
|
|
command: ["pg_isready", "-U", "$(POSTGRES_USER)", "-d", "$(POSTGRES_DB)", "-h", "127.0.0.1", "-p", "{{ .Values.postgresql.service.port }}"]
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 10
|
|
timeoutSeconds: 5
|
|
failureThreshold: 6
|
|
{{- if not .Values.postgresql.persistence.enabled }}
|
|
volumes:
|
|
- name: postgresql-data # Volume éphémère si persistance désactivée
|
|
emptyDir: {}
|
|
{{- end }}
|
|
{{- if .Values.postgresql.persistence.enabled }}
|
|
volumeClaimTemplates:
|
|
- metadata:
|
|
name: postgresql-data
|
|
spec:
|
|
accessModes: [ "ReadWriteOnce" ]
|
|
resources:
|
|
requests:
|
|
storage: {{ .Values.postgresql.persistence.size }}
|
|
{{- if .Values.postgresql.persistence.storageClass }}
|
|
{{- if (eq "-" .Values.postgresql.persistence.storageClass) }}
|
|
storageClassName: ""
|
|
{{- else }}
|
|
storageClassName: "{{ .Values.postgresql.persistence.storageClass }}"
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }} |