We utilize an init container in the deployment to create a database for our applications if it doesn’t already exist. The initialization script consists of three stage: wait until the postgres database is accepting conditions, attempt to make a select statement against the database, create the database if the select statement fails.
initContainers:
- name: init-database
image: postgres:14
envFrom:
- secretRef:
name: postgres-creds
optional: false
command:
- bash
- -c
- |
export PGPASSWORD=$( tr -d '\n\t\r' <<< $POSTGRES_PASSWORD )
until pg_isready -h postgres -p 5432 -U ${POSTGRES_USER}; do
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done
psql -h postgres -U ${POSTGRES_USER} -d 'radarr-main' -c "SELECT 1" || psql -h postgres -U ${POSTGRES_USER} -c 'CREATE DATABASE "radarr-main";'
psql -h postgres -U ${POSTGRES_USER} -d 'radarr-log' -c "SELECT 1" || psql -h postgres -U ${POSTGRES_USER} -c 'CREATE DATABASE "radarr-log";'
config.xml
base64 -w 0 config.xml
, copy output.apiVersion: v1
data:
config.xml: pen...15
kind: Secret
metadata:
name: lidarr-creds
namespace: media-scrapers
type: Opaque
kubeseal --scope strict -o yaml <config-secret.yaml > ../sealed-config-secret.yaml
.volumes:
- name: lidarr-config-xml
secret:
secretName: lidarr-creds
mountPath: /config/config.xml
subPath: config.xml
name: lidarr-config-xml
readOnly: True