
Upgrading Postgres 17 to 18 on Kubernetes with the Crunchy Operator and ArgoCD
We run our production Postgres clusters on Kubernetes, managed by Crunchy Data's Postgres Operator (PGO) and deployed through ArgoCD. When Postgres 19 became available, we upgraded our clusters from 17 to 18 without touching kubectl for a single change. Every step was a commit to our GitOps repository.
This post walks through how we did it, including the part where the upgrade sat in Progressing and nothing happened. There was no error and no log line. We hadn't read past the first step of the docs.
The stack in two paragraphs
Crunchy Postgres for Kubernetes (PGO) is an operator that turns a Postgres cluster into a Kubernetes resource. You describe the cluster in a PostgresCluster manifest (version, instances, storage, backups) and the operator handles provisioning, replication, failover and pgBackRest backups. Major version upgrades are handled through a separate custom resource, PGUpgrade, which runs pg_upgrade for you inside a dedicated Job.
ArgoCD is our GitOps controller. The desired state of the cluster lives in Git, and ArgoCD keeps Kubernetes in sync with it. That has one practical consequence for upgrades: if you patch a resource by hand with kubectl, ArgoCD will see drift and, depending on your sync policy, revert it. So for us the upgrade had to be expressed as a sequence of changes to YAML files, not a sequence of CLI commands.
Before you start
A major version upgrade is a one-way door. Crunchy's documentation is explicit that there is no declarative rollback, so the checklist is short but not optional:
- Take a fresh full backup. If something goes wrong, this is your way back.
- Make sure the cluster is healthy. The operator will not complete an upgrade on a degraded cluster.
- Check for unsupported setups. PostGIS clusters and standby clusters are not supported by
PGUpgrade. A standby has to be removed before the upgrade and rebuilt on the new version afterwards. - Plan for downtime. The cluster is shut down while
pg_upgraderuns. This is not a zero-downtime procedure, and how long it takes depends on the size of your data.
Step 1: Create the PGUpgrade resource
The PGUpgrade object tells the operator which cluster to upgrade and between which versions. It must live in the same namespace as the cluster.
yaml
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PGUpgrade
metadata:
name: nimbo1-prod-upgrade-18
spec:
postgresClusterName: nimbo1prd
fromPostgresVersion: 17
toPostgresVersion: 18Creating this resource does not start anything. It only declares intent.
Step 2: Add it to Kustomize so ArgoCD picks it up
Our Postgres clusters are grouped in one Kustomize overlay. We add the upgrade manifest next to the cluster definition:
yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: postgres-operator
resources:
- postgres_nimbo_1/postgres.yaml
- postgres_nimbo_1/upgrade18.yamlCommit, push, and ArgoCD creates the PGUpgrade object in the cluster.
At this point the upgrade shows up as Progressing, and it stays there. This is where we lost some time the first time around.
Why the upgrade sits in "Progressing"
PGO deliberately refuses to start a major upgrade on its own. It uses a two-key safeguard so that nobody upgrades a production database by accidentally applying a manifest:
- The
PostgresClustermust carry the annotationpostgres-operator.crunchydata.com/allow-upgrade, and its value must match the name of thePGUpgraderesource exactly. - The cluster must be shut down (
spec.shutdown: true).
Until both conditions are met, the operator waits quietly. There is no failure and no alert, which is why it looks like the operator is stuck. The only hint is in the PGUpgrade status conditions, which report PGClusterNotShutdown while the cluster is still running. The annotation value also has to match character for character, so a typo like upgrade18 instead of upgrade-18 keeps it waiting too.
We had created the PGUpgrade resource, saw Progressing, and expected the operator to take it from there. It was waiting for us to add the annotation and shut the cluster down.
Step 3: Trigger the upgrade with one commit
In the cluster's postgres.yaml, we add the annotation and set shutdown: true in the same change. The postgresVersion stays at 17 for now.
yaml
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
name: nimbo1prd
annotations:
postgres-operator.crunchydata.com/allow-upgrade: "nimbo1-prod-upgrade-18"
spec:
postgresVersion: 17
shutdown: true
# ...Keeping the version at 17 matters. If you bump postgresVersion before the upgrade has run, the operator rejects the upgrade.
Once ArgoCD syncs, the operator shuts down the Postgres pods. After the last pod terminates, it launches the upgrade Job, runs pg_upgrade against the primary's volume, and then prepares the replicas.
If you are not running GitOps, the same two gates can be set from the command line:
bash
kubectl annotate postgrescluster nimbo1prd \
postgres-operator.crunchydata.com/allow-upgrade="nimbo1-prod-upgrade-18" --overwrite
kubectl patch postgrescluster nimbo1prd --type=merge -p '{"spec":{"shutdown":true}}'In an ArgoCD-managed namespace, make the change in Git instead, or ArgoCD may undo it.
Watching the upgrade
We followed the upgrade in FreeLens, which gives a quick view of the PGUpgrade conditions and the upgrade Job's pod logs. The CLI equivalents are:
bash
kubectl get pgupgrade nimbo1-prod-upgrade-18 -n postgres-operator
kubectl describe pgupgrade nimbo1-prod-upgrade-18 -n postgres-operatorThe upgrade is done when the conditions show Progressing as false with reason PGUpgradeCompleted, and Succeeded as true with reason PGUpgradeSucceeded. If anything fails, the operator halts rather than continuing, and the Job's pod logs contain the pg_upgrade output.
The completed PGUpgrade in FreeLens
Once the gates were open, the upgrade itself finished in under a minute. Our databases are small, so don't take that as a benchmark. With more data, expect the shutdown window to grow.
Step 4: Start the cluster on Postgres 18
With the upgrade complete, the second commit sets the new version and brings the cluster back up. We also retire the annotation:
yaml
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
name: nimbo1prd
annotations:
# postgres-operator.crunchydata.com/allow-upgrade: "nimbo1-prod-upgrade-18"
spec:
postgresVersion: 18
shutdown: false
# ...If your manifest pins spec.image, update it to a Postgres 18 image in the same commit.
Then remove upgrade18.yaml from the kustomization.yaml. Deleting the PGUpgrade object also removes its Jobs and pods. If your ArgoCD application has pruning enabled, removing it from Git is enough. Otherwise delete it explicitly. A PGUpgrade object is single-use; the next major upgrade gets a new one.
Verifying
A quick check from psql:
sql
SELECT version();PostgreSQL 18.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14), 64-bitPost-upgrade housekeeping
A few things are worth doing once the cluster is back:
- Read the upgrade Job output.
pg_upgradewrites warnings and generated helper scripts there. - Review extension updates. The upgrade can produce an
update_extensions.sqlscript. Crunchy recommends reviewing it before running it, since some suggested steps may not apply. - Clean up old data. Old data and WAL directories are not removed automatically. Delete them once you are confident you won't need them.
- Take a new backup on the new version.
What we took away from it
The Crunchy operator makes a major Postgres upgrade a mostly mechanical process. It is also careful by design, and its safety gates are silent, so it is easy to mistake a waiting operator for a stuck one. Read the whole procedure before you start, not just the first step. Once you know the sequence, the whole upgrade fits into two commits:
- Add the
PGUpgraderesource, theallow-upgradeannotation andshutdown: true. - Bump
postgresVersion, setshutdown: false, and remove the upgrade resource.
Because every step lives in Git, we also get an audit trail of who upgraded which database and when, and the same procedure repeats cleanly across clusters. We upgraded two production clusters this way. The second one, for ChatLeo, was a copy of the first set of commits with the names changed.
Webmobix AG builds and operates cloud infrastructure for fintech and regulated industries. If you are running Postgres on Kubernetes and want help with operators, GitOps or upgrades, get in touch.