1

I have deleted the pvc on my mediawiki kubernetes deployment and I am unable to get the deployment back into a running state because it can't reattach to the existing pv.

If I install it fresh, it just creates a new pvc withi a new pv. I want to use an existing pv (which has all my data) when I reinstall.

  primary:
    ## Enable persistence using Persistent Volume Claims
    ## ref: https://kubernetes.io/docs/user-guide/persistent-volumes/
    ## @param mariadb.primary.persistence.enabled Enable database persistence using PVC
    ## @param mariadb.primary.persistence.storageClass PVC Storage Class
    ## @param mariadb.primary.persistence.accessModes Persistent Volume Access Mode
    ## @param mariadb.primary.persistence.size Database Persistent Volume Size
    ## @param mariadb.primary.persistence.hostPath Host mount path for MariaDB volume
    ## @param mariadb.primary.persistence.existingClaim Enable persistence using an existing PVC
    ##
    persistence:
      enabled: true
      ## mariadb data Persistent Volume Storage Class
      ## If defined, storageClassName: <storageClass>
      ## If set to "-", storageClassName: "", which disables dynamic provisioning
      ## If undefined (the default) or set to null, no storageClassName spec is
      ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
      ##   GKE, AWS & OpenStack)
      ##
      storageClass: ""
      accessModes:
        - ReadWriteOnce
      size: 8Gi
      ## Set path in case you want to use local host path volumes (not recommended in production)
      ##
      hostPath: ""
      ## Use an existing PVC
      ##
      existingClaim: ""

I am assuming I can just use the existingClaim: parameter and put in the pvc name.

However, I don't know how to create a pvc from scratch.

Can somebody please help me figure out how to create a pvc using an existing pv which is sitting unattached currently? As long as I don't delete that pv, I am hoping my data is safe.

This is on the Linode Kubernetes cluster if it matters.

Nate Houk
  • 143
  • 7

1 Answers1

1

We can create a new pvc by using the existing pv without any data loss (PV must exist, will typically exist if the reclaim policy of storageclass is Retain)

Step -1 : ensure the pv is moved into Available state which will be changed after deleting PVC.

kubectl get pv <pv name>

There you can see you still have references from the old Namespace at the CLAIM column.

Edit the PV (kubectl edit pv <pv name>) and remove the spec.claimRef part. The PV claim would be unset and in the claim column you verify that will be changed into blank

Then use the PV by creating the new PVC as below.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name:test-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 16Gi
  volumeName: "<pv name>"

You can find more information in this blog.

  • Thank you so much. I was able to recover the data. – Nate Houk Dec 02 '22 at 19:40
  • Now you can use the PVC into [pods](https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/) or deployment, glad to hear that :) – Sai Chandra Gadde Dec 03 '22 at 04:20
  • So I got it to work on my 1.23 cluster. But then I upgraded to 1.24 and I found one of my deployments is not compatible. Now I am trying to downgrade to 1.23 but can't find the persistent volumes in the new cluster. Please see this new thread: https://serverfault.com/questions/1117248/recovering-a-persistent-volume-across-linode-k8s-clusters – Nate Houk Dec 04 '22 at 13:05