리전 영구 디스크 프로비저닝

이 페이지에서는 리전 영구 디스크의 동적 프로비저닝을 사용 설정하는 방법과 Google Kubernetes Engine(GKE)에서 수동으로 프로비저닝하는 방법을 설명합니다.

리전 영구 디스크

영역 영구 디스크와 마찬가지로 리전 영구 디스크를 필요에 따라 동적으로 프로비저닝하거나 클러스터 관리자가 사전에 수동으로 프로비저닝할 수 있지만 동적 프로비저닝이 권장됩니다.

동적 프로비저닝

리전 영구 디스크의 동적 프로비저닝을 사용 설정하려면 replication-type 매개변수로 StorageClass를 만들고 allowedTopologies에 영역 제약조건을 지정합니다.

예를 들어 다음 매니페스트는 표준 영구 디스크를 사용하고 europe-west1-beurope-west1-c 영역에 데이터를 복제하는 regionalpd-storageclass라는 이름의 StorageClass를 설명합니다.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: regionalpd-storageclass
provisioner: pd.csi.storage.gke.io
parameters:
  type: pd-balanced
  replication-type: regional-pd
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
  - key: topology.gke.io/zone
    values:
    - europe-west1-b
    - europe-west1-c

리전 클러스터를 사용하는 경우 allowedTopologies를 지정되지 않은 상태로 둘 수 있습니다. 이렇게 하면 이 StorageClass를 사용하는 PersistentVolumeClaim을 소비하는 pod를 만들 때 리전 영구 디스크가 두 영역으로 프로비저닝됩니다. 한 영역은 pod가 예약된 영역과 동일합니다. 다른 한 영역은 클러스터에서 사용할 수 있는 영역에서 무작위로 선택됩니다.

영역 클러스터를 사용할 때 allowedTopologies를 설정해야 합니다.

StorageClass가 생성되면 다음으로 storageClassName 필드를 사용하여 PersistentVolumeClaim 객체를 만들고 StorageClass를 참조합니다. 예를 들어 다음 매니페스트는 regional-pvc라는 이름의 PersistentVolumeClaim을 만들고 regionalpd-storageclass를 참조합니다.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: regional-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Gi
  storageClassName: regionalpd-storageclass

StorageClassvolumeBindingMode: WaitForFirstConsumer로 구성되어 있으므로 PersistentVolumeClaim을 사용하는 pod가 생성될 때까지 PersistentVolume이 프로비저닝되지 않습니다.

다음 매니페스트는 이전에 만든 PersistentVolumeClaim을 사용하는 pod의 예시입니다.

kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
        claimName: regional-pvc
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage

수동 프로비저닝

먼저 gcloud compute disks create 명령어를 사용하여 리전 영구 디스크를 만듭니다. 다음 예시에서는 europe-west1-beurope-west1-c 영역에 복제된 gce-disk-1이라는 디스크를 만듭니다.

gcloud compute disks create gce-disk-1 \
   --size 500Gi \
   --region europe-west1 \
   --replica-zones europe-west1-b,europe-west1-c

그런 다음, 방금 만든 리전 영구 디스크를 참조하는 PersistentVolume을 만들 수 있습니다. 기존 Persistent Disk를 PersistentVolume으로 사용의 객체 외에도 리전 영구 디스크의 PersistentVolumenode-affinity도 지정해야 합니다. StorageClass를 사용하는 경우 영구 디스크 CSI 드라이버를 지정해야 합니다.

다음은 표준 영구 디스크를 사용하고 europe-west1-beurope-west1-c 영역에 데이터를 복제하는 StorageClass 매니페스트의 예시입니다.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: regionalpd-storageclass
provisioner: pd.csi.storage.gke.io
parameters:
  type: pd-balanced
  replication-type: regional-pd
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
  - key: topology.gke.io/zone
    values:
    - europe-west1-b
    - europe-west1-c

다음은 pv-demo라는 PersistentVolume을 만들고 regionalpd-storageclass를 참조하는 매니페스트의 예시입니다.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-demo
spec:
  storageClassName: "regionalpd-storageclass"
  capacity:
     storage: 500Gi
  accessModes:
     - ReadWriteOnce
  claimRef:
    namespace: default
    name: pv-claim-demo
  csi:
    driver: pd.csi.storage.gke.io
    volumeHandle: projects/PROJECT_ID/regions/europe-west1/disks/gce-disk-1
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
          - key: topology.gke.io/zone
            operator: In
            values:
               - europe-west1-b
               - europe-west1-c

PersistentVolume 예시는 다음을 참조하세요.

  • volumeHandle 필드에는 PROJECT_ID를 비롯한 gcloud compute disks create 호출의 세부정보가 포함됩니다.
  • default로 설정된 경우에도 claimRef.namespace 필드를 지정해야 합니다.

영구 디스크 이름 지정

Kubernetes는 동일한 이름을 가진 영역 영구 디스크와 리전 영구 디스크를 구분할 수 없습니다. 이 문제를 해결하려면 영구 디스크에 고유한 이름을 지정해야 합니다. 동적으로 프로비저닝된 영구 디스크를 사용하는 경우에는 이 문제가 발생하지 않습니다.

다음 단계