본문 바로가기
클라우드/Azure

[Kubernetes] Static Volume으로 다중 클러스터 Persistent Volume 연동

by worldcenter 2025. 1. 23.

 

보통 Azure를 사용할 때 1개 클러스터에서 동적으로 볼륨을 할당받아 사용한다. 하지만 특수한 경우에 다중 클러스터에서 동일한 스토리지를 마운트하여 사용해야 하는 경우가 존재한다. Azure에서는 정적 볼륨을 사용하여 해당 문제를 해결할 수 있다.

 

테스트 환경

  • 스토리지 스펙 : Standard_ZRS General_v2 Storage Account
  • 클러스터 스펙 : Azure Kubernetes 1.27.3

 

테스트

1. 볼륨으로 사용할 Strage Account Container를 하나 생성합니다.

 

2. 생성한 Storage Account 액세스 키를 토대로 Kubernetes Secret을 생성합니다.

kubectl create secret generic azure-storage-account-secret --from-literal azurestorageaccountname=NAME --from-literal azurestorageaccountkey="KEY" --type=Opaque

 

3. Storage Class 를 생성합니다.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: <StorageClassName>
provisioner: blob.csi.azure.com
parameters:
  resourceGroup: <ResourceGroup>
  storageAccount: <StorageAccountName>
  server: <StorageAccountDNS>
  skuName: Standard_ZRS  # available values: Standard_LRS, Premium_LRS, Standard_GRS, Standard_RAGRS, Standard_ZRS, Premium_ZRS
reclaimPolicy: Retain
volumeBindingMode: Immediate
allowVolumeExpansion: true
mountOptions:
  - -o allow_other
  - --file-cache-timeout-in-seconds=120
  - --use-attr-cache=true
  - --cancel-list-on-mount-seconds=10  # prevent billing charges on mounting
  - -o attr_timeout=120
  - -o entry_timeout=120
  - -o negative_timeout=120
  - --log-level=LOG_WARNING  # LOG_WARNING, LOG_INFO, LOG_DEBUG
  - --cache-size-mb=1000  # Default will be 80% of available memory, eviction will happen beyond that.

 

4. PersistentVolume을 생성합니다.

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: blob.csi.azure.com
  name: <PersistentVolumeName>
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain  # If set as "Delete" container would be removed after pvc deletion
  storageClassName: <StorageClassName>
  mountOptions:
    - -o allow_other
    - --file-cache-timeout-in-seconds=120
  csi:
    driver: blob.csi.azure.com
    readOnly: false
    # volumeid has to be unique for every identical storage blob container in the cluster
    # character `#`and `/` are reserved for internal use and cannot be used in volumehandle
    volumeHandle: unique-volumeid
    volumeAttributes:
      containerName: <ContainerName>
    nodeStageSecretRef:
      name: <SecretName>
      namespace: <SecretNamespace>

 

5. PersistentVolumeClaim을 생성합니다.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: <PersistentVolumeClaimName>
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  volumeName: <PersistentVolumeName>
  storageClassName: <StorageClassName>

 

6. 상기 작업을 다중 클러스터 내에서 동일하게 진행하면 1개 PV를 다중 클러스터가 사용 가능합니다.

 

 

참고 링크

https://learn.microsoft.com/ko-kr/azure/aks/azure-csi-blob-storage-provision?tabs=mount-blobfuse%2Csecret#statically-provision-a-volume

 

AKS(Azure Kubernetes Service)에서 Azure Blob Storage로 영구 볼륨 만들기 - Azure Kubernetes Service

AKS(Azure Kubernetes Service)에서 여러 Pod에 동시 사용하기 위해 Azure Blob Storage로 정적 또는 동적 영구 볼륨을 만드는 방법을 알아봅니다.

learn.microsoft.com