kubernetes-yaml/learn/learn-kubernetes-master/kiamol/ch09/todo-list/db/todo-db-scripts.yaml

44 lines
1.7 KiB
YAML
Raw Normal View History

apiVersion: v1
kind: ConfigMap
metadata:
name: todo-db-scripts
labels:
kiamol: ch09
data:
wait-service.sh: |-
#!/bin/sh
if [ "$HOSTNAME" == "$POSTGRES_PRIMARY_NAME" ]; then
echo '** Postgres primary **'
else
echo '** Postgres standby - waiting on DNS for primary **'
until nslookup ${POSTGRES_PRIMARY_FQDN}; do echo Waiting for ${POSTGRES_PRIMARY_FQDN}; sleep 1; done
fi
initialize-replication.sh: |-
#!/bin/bash
if [ "$HOSTNAME" == "$POSTGRES_PRIMARY_NAME" ]; then
echo '** Postgres primary - creating replication user script **'
cp /scripts/create-replica-user.sh /docker-entrypoint-initdb.d/create-replica-user.sh
ls -l /docker-entrypoint-initdb.d
else
echo '** Postgres standby - waiting on primary **'
until pg_isready -h "$POSTGRES_PRIMARY_FQDN"; do echo Waiting for db to be ready; sleep 1; done
fi
create-replica-user.sh: |-
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE ROLE replication WITH REPLICATION PASSWORD '$PGPASSWORD' LOGIN
EOSQL
startup.sh: |-
#!/bin/sh
if [ "$HOSTNAME" == "$POSTGRES_PRIMARY_NAME" ]; then
echo '** Postgres primary **'
/docker-entrypoint.sh postgres -c config_file=/conf/primary.conf -c hba_file=/conf/pg_hba.conf
else
echo '** Postgres standby - initializing replication**'
if [ -z "$(ls -A ${PGDATA})" ]; then
pg_basebackup -R -h "$POSTGRES_PRIMARY_FQDN" -D "$PGDATA" -P -U replication
chown -R postgres:postgres $PGDATA
fi
/docker-entrypoint.sh postgres -c config_file=/conf/standby.conf
fi