Skip to content

build(k8s): plan the PostgreSQL 18 move of the CNPG clusters #5094

Not planned

Description

@dan-petty

Problem or Motivation

The CloudNativePG clusters k8s/llm/gateway-db.yaml (LiteLLM) and k8s/mattermost/database.yaml (Mattermost) set imageName PostgreSQL 17 (17.2 live; the baseline #5065 takes 17.11). PostgreSQL 18 exists. Renovate (#4893) will offer it.

  • A PostgreSQL major needs pg_upgrade or a logical import into a new cluster (dump and restore). The image field alone is not safe.
  • Owner rule: a database major is never a pin-only update here. Renovate must hold PostgreSQL at 17 until this item plans the move.

Research of 2026-11-12 (research-k8s, record image-field:CloudNativePG imageName (PostgreSQL 18)).

Proposed Solution & Architectural Design

  • Write the upgrade plan: the CloudNativePG method (offline in-place major upgrade of the operator, or a new cluster with bootstrap.initdb.import), the backup before it (#4765 for Mattermost), the downtime, the check and the rollback.
  • Add a Renovate rule that holds the PostgreSQL major for a Dependency Dashboard approval, if feat(deps): track regular version updates with Renovate #4893 does not hold it already.

Done when the plan is in this issue and Renovate holds the major.

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

CloudNativePG major upgrade support and pg_upgrade. No new code.

Source: #4893

Alternatives check of 2026-11-22: in-use.
The repository already uses this tool.
Tool: cloudnative-pg/cloudnative-pg (https://github.com/cloudnative-pg/cloudnative-pg), Apache-2.0, last activity 2026-11-21, maintained.
Reason: Searches found CloudNativePG, already the operator of both clusters, covering offline in-place pg_upgrade and logical import; it does not supply the written runbook or the Renovate major hold, so the item keeps real work.

Covers:

  • Offline in-place major upgrade through pg_upgrade --link on imageName change
  • Logical dump and restore path for a new cluster as fallback
  • Automatic cleanup of a failed upgrade job when the image is reverted
  • Operator-managed backup and restore through Barman Cloud

Lacks:

  • No written runbook with downtime, checks and rollback per cluster
  • No Renovate rule holding the PostgreSQL major by itself
  • Pre-upgrade backup is only recommended, not enforced
  • No rollback guarantee once data is upgraded and backups cannot serve PITR

Proposed design

Problem statement

Write the PostgreSQL 18 upgrade plan for the two CloudNativePG clusters and hold Renovate at PostgreSQL 17 until a person approves the major. The clusters llm-gateway-db and mattermost-db run PostgreSQL 17.11. A major version needs a planned upgrade with a backup, downtime, checks and rollback.

Acceptance criteria

Requirement: Upgrade plan records the CloudNativePG method

The change SHALL add a plan that names the CloudNativePG pg_upgrade method for both clusters and bootstrap.initdb.import as the fallback.

Scenario: Plan names the chosen method

  • WHEN uv run pytest tests/k8s/test_postgresql_upgrade_plan.py runs
  • THEN the test passes and asserts that the plan names pg_upgrade for both clusters and bootstrap.initdb.import as the fallback.

Requirement: Plan records backup, downtime, checks and rollback

The plan SHALL state the pre-upgrade backup, the downtime, the post-upgrade checks and the rollback for each cluster.

Scenario: Each cluster has the four runbook parts

  • WHEN uv run pytest tests/k8s/test_postgresql_upgrade_plan.py runs
  • THEN the test passes and finds a backup, downtime, check and rollback part for llm-gateway-db and mattermost-db.

Requirement: Plan names the Mattermost backup prerequisite

The plan SHALL name dan-petty/homelab#342 as the backup prerequisite for mattermost-db.

Scenario: Mattermost backup part names dan-petty/homelab#342

  • WHEN uv run pytest tests/k8s/test_postgresql_upgrade_plan.py runs
  • THEN the test passes and finds #4765 in the mattermost-db backup part.

Requirement: Renovate holds the PostgreSQL major

The final Renovate configuration MUST hold a major update of ghcr.io/cloudnative-pg/postgresql for a Dependency Dashboard approval.

Scenario: Renovate holds the PostgreSQL major

  • WHEN uv run devops ci --check --only renovate runs, and gh api repos/dan-petty/devops-cli/contents/.github/renovate.json --jq .content | base64 -d | jq runs
  • THEN the validator exits 0 and the JSON shows dependencyDashboardApproval: true with matchUpdateTypes: ["major"] for ghcr.io/cloudnative-pg/postgresql.

Existing Tool Considered

cloudnative-pg/cloudnative-pg (Apache-2.0, maintained) is already in use. It covers the operator lifecycle and both major-upgrade paths: offline in-place pg_upgrade and a new cluster with bootstrap.initdb.import. It lacks a runbook for downtime, checks and rollback, and it does not hold the Renovate major by itself. The remaining work is the plan and one Renovate rule.

Key questions

  • Which CloudNativePG major-upgrade method should the plan use for the two clusters?: Use the CloudNativePG offline in-place pg_upgrade method for both clusters. Each cluster has one instance and small storage. The operator stops the instance, runs pg_upgrade and starts the new major. Use bootstrap.initdb.import only as the fallback when pg_upgrade fails before cutover. (best practice) [sources: k8s/llm/gateway-db.yaml, k8s/mattermost/database.yaml]
    • Chosen: Offline in-place pg_upgrade. Both clusters are single-instance and small, and the existing PVC and Service stay in place.
    • Rejected: New cluster with bootstrap.initdb.import. It needs a second cluster, a second PVC and an application cutover for a 5Gi and 10Gi database.
    • Rejected: Hand-run logical dump and restore. The operator already provides the import path, so a hand-run path adds work.
  • What backup must precede the upgrade?: Take a CloudNativePG Barman Cloud backup of each cluster and verify a restore before the maintenance window. For mattermost-db, use the backup from dan-petty/homelab#342. (best practice) [sources: k8s/mattermost/database.yaml]
    • Chosen: CloudNativePG Barman Cloud backup. The operator and its Barman Cloud plugin cover the backup and restore path.
    • Rejected: pg_dump from the application pod. It adds a hand-run path and does not prove the operator can restore the cluster.
    • Rejected: No backup; rely on pg_upgrade --link. A failed major upgrade has no rollback without a backup.
  • What downtime does each cluster need?: Plan one maintenance window for each cluster. The operator stops the single instance for the whole pg_upgrade. The gateway or Mattermost is unavailable from the stop until the new instance is Ready. Run the two clusters in separate windows. (best practice) [sources: k8s/llm/gateway-db.yaml, k8s/mattermost/database.yaml]
    • Chosen: One window for each cluster. Each cluster has one instance, so the upgrade is offline and the applications must not share the window.
    • Rejected: Both clusters in one window. A failure in one cluster would hold both applications down.
    • Rejected: No downtime with logical replication. It adds a second cluster and a cutover that this plan does not need.
  • What checks prove the upgrade succeeded?: Check that the Cluster is Ready and the pg_upgrade job completed. Check that SELECT version() reports 18 and the application health endpoint passes. Check that the CloudNativePG metrics and alerts are green. Run the checks after each cluster and before the next window. (best practice) [sources: k8s/llm/gateway-db.yaml, k8s/mattermost/database.yaml]
    • Chosen: Operator status, SQL version and application health. The operator status shows the cluster, SQL shows the major, and the application health shows the data path.
    • Rejected: Only the Pod is Running. A running pod does not prove that the new major serves the application.
    • Rejected: Only the application health. The application can pass while the operator upgrade job has failed.
  • What rollback does the plan use?: Restore the pre-upgrade Barman Cloud backup into a new cluster and point the application at it. Do not downgrade the upgraded cluster in place. PostgreSQL does not support a major downgrade in place. (best practice) [sources: k8s/llm/gateway-db.yaml]
    • Chosen: Restore the backup into a new cluster. It gives a tested path back to PostgreSQL 17 without an unsupported downgrade.
    • Rejected: Downgrade the existing cluster. PostgreSQL does not support an in-place major downgrade.
    • Rejected: Re-run pg_upgrade. It does not recover data after a failed upgrade.
  • Does .github/renovate.json already hold the PostgreSQL major?: The file has a custom manager for the CloudNativePG imageName field at line 97. The visible lines do not show a major-hold package rule. The final file must hold major updates of ghcr.io/cloudnative-pg/postgresql for Dependency Dashboard approval. Add the rule only when it is absent. (best practice) [sources: .github/renovate.json:97]
  • Should the item change the PostgreSQL image in the Cluster manifests?: No. The item writes the plan and holds Renovate at 17. The image change runs in a later item after a person approves the plan. (best practice) [sources: k8s/llm/gateway-db.yaml, k8s/mattermost/database.yaml]
    • Chosen: Keep imageName at 17.11. The issue is a plan, and a major move needs the planned backup and window.
    • Rejected: Bump imageName to 18 now. A pin-only major bump is not safe and the owner rule forbids it.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/infra
    scope/k8s
    status/new
    value/medium
    effort/low
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
    • Related: dan-petty/homelab#342, which asks for a different change. Both concern the Mattermost CloudNativePG database; dan-petty/homelab#342 adds a backup while this item plans the version upgrade that depends on that backup.
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The searches point to CloudNativePG as the operator the two cluster manifests already run, and the operator itself provides the two major-version paths the issue weighs (offline in-place pg_upgrade, or a new cluster that imports through bootstrap.initdb.import), with operand images published for each supported PostgreSQL version. So the tool the issue needs already exists and is in use; only the plan text and the Renovate hold rule are the project's own work.

    The repository already uses this tool.

    Tool: cloudnative-pg/cloudnative-pg (https://github.com/cloudnative-pg/cloudnative-pg)

    • License: Apache-2.0
    • Last activity: 2026-11-15
    • Maintained: yes

    Covers:

    • Operator for the full lifecycle of a PostgreSQL cluster on Kubernetes, which the gateway-db and mattermost manifests already use
    • Major-version moves: an offline in-place pg_upgrade of the cluster, or a new cluster bootstrapped with initdb.import
    • Operand images for every community-supported PostgreSQL version, so a PostgreSQL 18 image exists for imageName
    • Backup and restore of the cluster through the Barman Cloud plugin, which the pre-upgrade backup needs

    Lacks:

    • No runbook: the downtime, the checks and the rollback of each cluster stay the issue's own plan
    • Does not hold the Renovate major by itself; that is a Renovate rule in this repository
    • The image field alone is still not a safe major bump, so a person must choose the path and run it

    Tools considered:

    Searches run:

    • CloudNativePG bootstrap initdb import new cluster logical dump restore major upgrade, results: 5
    • CloudNativePG major version upgrade pg_upgrade PostgreSQL 18, results: 5
    • cloudnative-pg documentation "major version upgrade" operator in-place, results: 5
    • cloudnativepg cluster spec imageName postgresql 18 supported, results: 5
    • cloudnative-pg github repository, results: 5
    • CloudNativePG, results: 5
    • cloudnative.io docs postgresql major upgrade offline in-place, results: 5
    • cnpg major version upgrade guide, results: 5
    • CloudNativePG documentation site cloudnative-pg.io, results: 5
    • cloudnative-pg upgrade PostgreSQL 17 to 18 cluster annotation pg_upgrade offline, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  7. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at b8c7632 (see proposed design in issue body).

  8. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor

    Closed: the PostgreSQL 18 move already happened, and the next major is held.

    dan-petty/homelab set both CloudNativePG clusters to 18.6 on 2026-11-23 (dan-petty/homelab#158), and both were healthy on 18.6 on 2026-11-26. The preset renovate/base.json of dan-petty/infra holds a PostgreSQL major for Dashboard approval. No database backup is in git: dan-petty/homelab#332 and dan-petty/homelab#342 (moved to dan-petty/homelab) hold that work.

  9. removed
    status/ready
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/k8ssource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions