templates/statefulset-primary.yaml を追加

This commit is contained in:
2026-02-07 00:20:11 +00:00
parent 2533feda92
commit 0c9e478850

View File

@@ -0,0 +1,96 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "postgresql.fullname" . }}-primary
labels:
{{- include "postgresql.labels" . | nindent 4 }}
app.kubernetes.io/component: primary
spec:
serviceName: {{ include "postgresql.fullname" . }}-headless
replicas: 1
selector:
matchLabels:
{{- include "postgresql.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: primary
template:
metadata:
labels:
{{- include "postgresql.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: primary
spec:
containers:
- name: postgresql
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: postgres
containerPort: 5432
protocol: TCP
env:
- name: POSTGRES_DB
value: {{ .Values.postgres.database | quote }}
- name: POSTGRES_USER
value: {{ .Values.postgres.user | quote }}
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.postgres.existingSecret | default (include "postgresql.fullname" .) }}
key: {{ .Values.postgres.passwordKey }}
{{- if .Values.replication.enabled }}
- name: REPLICATION_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.postgres.existingSecret | default (include "postgresql.fullname" .) }}
key: {{ .Values.postgres.replicationPasswordKey }}
{{- end }}
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
{{- if .Values.replication.enabled }}
- name: config
mountPath: /docker-entrypoint-initdb.d/primary-init.sh
subPath: primary-init.sh
{{- end }}
livenessProbe:
exec:
command:
- /bin/sh
- -c
- pg_isready -U {{ .Values.postgres.user }}
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
readinessProbe:
exec:
command:
- /bin/sh
- -c
- pg_isready -U {{ .Values.postgres.user }}
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
resources:
{{- toYaml .Values.primary.resources | nindent 10 }}
volumes:
{{- if .Values.replication.enabled }}
- name: config
configMap:
name: {{ include "postgresql.fullname" . }}-config
defaultMode: 0755
{{- end }}
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- {{ .Values.primary.persistence.accessMode }}
resources:
requests:
storage: {{ .Values.primary.persistence.size }}
{{- if .Values.primary.persistence.storageClass }}
storageClassName: {{ .Values.primary.persistence.storageClass }}
{{- end }}