68a158ca by Adam Heath

Add postgresql support, similar to mariadb(at this juncture).

1 parent 975ff536
1 apiVersion: kustomize.config.k8s.io/v1beta1
2 kind: Kustomization
3
4 resources:
5 - ./restore-from-empty.yaml
6
1 apiVersion: batch/v1
2 kind: Job
3 metadata:
4 name: postgresql-restore-from-empty
5 spec:
6 #replicas: 1
7 #progressDeadlineSeconds: 600
8 template:
9 spec:
10 restartPolicy: OnFailure
11 securityContext:
12 runAsUser: 0
13 runAsGroup: 0
14
15 volumes:
16 - name: postgresql-entrypoint-initdb
17 persistentVolumeClaim:
18 claimName: postgresql-entrypoint-initdb
19 - name: postgresql-scripts
20 configMap:
21 name: postgresql-scripts
22 defaultMode: 0755
23
24 containers:
25 - name: restore-from-empty
26 image: debian
27 command: ["/scripts/restore-from-empty"]
28 volumeMounts:
29 - name: postgresql-entrypoint-initdb
30 mountPath: /docker-entrypoint-initdb.d
31 - name: postgresql-scripts
32 mountPath: /scripts
33
1 ---
2 apiVersion: v1
3 kind: ConfigMap
4 metadata:
5 name: postgresql-config
6 data:
7 POSTGRESQL_DATABASE: ""
8 POSTGRESQL_USER: ""
9 ---
10 apiVersion: v1
11 kind: Secret
12 metadata:
13 name: postgresql-secret
14 stringData:
15 POSTGRESQL_PASSWORD: "CHANGEME"
16 POSTGRESQL_POSTGRES_PASSWORD: "CHANGEME"
17 ---
18 apiVersion: v1
19 kind: PersistentVolumeClaim
20 metadata:
21 name: postgresql-data
22 spec:
23 accessModes:
24 - ReadWriteOnce
25 resources:
26 requests:
27 storage: 10Gi
28 ---
29 apiVersion: v1
30 kind: PersistentVolumeClaim
31 metadata:
32 name: postgresql-entrypoint-initdb
33 spec:
34 accessModes:
35 - ReadWriteOnce
36 resources:
37 requests:
38 storage: 10Gi
39 ---
40
41
1 environments:
2 default:
3 values:
4 - namespace: postgresql
5 namePrefix: "test-"
6 restoreFromEmpty:
7 enabled: true
8 postgresqlServer:
9 jsonPatches: []
10 strategicMergePatches: []
11 postgresPassword: CHANGEME
12 password: CHANGEME
13 database: CHANGEME
14 user: CHANGEME
15 images:
16 debian: "debian:bullseye-20211220"
17 postgresql: "bitnami/postgresql:14.1.0-debian-10-r66"
18
19 releases:
20
21 - name: {{ .Values.namePrefix }}postgresql-restore-from-empty
22 namespace: {{ .Values.namespace }}
23 chart: charts/restore-from-empty
24 condition: restoreFromEmpty.enabled
25 values:
26 - set-common-values.yaml.gotmpl
27 strategicMergePatches:
28 - apiVersion: batch/v1
29 kind: Job
30 metadata:
31 name: {{ .Values.namePrefix }}postgresql-restore-from-empty
32 namespace: {{ .Values.namespace }}
33 spec:
34 template:
35 spec:
36 volumes:
37 - name: postgresql-entrypoint-initdb
38 persistentVolumeClaim:
39 claimName: {{ .Values.namePrefix }}postgresql-entrypoint-initdb
40 - name: postgresql-scripts
41 configMap:
42 name: {{ .Values.namePrefix }}postgresql-scripts
43
44 - name: {{ .Values.namePrefix }}postgresql-server
45 namespace: {{ .Values.namespace }}
46 chart: .
47 values:
48 - set-common-values.yaml.gotmpl
49 jsonPatches:
50 {{- if not (empty (.Values.postgresqlServer.jsonPatches)) }}
51 {{- .Values.postgresqlServer.jsonPatches | toYaml | indent 6 }}
52 {{- end }}
53 strategicMergePatches:
54 - apiVersion: apps/v1
55 kind: Deployment
56 metadata:
57 name: {{ .Values.namePrefix }}postgresql-server
58 namespace: {{ .Values.namespace }}
59 spec:
60 selector:
61 matchLabels:
62 app: {{ .Values.namePrefix }}postgresql-server
63 template:
64 metadata:
65 labels:
66 app: {{ .Values.namePrefix }}postgresql-server
67 spec:
68 volumes:
69 - name: postgresql-data
70 persistentVolumeClaim:
71 claimName: {{ .Values.namePrefix }}postgresql-data
72 - name: postgresql-config
73 configMap:
74 name: {{ .Values.namePrefix }}postgresql-config
75 - name: postgresql-scripts
76 configMap:
77 name: {{ .Values.namePrefix }}postgresql-scripts
78 - name: postgresql-secret
79 secret:
80 secretName: {{ .Values.namePrefix }}postgresql-secret
81 - apiVersion: v1
82 kind: Service
83 metadata:
84 name: {{ .Values.namePrefix }}postgresql
85 namespace: {{ .Values.namespace }}
86 spec:
87 selector:
88 app: {{ .Values.namePrefix }}postgresql-server
89 - apiVersion: v1
90 kind: ConfigMap
91 metadata:
92 name: {{ .Values.namePrefix }}postgresql-config
93 namespace: {{ .Values.namespace }}
94 data:
95 POSTGRESQL_DATABASE: {{ .Values.postgresqlServer.database }}
96 POSTGRESQL_USER: {{ .Values.postgresqlServer.user }}
97 - apiVersion: v1
98 kind: Secret
99 metadata:
100 name: {{ .Values.namePrefix }}postgresql-secret
101 namespace: {{ .Values.namespace }}
102 stringData:
103 POSTGRESQL_PASSWORD: {{ .Values.postgresqlServer.password }}
104 POSTGRESQL_POSTGRES_PASSWORD: {{ .Values.postgresqlServer.postgresPassword }}
105 {{- if not (empty (.Values.postgresqlServer.strategicMergePatches)) }}
106 {{- .Values.postgresqlServer.strategicMergePatches | toYaml | indent 6 }}
107 {{- end }}
108
1 apiVersion: kustomize.config.k8s.io/v1beta1
2 kind: Kustomization
3
4 resources:
5 - ./config.yaml
6 - ./postgresql-server.yaml
7
8 generatorOptions:
9 disableNameSuffixHash: true
10 configMapGenerator:
11 - name: postgresql-scripts
12 files:
13 - ./scripts/wait-for-file
14 - ./scripts/restore-from-empty
15 - ./scripts/bitnami-postgresql-entrypoint-container.sh
16 - ./scripts/bitnami-postgresql-entrypoint-initContainer.sh
17
1 ---
2 apiVersion: v1
3 kind: Service
4 metadata:
5 name: postgresql
6 spec:
7 selector:
8 app: postgresql-server
9 ports:
10 - name: mysql
11 protocol: TCP
12 port: 5432
13 targetPort: 5432
14 ---
15 apiVersion: apps/v1
16 kind: Deployment
17 metadata:
18 name: postgresql-server
19 labels:
20 app: postgresql-server
21 spec:
22 replicas: 1
23 progressDeadlineSeconds: 600
24 selector:
25 matchLabels:
26 app: postgresql-server
27 template:
28 metadata:
29 labels:
30 app: postgresql-server
31 spec:
32 restartPolicy: Always
33 securityContext:
34 runAsUser: 0
35 runAsGroup: 0
36
37 volumes:
38 - name: postgresql-data
39 persistentVolumeClaim:
40 claimName: postgresql-data
41 - name: postgresql-entrypoint-initdb
42 persistentVolumeClaim:
43 claimName: postgresql-entrypoint-initdb
44 - name: postgresql-scripts
45 configMap:
46 name: postgresql-scripts
47 defaultMode: 0755
48 - name: postgresql-config
49 configMap:
50 name: postgresql-config
51 - name: postgresql-secret
52 secret:
53 secretName: postgresql-secret
54 - name: database-restore
55 emptyDir: {}
56 - name: etc
57 emptyDir: {}
58
59 initContainers:
60 - name: wait-for-file
61 image: debian
62 command: ["/scripts/wait-for-file"]
63 volumeMounts:
64 - name: postgresql-entrypoint-initdb
65 mountPath: /docker-entrypoint-initdb.d
66 - name: postgresql-scripts
67 mountPath: /scripts
68 env:
69 - name: WAIT_FOR_FILE
70 value: /docker-entrypoint-initdb.d/.restored
71
72 - name: init-postgresql
73 image: postgresql
74 command: ["/var/scripts/bitnami-postgresql-entrypoint-initContainer.sh"]
75 volumeMounts:
76 - name: postgresql-scripts
77 mountPath: /var/scripts
78 - name: postgresql-data
79 mountPath: /bitnami/postgresql
80 - name: postgresql-config
81 mountPath: /var/postgresql-config
82 - name: postgresql-secret
83 mountPath: /var/postgresql-secret
84 - name: postgresql-entrypoint-initdb
85 mountPath: /docker-entrypoint-initdb.d
86 - name: etc
87 mountPath: /runtime-etc
88 env:
89 - name: POSTGRESQL_DATABASE_FILE
90 value: /var/postgresql-config/POSTGRESQL_DATABASE
91 - name: POSTGRESQL_USER_FILE
92 value: /var/postgresql-config/POSTGRESQL_USER
93 - name: POSTGRESQL_PASSWORD_FILE
94 value: /var/postgresql-secret/POSTGRESQL_PASSWORD
95 - name: POSTGRESQL_POSTGRES_PASSWORD_FILE
96 value: /var/postgresql-secret/POSTGRESQL_POSTGRES_PASSWORD
97
98 containers:
99 - name: postgresql
100 image: postgresql
101 #securityContext:
102 # runAsUser: 1001
103 # runAsGroup: 1001
104 command: ["/var/scripts/bitnami-postgresql-entrypoint-container.sh"]
105 args: ["/opt/bitnami/scripts/postgresql/run.sh"]
106 volumeMounts:
107 - name: postgresql-scripts
108 mountPath: /var/scripts
109 - name: postgresql-data
110 mountPath: /bitnami/postgresql
111 - name: etc
112 mountPath: /etc
113
1 #!/bin/bash
2
3 # shellcheck disable=SC1091
4
5 set -o errexit
6 set -o nounset
7 set -o pipefail
8 # set -o xtrace # Uncomment this line for debugging purposes
9
10 # Load libraries
11 . /opt/bitnami/scripts/libbitnami.sh
12 . /opt/bitnami/scripts/libpostgresql.sh
13
14 # Load MySQL environment variables
15 . /opt/bitnami/scripts/postgresql-env.sh
16
17 print_welcome_page
18
19 set -x
20 id
21 cat /etc/passwd
22 ls -la /bitnami/postgresql /bitnami/postgresql/data/ /opt/bitnami/postgresql/
23 chown -R $POSTGRESQL_DAEMON_USER:$POSTGRESQL_DAEMON_GROUP /opt/bitnami/postgresql/tmp /opt/bitnami/postgresql/logs
24 exec bash -x "$@"
1 #!/bin/bash
2
3 # shellcheck disable=SC1091
4
5 set -o errexit
6 set -o nounset
7 set -o pipefail
8 # set -o xtrace # Uncomment this line for debugging purposes
9
10 # Load libraries
11 . /opt/bitnami/scripts/libbitnami.sh
12 . /opt/bitnami/scripts/libpostgresql.sh
13
14 # Load MySQL environment variables
15 . /opt/bitnami/scripts/postgresql-env.sh
16
17 print_welcome_page
18
19 info "** Starting PostgresQL setup **"
20 /opt/bitnami/scripts/postgresql/setup.sh
21 info "** PostgresQL setup finished! **"
22 ls -la /bitnami/postgresql /bitnami/postgresql/data/ /opt/bitnami/postgresql/
23 cp -a /etc/* /runtime-etc/
24 cat /etc/passwd
1 #!/bin/sh
2
3 set -e
4
5 touch /docker-entrypoint-initdb.d/.restored
1 #!/usr/bin/env bash
2
3 set -ex
4 trap 'exit' TERM
5
6 while [[ ! -e $WAIT_FOR_FILE ]]; do
7 echo "Waiting for file: $WAIT_FOR_FILE" 1>&2
8 sleep 1
9 count=5
10 while [[ ! -e $WAIT_FOR_FILE && $count -gt 0 ]]; do
11 count=$(($count - 1))
12 sleep 1
13 done
14 done
15
1 namePrefix: {{ .Values.namePrefix }}
2 namespace: {{ .Values.namespace }}
3 images:
4 - name: debian
5 newName: {{ .Values.images.debian }}
6 - name: postgresql
7 newName: {{ .Values.images.postgresql }}
8