大网数据广告活动
服务器运维问答

How to create pvc using existing pv?

· 52CE 我爱测

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 n…

问题原文

原帖链接 · Nate Houk · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Sai Chandra Gadde · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-12-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。