The module lifecycle stage: Preview
The module has requirements for installation
How disaster recovery works
Disaster recovery (DR) maintains a PostgreSQL copy in another Kubernetes cluster. Active accepts writes; Standby receives changes through asynchronous physical replication. Promotion makes Standby writable and is initiated manually on the Standby site. The operator does not initiate cross-site failover automatically.
The Active operator creates a Postgres object with the same name in the same-named namespace on the remote site and synchronizes its configuration. The remote service uses Standalone regardless of the Active topology. Provisioning and initial data transfer take time; creation of the remote object does not mean that the copy is ready.
Prepare both sites
Prepare the following dependencies before enabling DR. The operator does not install or synchronize them between sites.
| Dependency | Manual preparation |
|---|---|
| Module version | Install the same managed-postgres module version on both sites. When testing overrides, use the same module build. The operator does not compare module versions. |
| PostgresClass | Create a PostgresClass with the same name and identical spec on both sites. The operator copies postgresClassName, not the class itself, and does not compare class contents. |
| PostgreSQL version | Ensure that the version selected in Postgres is available and permitted by the class on both sites. Physical replication requires the same PostgreSQL major version. |
| Namespace and capacity | Create namespaces with identical names. Prepare quotas, nodes matching the class scheduling settings, and sufficient CPU, memory and storage for the remote instance. |
| Storage | Prepare the StorageClass referenced by Postgres or its class on the remote site. Its name must resolve locally; its provisioner may differ between sites. Check volume provisioning and the requested capacity. |
| Peering | Enable the peering module on both sites and configure ClusterPeer and ProjectPeer. ProjectPeer must be Paired, publish the remote cluster UUID, and grant the postgres capability with the project scope. Active specifies exactly one ProjectPeer; reverse lookup on Standby must resolve exactly one matching peer. |
| Network | Prepare ClusterMesh and global Service import/export through cni-cilium. Verify cross-site PostgreSQL connectivity on TCP 5432, service DNS resolution and access to the peer Kubernetes API. A paired ProjectPeer alone does not establish the replication network. |
| TLS | Enable cert-manager and prepare a working CA-based Issuer or ClusterIssuer on each site. Use tls.mode: CertManager. Issuer names and kinds referenced by the copied configuration must exist on both sites. The issuer must have spec.ca.secretName; a SelfSigned issuer is not sufficient. |
| Other local dependencies | Prepare any additional resources referenced by the class or service configuration, including credentials for external services. Referenced Secrets are not copied automatically. |
| Applications | Prepare application deployment, external Secrets, traffic switching and a procedure for isolating the old Active. These remain the administrator’s responsibility. |
The sites may use different certificate authorities. The operator exchanges public trust material; CA private keys do not need to be copied between sites.
The remote namespace must not contain an unrelated Postgres with the intended name. The operator checks source identity and does not adopt an arbitrary existing remote service.
Configure d8 contexts and install jq for the promotion example. Replace <ACTIVE_CONTEXT> and <STANDBY_CONTEXT> with your kubeconfig context names:
CONTEXT_A='<ACTIVE_CONTEXT>'
CONTEXT_B='<STANDBY_CONTEXT>'
PG_NAMESPACE=postgres
PG_NAME=dr-demoThe examples use PostgresClass dr-default, StorageClass dr-storage, ClusterIssuer dr-ca, namespace postgres and ProjectPeer cluster-b on Active. Prepare these objects or replace their names throughout the examples. Inspect the dependencies on both sites:
for context in "$CONTEXT_A" "$CONTEXT_B"; do
d8 k --context "$context" get module managed-postgres
d8 k --context "$context" get postgresclass dr-default -o yaml
d8 k --context "$context" get storageclass dr-storage
d8 k --context "$context" get clusterissuer dr-ca -o yaml
d8 k --context "$context" --namespace "$PG_NAMESPACE" get projectpeer -o yaml
doneCompare module versions and class specifications, inspect issuer readiness and peer capabilities. These commands display configuration; they do not replace checking the cross-site network or storage provisioning.
Enable replication
Save this manifest as postgres-dr.yaml. Apply it only on Active after completing the prerequisites:
apiVersion: managed-services.deckhouse.io/v1alpha2
kind: Postgres
metadata:
name: dr-demo
namespace: postgres
spec:
type: Standalone
version: "17"
postgresClassName: dr-default
instance:
cpu:
cores: 1
coreFraction: "50%"
memory:
size: 1Gi
persistentVolumeClaim:
size: 10Gi
storageClassName: dr-storage
tls:
mode: CertManager
certManager:
clusterIssuerName: dr-ca
disasterRecovery:
role: Active
projectPeerNames:
- cluster-bCreate the service:
d8 k --context "$CONTEXT_A" apply -f postgres-dr.yamlFor an existing Postgres, add spec.disasterRecovery to its declarative configuration and ensure its TLS and local dependencies meet the prerequisites. Do not apply the whole example over an existing service.
The operator creates the remote Standby, configures its initial copy and streaming replication, and creates the d8ms-pg-dr-demo-dr mesh Service on both sites. The Active service exports the current primary; the Standby service imports that endpoint. Configure the service through Active; the operator synchronizes the remote specification.
Check replication
Inspect both Postgres objects:
for context in "$CONTEXT_A" "$CONTEXT_B"; do
d8 k --context "$context" \
--namespace "$PG_NAMESPACE" \
get postgres "$PG_NAME" -o yaml
doneCheck status.disasterRecovery and the DisasterRecoveryReady condition in status.conditions. A remote state of Created only confirms that the remote Postgres exists. DisasterRecoveryReady=True confirms observed streaming replication; it does not guarantee zero replication lag or zero data loss during an emergency switch.
An unavailable or stale observation cannot confirm current replication health. Check the condition reason and message, network connectivity and PostgreSQL replication state before relying on the Standby copy.
Inventory runs on the designated primary of Standby and publishes PostgresDatabase and PostgresUser objects with empty spec. Standby does not apply user declarations or generate user passwords while PostgreSQL remains read-only.
Promote Standby
Promotion is a manual operation on site B. Plan application downtime and credential updates before starting.
Stop writes to the old Active and isolate it before promotion. The confirmation annotation records the administrator’s decision; it does not fence the old site or prove that all WAL has been replayed. Two writable sites can diverge.
For a planned switch:
- Stop all writers on Active, including applications, scheduled jobs and administrative sessions. Prevent them from reconnecting.
- Record the final WAL flush position on Active using
SELECT pg_current_wal_flush_lsn();through an authorized SQL connection. - On Standby, check
SELECT pg_last_wal_replay_lsn();and wait until the recorded position has been replayed. Keep Active isolated after this check. - Promote Standby using the command below.
For an emergency switch, isolate Active even if its Kubernetes API is unavailable. If the final WAL position cannot be checked, account for possible loss of changes not replayed on Standby. Streaming health alone is not proof that the copy contains the latest transactions.
The following command reads the source identity from Standby, adds managed-services.deckhouse.io/dr-promotion-confirmed-source with the value <source-cluster-UUID>/<source-Postgres-UID>, and removes spec.disasterRecovery in one update. A resource-version check prevents applying the patch to a changed object. Run it only after the isolation and data-loss checks above:
postgres_json=$(d8 k --context "$CONTEXT_B" \
--namespace "$PG_NAMESPACE" \
get postgres "$PG_NAME" -o json)
patch=$(printf '%s' "$postgres_json" | jq -ce '
.metadata.annotations as $a |
$a["managed-services.deckhouse.io/dr-source-cluster"] as $cluster |
$a["managed-services.deckhouse.io/dr-source-uid"] as $uid |
if (.spec.disasterRecovery.role != "Standby" or
($cluster // "") == "" or ($uid // "") == "")
then error("Expected Standby with source identity")
else [
{op: "test", path: "/metadata/resourceVersion", value: .metadata.resourceVersion},
{op: "add", path: "/metadata/annotations/managed-services.deckhouse.io~1dr-promotion-confirmed-source",
value: ($cluster + "/" + $uid)},
{op: "remove", path: "/spec/disasterRecovery"}
] end
') && d8 k --context "$CONTEXT_B" \
--namespace "$PG_NAMESPACE" \
patch postgres "$PG_NAME" --type=json --patch "$patch"If the resource-version check fails, inspect the current object and repeat the command. Do not bypass the check by removing source identity annotations.
Wait for DisasterRecoveryPromotion=True with reason PromotionCompleted and inspect service availability. WaitingForInventoryWitness means the operator is waiting for the local inventory observation required for credential recovery. Promotion completion does not mean that all application credentials are ready.
Restore application access
After promotion, the operator uses replicated SQL-role metadata to restore management of users whose passwords were generated through storeCredsToSecret. It fills the existing local inventory objects, creates Secrets with the recorded names and generates new passwords. The old Active passwords are not copied. Existing Admin privileges are preserved during this recovery.
Before switching traffic:
- Check the restored PostgresUser objects and their
Syncedconditions. Inspect conflicts rather than overwriting Secrets belonging to another object. - Update or restart applications so they use the new site’s Secrets and service endpoint. Verify an actual authenticated connection.
- For users managed through
hashedPasswordorpasswordSecretRef, provide the password source on the new site and explicitly adopt the local inventory objects. These users, and users without generated-password metadata, remain unmanaged automatically. - Explicitly adopt PostgresDatabase inventory objects if declarative database management is required. Database declarations are not restored by credential recovery.
Automatic recovery does not overwrite already managed, conflicting, deleting or lost user objects. After resolving a conflict, reconciliation retries recovery. Do not delete generated Secrets as a diagnostic step: deletion requests password rotation.
Keep the former Active isolated. Rebuilding replication in the reverse direction and returning applications to the original site require a separate recovery plan; promotion does not perform them automatically.
Limitations and troubleshooting
DR supports one remote peer per Active. Replication is asynchronous and does not replace backups. Monitor available disk space, replication lag and WAL retention; an extended interruption can require a new Standby copy if the required WAL is no longer available.
Use condition messages and operator logs to distinguish dependency failures from replication failures:
| Reason or symptom | What to check |
|---|---|
IntegrationDisabled |
The peering module is enabled on both sites. |
PeerUnavailable |
ProjectPeer pairing, the postgres capability, remote API availability and reverse peer lookup. |
IncompatibleMeshIdentity |
Matching namespace and Postgres names across sites. |
OwnershipConflict |
The remote Postgres belongs to this source identity. Do not delete an unrelated service to clear the error. |
UnsupportedTLSMode or CA issuer error |
CertManager mode, the referenced issuer and its CA configuration on each site. |
SpecSyncFailed |
The detailed message, remote admission errors and missing configuration dependencies. |
WALReceiverInactive |
Replication network, certificates, source availability and PostgreSQL logs. |
ObservationStale or ObservationUnavailable |
The component publishing replication observations and connectivity to it. |
| Credentials remain unavailable after promotion | PostgresUser conditions, generated Secret ownership, role metadata and external password sources. |