콘텐츠로 이동

Kubernetes Storage 구성 요소 배포

개요

nfs-subdir-external-provisioner는 Kubernetes에 동적으로 PV 볼륨을 제공할 수 있으며, Kubernetes용 간편한 NFS 외부 프로비저너입니다. 자체적으로 NFS를 제공하지 않으며, 기존 NFS 서버가 스토리지를 제공해야 합니다. 퍼시스턴트 볼륨 디렉터리의 이름 규칙은 ${namespace}-${pvcName}-${pvName}입니다.

Kubernetes nfs-subdir-external-provisioner 구성 요소 배포 참고: https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner

전제 조건

  • NFS 서비스가 배포되어 있어야 합니다. 배포되지 않은 경우 NFS 배포를 참고하세요.
  • Kubernetes 클러스터가 배포되어 있어야 합니다. 배포되지 않은 경우 Kubernetes 배포를 참고하세요.
  • (선택 사항) Helm 도구가 배포되어 있어야 합니다. 배포되지 않은 경우 Helm 설치를 참고하세요.

기본 정보 및 호환성

NFS IP NFS 경로 StorageClass 이름 설명
192.168.100.105 /nfsdata df-nfs-storage 배포 시 실제 상황에 맞게 구성 수정 필요
이름 버전 오프라인 배포 지원 지원 아키텍처 지원 클러스터 버전
nfs-subdir-external-provisioner 4.0.16 amd64/arm64 1.18+

배포 단계

1. Kubernetes nfs-subdir-external-provisioner 배포

참고

Kubernetes 모든 노드에 nfs-utils가 설치되어 있어야 합니다. 설치되지 않은 경우 다음 명령을 실행하세요:

yum install -y nfs-utils

다음 명령을 실행하여 설치합니다:

helm install nfs-provisioner nfs-subdir-external-provisioner \
    --repo https://pubrepo.guance.com/chartrepo/dataflux-chart \
    --set nfs.server=192.168.100.105 \
    --set nfs.path=/nfsdata \
    --set storageClass.name=df-nfs-storage \
    -n kube-system 
참고

nfs.server는 NFS 주소, nfs.path는 경로이므로 혼동하지 않도록 주의하세요.

다음 YAML에서 하이라이트된 부분을 수정하고 배포하세요.

nfs-provisioner.yaml (클릭하여 펼치기)
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: kube-system
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: kube-system
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: kube-system
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: kube-system
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: dyrnq/nfs-subdir-external-provisioner:v4.0.2
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: k8s-sigs.io/nfs-subdir-external-provisioner
            - name: NFS_SERVER
              value: 192.168.100.105   # 실제 NFS 서버 주소 입력
            - name: NFS_PATH
              value: /nfsdata   # 실제 공유 디렉터리
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.100.105 # 실제 NFS 서버 주소 입력
            path: /nfsdata  # 실제 공유 디렉터리
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: df-nfs-storage
  annotations:
    storageclass.beta.kubernetes.io/is-default-class: "true"  # 해당 StorageClass를 기본값으로 설정
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
allowVolumeExpansion: true 
reclaimPolicy: Delete
parameters:
  archiveOnDelete: "false"            

다음 명령을 실행하여 설치합니다:

kubectl apply -f nfs-provisioner.yaml

2. 배포 확인

2.1 Pod 상태 확인

$ kubectl get pod -n kube-system | grep nfs-provisione

nfs-provisioner-nfs-subdir-external-provisioner-79d448b5d7tbp7v   1/1     Running   0          3d5h

2.2 PVC 생성

다음 명령을 실행하여 PVC를 생성합니다.

$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: cfs-pvc001
spec:
 accessModes:
   - ReadWriteOnce
 resources:
   requests:
     storage: 1Gi
 storageClassName: df-nfs-storage
EOF

2.3 PVC 상태 확인

$ kubectl get pvc | grep cfs-pvc001

cfs-pvc001       Bound    pvc-a17a0e50-04d2-4ee0-908d-bacd8d53aaa4   1Gi        RWO            df-nfs-storage           3d7h

Bound 상태는 배포 성공을 의미합니다.

제거 방법

helm uninstall -n kube-system nfs-provisioner
kubectl delete -f nfs-provisioner.yaml

문서 평가

이 페이지가 도움이 되었나요?