Switching to the Official Postgres Image#
If you want to move from the Bitnami Postgres image to the official Postgres image, set:
components:
database: false
postgres: true
global:
database:
url: "jdbc:postgresql://{{ .component.prefix }}postgres:5432/{{ .this.database.name }}"in the values file. This will instantiate the official Postgres image. All values are identical.
You can also run both components side-by-side to perform migrations.
Make sure you set the database URL to the new DB when you are done.
Migration Scenario#
- Add the postgres component
components:
database: true
postgres: true- Copy the database from the
databasecomponent to thepostgrescomponent (single DB)
Because default-deny egress is enabled for the instance, allow temporary egress for the migration client:
kubectl apply -n lab -f - <<'EOF1'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: sample-postgres-allow-migration-egress
spec:
podSelector:
matchLabels:
nplus/group: sample-postgres
nplus/type: core
policyTypes:
- Egress
egress:
- to:
- podSelector:
matchLabels:
nplus/group: sample-postgres
nplus/type: database
- to:
- podSelector:
matchLabels:
nplus/group: sample-postgres
nplus/type: postgres
EOF1kubectl run -n lab pg-client --rm -i --image=postgres:17 \
--labels nplus/group=sample-postgres,nplus/type=core -- \
sh -c 'export PGPASSWORD=nscale; \
pg_dump -h sample-postgres-database -U nscale -Fc nscale | \
pg_restore -h sample-postgres-postgres -U nscale -d nscale --clean --if-exists'Clean up the temporary egress rule:
kubectl delete -n lab networkpolicy sample-postgres-allow-migration-egress- Set nappl to use the new postgres component
global:
database:
url: "jdbc:postgresql://{{ .component.prefix }}postgres:5432/{{ .this.database.name }}"- Remove the old database component
components:
database: false
postgres: trueFiles#
Download all files of this sample
build.sh#
#!/bin/bash
#
# This sample script builds the example as described. It is also used to build the test environment in our lab,
# so it should be well tested.
#
# Make sure it fails immediately, if anything goes wrong
set -e
# -- ENVironment variables:
# CHARTS: The path to the source code
# DEST: The path to the build destination
# SAMPLE: The directory of the sample
# NAME: The name of the sample, used as the .Release.Name
# KUBE_CONTEXT: The name of the kube context, used to build this sample depending on where you run it against. You might have different Environments such as lab, dev, qa, prod, demo, local, ...
# Check, if we have the source code available
if [ ! -d "$CHARTS" ]; then
echo "ERROR Building $SAMPLE example: The Charts Sources folder is not set. Please make sure to run this script with the full Source Code available"
exit 1
fi
if [ ! -d "$DEST" ]; then
echo "ERROR Building $SAMPLE example: DEST folder not found."
exit 1
fi
if [ ! -d "$CHARTS/instance" ]; then
echo "ERROR Building $SAMPLE example: Chart Sources in $CHARTS/instance not found. Are you running this script as a subscriber?"
exit 1
fi
# Set the Variables
SAMPLE="postgres"
NAME="sample-$SAMPLE"
# Output what is happening
echo "Building $NAME"
# Create the manifest
mkdir -p $DEST/instance
helm template --debug \
--values $SAMPLES/application/empty.yaml \
--values $SAMPLES/environment/$KUBE_CONTEXT.yaml \
--values $SAMPLES/resources/$KUBE_CONTEXT.yaml \
--values $SAMPLES/$SAMPLE/values.yaml \
$NAME $CHARTS/instance > $DEST/instance/$SAMPLE.yamlvalues.yaml#
components:
database: false
postgres: true
global:
database:
url: "jdbc:postgresql://{{ .component.prefix }}postgres:5432/{{ .this.database.name }}"
nappl:
waitFor:
- "-service {{ .component.prefix }}postgres.{{ .Release.Namespace }}.svc.cluster.local:5432 -timeout 600"
# the same for the dedicated jobs node, so this sample can be stacked on top of
# the ha sample - which otherwise waits for the "database" service by name
nappljobs:
waitFor:
- "-service {{ .component.prefix }}postgres.{{ .Release.Namespace }}.svc.cluster.local:5432 -timeout 600"