Skip to content

Instantly share code, notes, and snippets.

@MikaelSmith
Created July 29, 2020 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikaelSmith/98683d0edaec750ffaa21bbda5cb0cf8 to your computer and use it in GitHub Desktop.
Save MikaelSmith/98683d0edaec750ffaa21bbda5cb0cf8 to your computer and use it in GitHub Desktop.
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app.kubernetes.io/name: cd4pe-postgres
name: postgres
namespace: cd4pe
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: cd4pe-postgres
serviceName: postgres
template:
metadata:
labels:
app.kubernetes.io/name: cd4pe-postgres
spec:
containers:
- env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: cd4pe-postgres
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
key: user
name: cd4pe-postgres
- name: PGDATA
value: /var/lib/postgresql/data/pgdata11
image: postgres:11.7-alpine
lifecycle:
preStop:
exec:
command:
- /bin/kill
- -INT
- "1"
name: postgres
ports:
- containerPort: 5432
name: postgres
protocol: TCP
resources:
limits:
cpu: "4"
memory: 2Gi
requests:
cpu: 250m
memory: 64Mi
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: data
hostname: postgres
initContainers:
- name: pg-upgrade
image: tianon/postgres-upgrade:9.6-to-11
env:
- name: PGDATAOLD
value: /var/lib/postgresql/data/pgdata
- name: PGDATANEW
value: /var/lib/postgresql/data/pgdata11
- name: PGUSER
valueFrom:
secretKeyRef:
key: user
name: cd4pe-postgres
- name: POSTGRES_INITDB_ARGS
value: --username=$(cat /var/lib/postgresql/creds/user) --pwfile=/var/lib/postgresql/creds/password
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: data
- mountPath: /var/lib/postgresql/creds
name: creds
readOnly: true
- name: pg-hba
image: postgres:11.7-alpine
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: data
command: ['cp', '/var/lib/postgresql/data/pgdata/pg_hba.conf', '/var/lib/postgresql/data/pgdata11/pg_hba.conf']
terminationGracePeriodSeconds: 60
volumes:
- name: creds
secret:
secretName: cd4pe-postgres
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment