#!/usr/bin/env bash # PostgreSQL — the cluster half of the postgres cabinet: plain manifests, one replica on a PVC. # Notes: docs/notes/addons.md set -euo pipefail cd "$(dirname "$0")/.." source ./lib/config.sh load_config K="kubectl --context ${KUBECONTEXT}" NS="${DATA_NAMESPACE:-data}" $K get namespace "$NS" >/dev/null 2>&1 || $K create namespace "$NS" # The password is generated once and then left alone, so re-running this does # not rotate the credential out from under whatever is already connected. if $K get secret -n "$NS" postgres >/dev/null 2>&1; then echo " secret exists, keeping the current password" else password=$(head -c 18 /dev/urandom | base64 | tr -d '/+=' | head -c 24) $K create secret generic postgres -n "$NS" \ --from-literal=POSTGRES_DB="${POSTGRES_DB:-postgres}" \ --from-literal=POSTGRES_USER="${POSTGRES_USER:-postgres}" \ --from-literal=POSTGRES_PASSWORD="$password" >/dev/null echo " generated a password (read it back with the command printed below)" fi echo " applying manifests" $K apply -n "$NS" -f - >/dev/null <