LoginSignup
1
1

More than 3 years have passed since last update.

OpenShiftの永続ボリュームを別ネームスペースにクローニング

Posted at

OpenShiftでPVC(PersistentVolumeClaim)の複製が可能なCSI volume cloningには、ソースとターゲットが同じネームスペースであるという制約があります。

The destination persistent volume claim (PVC) must exist in the same namespace as the source PVC.
CSI volume cloning

クローニングしたPVCを別のネームスペースで使えるようにするために必要な手順をまとめました。
環境:

  • OpenShift Container Platform V4.6.19
  • OpenShift Container Storage V4.6.3

Step1:Reclaim Policyの修正

PV(PersistentVolume)のReclaim PolicyがDeleteとなっている場合はRetainに変更します。
(動的プロビジョニングではReclaim PolicyがデフォルトでDeleteとなっているため、後続の手順でPVCを削除するとPVも削除されます。)

$ oc get pv | grep clone
pvc-00afceb6-fdd3-48f9-bc2a-6060a8791f2c   1Gi        RWX            Delete           Bound       test/clone-pvc01                                                ocs-storagecluster-cephfs              14m
pvc-6cd6a466-fc51-4871-ad9b-82133d281d49   1Gi        RWX            Delete           Bound       test/clone-pvc02                                                ocs-storagecluster-cephfs              37s

clone-pvc02でクローニングしたPVを別ネームスペースに移動させることにします。(test→test2)
oc patch pvでReclaim Policyを変更します。

$ oc patch pv pvc-6cd6a466-fc51-4871-ad9b-82133d281d49 -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
persistentvolume/pvc-6cd6a466-fc51-4871-ad9b-82133d281d49 patched

Delete→Retainに変更されたことを確認します。

$ oc get pv | grep clone
pvc-00afceb6-fdd3-48f9-bc2a-6060a8791f2c   1Gi        RWX            Delete           Bound       test/clone-pvc01                                                ocs-storagecluster-cephfs              15m
pvc-6cd6a466-fc51-4871-ad9b-82133d281d49   1Gi        RWX            Retain           Bound       test/clone-pvc02                                                ocs-storagecluster-cephfs              71s

Step2:ネームスペースとの紐付けを解除

clone-pvc02のPVCを削除します。

$ oc delete pvc clone-pvc02
persistentvolumeclaim "clone-pvc02" deleted

Retainに変更したのでPVは削除されずに残りますが、Releasedというステータスであり、クローニングされた時のネームスペースの情報が残ったままです。

$ oc get pv | grep clone
pvc-00afceb6-fdd3-48f9-bc2a-6060a8791f2c   1Gi        RWX            Delete           Bound       test/clone-pvc01                                                ocs-storagecluster-cephfs              16m
pvc-6cd6a466-fc51-4871-ad9b-82133d281d49   1Gi        RWX            Retain           Released    test/clone-pvc02                                                ocs-storagecluster-cephfs              98s

oc edit pvでclaimRefの部分を削除します。

$ oc edit pv pvc-6cd6a466-fc51-4871-ad9b-82133d281d49
抜粋
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 1Gi
  claimRef:                      ←削除
    apiVersion: v1                  ←削除
    kind: PersistentVolumeClaim          ←削除
    name: clone-pvc02                ←削除
    namespace: test                  ←削除
    resourceVersion: "20856763"          ←削除
    uid: 6cd6a466-fc51-4871-ad9b-82133d281d49   ←削除
  csi:
    controllerExpandSecretRef:

Released→Availableに変更されたことを確認します。

$ oc get pv | grep pvc-6cd6a466-fc51-4871-ad9b-82133d281d49
pvc-6cd6a466-fc51-4871-ad9b-82133d281d49   1Gi        RWX            Retain           Available                                                                     ocs-storagecluster-cephfs              6h39m

Step3:別ネームスペースでPVCを作成

PVを指定してPVC用のyamlファイルを作成します。

reuse-pvc02.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: reuse-pvc02
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: ocs-storagecluster-cephfs
  volumeName: pvc-6cd6a466-fc51-4871-ad9b-82133d281d49

クローニングしたデータを使用したいネームスペースに移動して、PVCを作成します。

$ oc create -f reuse-pvc02.yaml 
persistentvolumeclaim/reuse-pvc02 created

別のネームスペースでクローニングされたPVCを作成することができました。

$ oc get pv | grep pvc-6cd6a466-fc51-4871-ad9b-82133d281d49
pvc-6cd6a466-fc51-4871-ad9b-82133d281d49   1Gi        RWX            Retain           Bound       test2/reuse-pvc02                                               ocs-storagecluster-cephfs              6h53m

このようにStep1~3まで実施することで、CSI volume cloningでクローニングしたPVCを別のネームスペースで使用することができるようになります。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1