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 }}"
nappl:
waitFor:
- "-service {{ .component.prefix }}postgres.{{ .Release.Namespace }}.svc.cluster.local:5432 -timeout 600"
nappljobs:
waitFor:
- "-service {{ .component.prefix }}postgres.{{ .Release.Namespace }}.svc.cluster.local:5432 -timeout 600"in the values file (see values.yaml). This will instantiate the official Postgres image.
The postgres component takes the same values as database (name, user, password, mounts), but its service
has a different name. So point the database URL and the wait condition of nappl (and of nappljobs, if you
run one) to postgres: by default they wait for the service database, and without it they never start.
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 and to wait for it
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"
nappljobs:
waitFor:
- "-service {{ .component.prefix }}postgres.{{ .Release.Namespace }}.svc.cluster.local:5432 -timeout 600"- Remove the old database component
components:
database: false
postgres: trueWhich PostgreSQL version runs?#
Two database components exist, and they differ in image, not only in name:
| Component | Image | Default version |
|---|---|---|
database | bitnamilegacy/postgresql | 16 (from versions/latest.yaml, the newest version file follows) |
postgres | the official postgres image | 18 |
The default of database stays on major version 16, deliberately slower than the
Ceyoniq examples (17) and the official image (18): a major jump on an existing
data directory is not an upgrade, it is a dump/restore — see the migration
scenario below, which is exactly that procedure. bitnamilegacy is the frozen
pre-License-Change Bitnami repository; the regular bitnami/* images now carry
a restrictive license and are not used.
For a new installation you can pick either component and any major your operating policy allows — set the tag per version file or per component:
database:
image:
name: bitnamilegacy/postgresql
tag: "17"For an existing installation, stay on your major until you run the dump/restore below into the new major; PostgreSQL refuses to start an older data directory with a newer binary.
Files#
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"