쿠버네티스

NFS를 사용하여 k8s에서 PV 동적 할당 해보기

황동리 2024. 10. 11. 16:42
반응형

이번에 해볼 것은 StorageClass를 NFS 서버로 정의하여 PV를 동적으로 할당 해보도록 하겠습니다.

 


 

먼저 Helm 차트를 사용하여 nfs-provisioner를 설치해줍니다.

 

1. 네임스페이스를 새로 생성

# kubectl create namespace nfs-provisioner

 

2. Helm repo 등록

# helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner

 

3. values.yaml 파일 수정

(https://artifacthub.io/packages/helm/nfs-subdir-external-provisioner/nfs-subdir-external-provisioner) 해당 URL에서 DEFAUTL VALUE 설정 값을 복사하여 수정 해줍니다.

replicaCount: 1   # Pod 갯수 조절
strategyType: Recreate

image:
  repository: registry.k8s.io/sig-storage/nfs-subdir-external-provisioner
  tag: v4.0.2
  pullPolicy: IfNotPresent
imagePullSecrets: []

nfs:
  server: <NFS 서버 IP 입력>
  path: /nfs-storage # 파일의 디렉터리 경로 지정
  mountOptions:
  volumeName: nfs-subdir-external-provisioner-root
  # Reclaim policy for the main nfs volume
  reclaimPolicy: Retain

# For creating the StorageClass automatically:
storageClass:
  create: true # 스토리지 클래스 생성 여부 확인

  # Set a provisioner name. If unset, a name will be generated.
  # provisionerName:

  # Set StorageClass as the default StorageClass
  # Ignored if storageClass.create is false
  defaultClass: false # 해당 스토리지 클래스를 기본으로 사용할 지 여부

  # Set a StorageClass name
  # Ignored if storageClass.create is false
  name: nfs-client # 스토리지 클래스 이름

  # Allow volume to be expanded dynamically
  allowVolumeExpansion: true # PV 생성 후 용량 변경 여부

  # Method used to reclaim an obsoleted volume
  reclaimPolicy: Delete # PVC 삭제 시, PV 삭제 할 지 여부

  # When set to false your PVs will not be archived by the provisioner upon deletion of the PVC.
  archiveOnDelete: true

  # If it exists and has 'delete' value, delete the directory. If it exists and has 'retain' value, save the directory.
  # Overrides archiveOnDelete.
  # Ignored if value not set.
  onDelete:

  # Specifies a template for creating a directory path via PVC metadata's such as labels, annotations, name or namespace.
  # Ignored if value not set.
  # PV 디렉터리가 생성될 위치 지정
  ex) 
  pathPattern: "${.PVC.namespace}/${.PVC.name}" # PVC 네임스페이스/PVC 이름 으로 경로 생성

  # Set access mode - ReadWriteOnce, ReadOnlyMany or ReadWriteMany
  accessModes: ReadWriteOnce # AceessMode 선택, PVC 생성할 때 선택한 설정과 동일 해야함

  # Set volume bindinng mode - Immediate or WaitForFirstConsumer
  volumeBindingMode: Immediate

  # Storage class annotations
  annotations: {}

leaderElection:
  # When set to false leader election will be disabled
  enabled: true

## For RBAC support:
rbac:
  # Specifies whether RBAC resources should be created
  create: true

# If true, create & use Pod Security Policy resources
# https://kubernetes.io/docs/concepts/policy/pod-security-policy/
podSecurityPolicy:
  enabled: false

# Deployment pod annotations
podAnnotations: {}

## Set pod priorityClassName
# priorityClassName: ""

podSecurityContext: {}

securityContext: {}

serviceAccount:
  # Specifies whether a ServiceAccount should be created
  create: true

  # Annotations to add to the service account
  annotations: {}

  # The name of the ServiceAccount to use.
  # If not set and create is true, a name is generated using the fullname template
  name:

resources: {}
  # limits:
  #  cpu: 100m
  #  memory: 128Mi
  # requests:
  #  cpu: 100m
  #  memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

# Additional labels for any resource created
labels: {}

podDisruptionBudget:
  enabled: false
  maxUnavailable: 1

 

원하시는 대로 values.yaml 파일의 내용을 수정을 한 후에 설치를 진행 해줍니다.

 

4. helm 설치 진행

# helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner -f values.yaml -n nfs-provisioner

 

5. Pod, StorageClass 정상 생성 확인

Pod가 정상적으로 생성이 되었는지 확인 해줍니다.

# kubectl get pods -n nfs-provisioner

 

스토리지 클래스가 정상적으로 생성 되었는지 확인 해줍니다.

# kubectl get storageclass

 

6. PV 동적으로 생성되는지 확인

PVC를 생성하여 PV가 동적으로 생성이 되는지 확인 해줍니다.

 

pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test004-pvc # 원하는 pvc 이름 설정
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Ti # 필요한 만큼 크기 설정 (ex. 1Mi, 1Gi, 1Ti)
  storageClassName: nfs-client  # 앞서 생성한 StorageClass의 이름 적을 것

 

앞서 생성한 storageClassName을 가지고 PVC를 생상하면 아래 이미지와 같이 해당하는 PV가 동적으로 생성 됩니다.

 

감사합니다.

반응형