{{- if .Values.postgres.enabled }} apiVersion: v1 kind: Service metadata: name: {{ include "lab.postgresHost" . }} namespace: {{ include "lab.namespace" . }} labels: {{- include "lab.labels" . | nindent 4 }} app.kubernetes.io/component: postgres spec: type: ClusterIP ports: - name: postgres port: 5432 targetPort: postgres protocol: TCP selector: {{- include "lab.selectorLabels" . | nindent 4 }} app.kubernetes.io/component: postgres --- apiVersion: apps/v1 kind: StatefulSet metadata: name: {{ include "lab.postgresHost" . }} namespace: {{ include "lab.namespace" . }} labels: {{- include "lab.labels" . | nindent 4 }} app.kubernetes.io/component: postgres spec: serviceName: {{ include "lab.postgresHost" . }} replicas: 1 selector: matchLabels: {{- include "lab.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: postgres template: metadata: labels: {{- include "lab.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: postgres spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} containers: - name: postgres image: "{{ .Values.postgres.image.repository }}:{{ .Values.postgres.image.tag }}" imagePullPolicy: {{ .Values.postgres.image.pullPolicy }} ports: - name: postgres containerPort: 5432 protocol: TCP env: - name: POSTGRES_USER value: {{ .Values.postgres.auth.username | quote }} - name: POSTGRES_DB value: {{ .Values.postgres.auth.database | quote }} - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: name: {{ include "lab.fullname" . }} key: postgres-password - name: PGDATA value: /var/lib/postgresql/data/pgdata volumeMounts: - name: data mountPath: /var/lib/postgresql/data - name: init mountPath: /docker-entrypoint-initdb.d readOnly: true readinessProbe: exec: command: ["pg_isready", "-U", {{ .Values.postgres.auth.username | quote }}, "-d", {{ .Values.postgres.auth.database | quote }}] initialDelaySeconds: 5 periodSeconds: 5 timeoutSeconds: 3 failureThreshold: 12 livenessProbe: exec: command: ["pg_isready", "-U", {{ .Values.postgres.auth.username | quote }}, "-d", {{ .Values.postgres.auth.database | quote }}] initialDelaySeconds: 15 periodSeconds: 10 timeoutSeconds: 3 {{- with .Values.postgres.resources }} resources: {{- toYaml . | nindent 12 }} {{- end }} volumes: - name: init configMap: name: {{ include "lab.fullname" . }}-postgres-init {{- if not .Values.postgres.persistence.enabled }} - name: data emptyDir: {} {{- end }} {{- if .Values.postgres.persistence.enabled }} volumeClaimTemplates: - metadata: name: data spec: accessModes: ["ReadWriteOnce"] {{- if .Values.postgres.persistence.storageClass }} storageClassName: {{ .Values.postgres.persistence.storageClass | quote }} {{- end }} resources: requests: storage: {{ .Values.postgres.persistence.size }} {{- end }} {{- end }}