Repository navigation
Description
Hello,
I've set up two namespaces, let's say source and destination, the dst is empty for now.
I've created two VolumeSnapshotClass.
I've created a minimal cluster in the src ns:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: yacine
namespace: source
spec:
backup:
volumeSnapshot:
className: csi-vsc-delete
online: true
onlineConfiguration:
immediateCheckpoint: true
waitForArchive: true
snapshotOwnerReference: backup
instances: 1
storage:
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: sc-delete
volumeMode: Filesystem
walStorage:
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: sc-delete
volumeMode: Filesystem
switchoverDelay: 3600
Then i executed some sql commands to create tables and make some insertions in order to have some data in it to verify later that my restore work as expected.
So, i create a back up using volumesnapshot:
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: yacine-snapshot
namespace: source
spec:
method: volumeSnapshot
cluster:
name: yacine
I've found that two volume snapshot are created one for data and the second for wals which is the expected behavior, for now everything works fine.
kg volumesnapshot -n source
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
yacine-snapshot true yacine-1 2Gi csi-vsc-delete snapcontent-9edbca5e-1e5b-47a3-8dd8-b407b627ce3d 175m 175m
yacine-snapshot-wal true yacine-1-wal 2Gi csi-vsc-delete snapcontent-3be03e15-4272-4e0e-9a6f-e387ca980684 175m 175m
What i wanted to achieve is to restore this database using this backup in the destination namespace
Searching in the official documentation of cnpg, i found out that it does not seems possible to achieve this ( directly at least)
in the recovery link in the refs section below, you can find the entire example, but what is interesting for me is this part
bootstrap:
recovery:
volumeSnapshots:
storage:
name: <snapshot name>
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
i tried to add namespace parameter directly under the storage section but it does not work, it is not supported.
What i did next is to create two pvcs based on the volumesnapshots of the source namespace ant then recreate a volumesnapshot in the "destination namespace" which will make me able to restore the database.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: yacine-snapshot
namespace: destination
spec:
storageClassName: sc-retain
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
dataSourceRef:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: yacine-snapshot
namespace: source
volumeMode: Filesystem
Same thing for the wals:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: yacine-snapshot-wal
namespace: destination
spec:
storageClassName: sc-retain
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
dataSourceRef:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: yacine-snapshot-wal
namespace: source
volumeMode: Filesystem
Now VolumeSnapshot:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: yacine-snapshot
namespace: destination
spec:
volumeSnapshotClassName: csi-vsc-delete
source:
persistentVolumeClaimName: yacine-snapshot
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: yacine-snapshot-wal
namespace: destination
spec:
volumeSnapshotClassName: csi-vsc-delete
source:
persistentVolumeClaimName: yacine-snapshot-wal
Finally, set up a cluster that will restore from these VolumeSnapshots
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: yacine
namespace: destination
spec:
instances: 1
storage:
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: gp2-retain-immediate
volumeMode: Filesystem
walStorage:
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: gp2-retain-immediate
volumeMode: Filesystem
backup:
volumeSnapshot:
className: csi-osc-vsc-delete
online: true
onlineConfiguration:
immediateCheckpoint: true
waitForArchive: true
snapshotOwnerReference: backup
retentionPolicy: 3d
bootstrap:
recovery:
database: yacine
owner: yacine
volumeSnapshots:
storage:
name: yacine-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
walStorage:
name: yacine-snapshot-wal
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
At this level, i expected everything to work fine, but unfortunatelly no :)
$ kg po -n destination
NAME READY STATUS RESTARTS AGE
yacine-1 0/1 CrashLoopBackOff 10 (4m27s ago) 30m
yacine-1-snapshot-recovery-lstx4 0/1 Completed 0 31m
Logs:
recovery-job:
$ k logs yacine-1-snapshot-recovery-lstx4 -n destination
Defaulted container "snapshot-recovery" out of: snapshot-recovery, bootstrap-controller (init)
{"level":"info","ts":"2024-05-17T12:55:45Z","msg":"Cleaning up PGDATA from stale files","logging_pod":"yacine-1-snapshot-recovery"}
the instance of the pg cluster:
$ k logs yacine-1 -n destination
Defaulted container "postgres" out of: postgres, bootstrap-controller (init)
{"level":"info","ts":"2024-05-17T13:27:20Z","logger":"setup","msg":"Starting CloudNativePG Instance Manager","logging_pod":"yacine-1","version":"1.23.1","build":{"Version":"1.23.1","Commit":"336ddf53","Date":"2024-04-30"}}
{"level":"info","ts":"2024-05-17T13:27:20Z","logger":"setup","msg":"Starting CloudNativePG Instance Manager","logging_pod":"yacine-1","version":"1.23.1","build":{"Version":"1.23.1","Commit":"336ddf53","Date":"2024-04-30"}}
{"level":"info","ts":"2024-05-17T13:27:20Z","logger":"setup","msg":"Starting CloudNativePG Instance Manager","logging_pod":"yacine-1","version":"1.23.1","build":{"Version":"1.23.1","Commit":"336ddf53","Date":"2024-04-30"}}
{"level":"info","ts":"2024-05-17T13:27:20Z","logger":"setup","msg":"Starting CloudNativePG Instance Manager","logging_pod":"yacine-1","version":"1.23.1","build":{"Version":"1.23.1","Commit":"336ddf53","Date":"2024-04-30"}}
{"level":"info","ts":"2024-05-17T13:27:20Z","logger":"setup","msg":"Starting CloudNativePG Instance Manager","logging_pod":"yacine-1","version":"1.23.1","build":{"Version":"1.23.1","Commit":"336ddf53","Date":"2024-04-30"}}
**Error: lstat /var/lib/postgresql/data/pgdata/pg_wal: no such file or directory**
I've installed the cnpg plugin to see if i can find anything helpul, but i had no chance :/
$ k cnpg status yacine -n destination
Cluster Summary
Primary server is initializing
Name: yacine
Namespace: destination
PostgreSQL Image: ghcr.io/cloudnative-pg/postgresql:16.2
Primary instance: (switching to yacine-1)
Status: Waiting for the instances to become active Some instances are not yet active. Please wait.
Instances: 1
Ready instances: 0
Certificates Status
Certificate Name Expiration Date Days Left Until Expiration
---------------- --------------- --------------------------
yacine-ca 2024-08-15 12:50:02 +0000 UTC 89.97
yacine-replication 2024-08-15 12:50:02 +0000 UTC 89.97
yacine-server 2024-08-15 12:50:02 +0000 UTC 89.97
Continuous Backup status
First Point of Recoverability: Not Available
No Primary instance found
Physical backups
Primary instance not found
Streaming Replication status
Not configured
Unmanaged Replication Slot Status
No unmanaged replication slots found
Managed roles status
No roles managed
Tablespaces status
No managed tablespaces
Pod Disruption Budgets status
Name Role Expected Pods Current Healthy Minimum Desired Healthy Disruptions Allowed
---- ---- ------------- --------------- ----------------------- -------------------
yacine-primary primary 0 0 1 0
yacine-primary primary 1 1 1 0
Instances status
Name Database Size Current LSN Replication role Status QoS Manager Version Node
---- ------------- ----------- ---------------- ------ --- --------------- ----
yacine-1 - - - pod not available BestEffort - worker1.compute
I've enabled two kube api server args required for crossnamespace volume snapshot
- feature-gates=CrossNamespaceVolumeDataSource=true
- feature-gates=AnyVolumeDataSource=true
See Ref:3 for entire docs
...
Kubernetes supports cross namespace volume data sources. To use cross namespace volume data sources, you must enable the AnyVolumeDataSource and CrossNamespaceVolumeDataSource [feature gates](https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/) for the kube-apiserver and kube-controller-manager. Also, you must enable the CrossNamespaceVolumeDataSource feature gate for the csi-provisioner.
...
And this parameter in args of my csi driver:
- '--feature-gates=CrossNamespaceVolumeDataSource=true'
I'll be grateful if you can help finding why this is happening, i tried to change parameters and see if there are any changes, but nothing useful unfortunatelly. Thank you in advance 😄
Refs:
*1 https://cloudnative-pg.io/documentation/1.22/backup_volumesnapshot/
*2 https://cloudnative-pg.io/documentation/1.20/recovery/#recovery-from-volumesnapshot-objects
*3 https://kubernetes.io/docs/concepts/storage/persistent-volumes/#cross-namespace-data-sources
Activity
sreisich commentedon Jun 20, 2024
Hello,
I have a similar issue. I'm setting the namespace in the storage object like this:
But the Cluster seems to not take the namespace into account because when I describe the Cluster I see only this:
dosubot commentedon Apr 9, 2025
Hi, @yacinebbt. I'm Dosu, and I'm helping the cloudnative-pg team manage their backlog. I'm marking this issue as stale.
Issue Summary
Next Steps
Thank you for your understanding and contribution!
JordanP commentedon Apr 10, 2025
The problem here is that the volumeSnapshot k8s resource has to be in the same namespace than the new cluster. It's a big limitation imo: we can't restore that cluster in another namespace.
github-actions commentedon Jul 3, 2025
This issue is stale because it has been open for 60 days with no activity.
github-actions commentedon Jul 17, 2025
This issue was closed because it has been inactive for 14 days since being marked as stale.