将kubernetes保留的PVC重新连接到现有的azure磁盘

6jygbczu  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(93)

使用Azure CSI驱动程序v1.27.1,Kubernetes v1.23(无AKS,但通过牧场主引擎RKE)
我们“保留”了所有的PVC,我可以看到在删除PVC/PV后,Azure磁盘仍然在这里。没关系的。
但是现在,当再次创建相同的PVC/PV时,它将创建一个新的Azure磁盘,而不是使用现有的磁盘!
如何重新使用现有磁盘?
(我相信这是自动的,通过使用PVC命名空间/标签)。
我可以手动“附加”到现有磁盘,但语法并不方便:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-reclaim
  finalizers:
    - kubernetes.io/pv-protection
    - external-attacher/disk-csi-azure-com
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  claimRef:
    namespace: default
    name: test-reclaim
  storageClassName: azure-disk-retain
  volumeMode: Filesystem
  csi:
    driver: disk.csi.azure.com
    volumeHandle: /subscriptions/XXXXXX/resourceGroups/rg-XXXX/providers/Microsoft.Compute/disks/pvc-XXXXXX
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-reclaim
spec:
  storageClassName: azure-disk-retain
  volumeName: test-reclaim
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

字符串

hts6caw3

hts6caw31#

  • 您可以使用下面的yml代码来重用现有的azure磁盘。*
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: disk.csi.azure.com
  name: pv-azuredisk
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: managed-csi
  csi:
    driver: disk.csi.azure.com
    readOnly: false
    volumeHandle: /subscriptions/<subscriptionID>/resourceGroups/MC_myAKSCluster_myAKSCluster_eastus/providers/Microsoft.Compute/disks/myAKSDisk
    volumeAttributes:
      fsType: ext4
---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-azuredisk
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  volumeName: pv-azuredisk
  storageClassName: managed-csi

字符串
我在我的Kubernetes中应用了它:

kubectl apply -f pvc.yml


的数据


相关问题