68a158ca by Adam Heath

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

1 parent 975ff536
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./restore-from-empty.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: postgresql-restore-from-empty
spec:
#replicas: 1
#progressDeadlineSeconds: 600
template:
spec:
restartPolicy: OnFailure
securityContext:
runAsUser: 0
runAsGroup: 0
volumes:
- name: postgresql-entrypoint-initdb
persistentVolumeClaim:
claimName: postgresql-entrypoint-initdb
- name: postgresql-scripts
configMap:
name: postgresql-scripts
defaultMode: 0755
containers:
- name: restore-from-empty
image: debian
command: ["/scripts/restore-from-empty"]
volumeMounts:
- name: postgresql-entrypoint-initdb
mountPath: /docker-entrypoint-initdb.d
- name: postgresql-scripts
mountPath: /scripts
---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgresql-config
data:
POSTGRESQL_DATABASE: ""
POSTGRESQL_USER: ""
---
apiVersion: v1
kind: Secret
metadata:
name: postgresql-secret
stringData:
POSTGRESQL_PASSWORD: "CHANGEME"
POSTGRESQL_POSTGRES_PASSWORD: "CHANGEME"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgresql-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgresql-entrypoint-initdb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
environments:
default:
values:
- namespace: postgresql
namePrefix: "test-"
restoreFromEmpty:
enabled: true
postgresqlServer:
jsonPatches: []
strategicMergePatches: []
postgresPassword: CHANGEME
password: CHANGEME
database: CHANGEME
user: CHANGEME
images:
debian: "debian:bullseye-20211220"
postgresql: "bitnami/postgresql:14.1.0-debian-10-r66"
releases:
- name: {{ .Values.namePrefix }}postgresql-restore-from-empty
namespace: {{ .Values.namespace }}
chart: charts/restore-from-empty
condition: restoreFromEmpty.enabled
values:
- set-common-values.yaml.gotmpl
strategicMergePatches:
- apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.namePrefix }}postgresql-restore-from-empty
namespace: {{ .Values.namespace }}
spec:
template:
spec:
volumes:
- name: postgresql-entrypoint-initdb
persistentVolumeClaim:
claimName: {{ .Values.namePrefix }}postgresql-entrypoint-initdb
- name: postgresql-scripts
configMap:
name: {{ .Values.namePrefix }}postgresql-scripts
- name: {{ .Values.namePrefix }}postgresql-server
namespace: {{ .Values.namespace }}
chart: .
values:
- set-common-values.yaml.gotmpl
jsonPatches:
{{- if not (empty (.Values.postgresqlServer.jsonPatches)) }}
{{- .Values.postgresqlServer.jsonPatches | toYaml | indent 6 }}
{{- end }}
strategicMergePatches:
- apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.namePrefix }}postgresql-server
namespace: {{ .Values.namespace }}
spec:
selector:
matchLabels:
app: {{ .Values.namePrefix }}postgresql-server
template:
metadata:
labels:
app: {{ .Values.namePrefix }}postgresql-server
spec:
volumes:
- name: postgresql-data
persistentVolumeClaim:
claimName: {{ .Values.namePrefix }}postgresql-data
- name: postgresql-config
configMap:
name: {{ .Values.namePrefix }}postgresql-config
- name: postgresql-scripts
configMap:
name: {{ .Values.namePrefix }}postgresql-scripts
- name: postgresql-secret
secret:
secretName: {{ .Values.namePrefix }}postgresql-secret
- apiVersion: v1
kind: Service
metadata:
name: {{ .Values.namePrefix }}postgresql
namespace: {{ .Values.namespace }}
spec:
selector:
app: {{ .Values.namePrefix }}postgresql-server
- apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.namePrefix }}postgresql-config
namespace: {{ .Values.namespace }}
data:
POSTGRESQL_DATABASE: {{ .Values.postgresqlServer.database }}
POSTGRESQL_USER: {{ .Values.postgresqlServer.user }}
- apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.namePrefix }}postgresql-secret
namespace: {{ .Values.namespace }}
stringData:
POSTGRESQL_PASSWORD: {{ .Values.postgresqlServer.password }}
POSTGRESQL_POSTGRES_PASSWORD: {{ .Values.postgresqlServer.postgresPassword }}
{{- if not (empty (.Values.postgresqlServer.strategicMergePatches)) }}
{{- .Values.postgresqlServer.strategicMergePatches | toYaml | indent 6 }}
{{- end }}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./config.yaml
- ./postgresql-server.yaml
generatorOptions:
disableNameSuffixHash: true
configMapGenerator:
- name: postgresql-scripts
files:
- ./scripts/wait-for-file
- ./scripts/restore-from-empty
- ./scripts/bitnami-postgresql-entrypoint-container.sh
- ./scripts/bitnami-postgresql-entrypoint-initContainer.sh
---
apiVersion: v1
kind: Service
metadata:
name: postgresql
spec:
selector:
app: postgresql-server
ports:
- name: mysql
protocol: TCP
port: 5432
targetPort: 5432
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgresql-server
labels:
app: postgresql-server
spec:
replicas: 1
progressDeadlineSeconds: 600
selector:
matchLabels:
app: postgresql-server
template:
metadata:
labels:
app: postgresql-server
spec:
restartPolicy: Always
securityContext:
runAsUser: 0
runAsGroup: 0
volumes:
- name: postgresql-data
persistentVolumeClaim:
claimName: postgresql-data
- name: postgresql-entrypoint-initdb
persistentVolumeClaim:
claimName: postgresql-entrypoint-initdb
- name: postgresql-scripts
configMap:
name: postgresql-scripts
defaultMode: 0755
- name: postgresql-config
configMap:
name: postgresql-config
- name: postgresql-secret
secret:
secretName: postgresql-secret
- name: database-restore
emptyDir: {}
- name: etc
emptyDir: {}
initContainers:
- name: wait-for-file
image: debian
command: ["/scripts/wait-for-file"]
volumeMounts:
- name: postgresql-entrypoint-initdb
mountPath: /docker-entrypoint-initdb.d
- name: postgresql-scripts
mountPath: /scripts
env:
- name: WAIT_FOR_FILE
value: /docker-entrypoint-initdb.d/.restored
- name: init-postgresql
image: postgresql
command: ["/var/scripts/bitnami-postgresql-entrypoint-initContainer.sh"]
volumeMounts:
- name: postgresql-scripts
mountPath: /var/scripts
- name: postgresql-data
mountPath: /bitnami/postgresql
- name: postgresql-config
mountPath: /var/postgresql-config
- name: postgresql-secret
mountPath: /var/postgresql-secret
- name: postgresql-entrypoint-initdb
mountPath: /docker-entrypoint-initdb.d
- name: etc
mountPath: /runtime-etc
env:
- name: POSTGRESQL_DATABASE_FILE
value: /var/postgresql-config/POSTGRESQL_DATABASE
- name: POSTGRESQL_USER_FILE
value: /var/postgresql-config/POSTGRESQL_USER
- name: POSTGRESQL_PASSWORD_FILE
value: /var/postgresql-secret/POSTGRESQL_PASSWORD
- name: POSTGRESQL_POSTGRES_PASSWORD_FILE
value: /var/postgresql-secret/POSTGRESQL_POSTGRES_PASSWORD
containers:
- name: postgresql
image: postgresql
#securityContext:
# runAsUser: 1001
# runAsGroup: 1001
command: ["/var/scripts/bitnami-postgresql-entrypoint-container.sh"]
args: ["/opt/bitnami/scripts/postgresql/run.sh"]
volumeMounts:
- name: postgresql-scripts
mountPath: /var/scripts
- name: postgresql-data
mountPath: /bitnami/postgresql
- name: etc
mountPath: /etc
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libbitnami.sh
. /opt/bitnami/scripts/libpostgresql.sh
# Load MySQL environment variables
. /opt/bitnami/scripts/postgresql-env.sh
print_welcome_page
set -x
id
cat /etc/passwd
ls -la /bitnami/postgresql /bitnami/postgresql/data/ /opt/bitnami/postgresql/
chown -R $POSTGRESQL_DAEMON_USER:$POSTGRESQL_DAEMON_GROUP /opt/bitnami/postgresql/tmp /opt/bitnami/postgresql/logs
exec bash -x "$@"
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libbitnami.sh
. /opt/bitnami/scripts/libpostgresql.sh
# Load MySQL environment variables
. /opt/bitnami/scripts/postgresql-env.sh
print_welcome_page
info "** Starting PostgresQL setup **"
/opt/bitnami/scripts/postgresql/setup.sh
info "** PostgresQL setup finished! **"
ls -la /bitnami/postgresql /bitnami/postgresql/data/ /opt/bitnami/postgresql/
cp -a /etc/* /runtime-etc/
cat /etc/passwd
#!/bin/sh
set -e
touch /docker-entrypoint-initdb.d/.restored
#!/usr/bin/env bash
set -ex
trap 'exit' TERM
while [[ ! -e $WAIT_FOR_FILE ]]; do
echo "Waiting for file: $WAIT_FOR_FILE" 1>&2
sleep 1
count=5
while [[ ! -e $WAIT_FOR_FILE && $count -gt 0 ]]; do
count=$(($count - 1))
sleep 1
done
done
namePrefix: {{ .Values.namePrefix }}
namespace: {{ .Values.namespace }}
images:
- name: debian
newName: {{ .Values.images.debian }}
- name: postgresql
newName: {{ .Values.images.postgresql }}