EFS 파일 시스템 사용

Anthos clusters on AWS 버전 1.6 이상은 EFS CSI 드라이버를 통해 AWS Elastic File System(EFS)을 지원합니다. 이 주제에서는 사용자 클러스터에 기존 EFS 파일 시스템을 PersistentVolume으로 마운트하는 방법을 설명합니다.

시작하기 전에

이 주제의 단계를 수행하려면 다음이 필요합니다.

  • Anthos clusters on AWS 설치와 동일한 AWS VPC에 있는 기존 EFS 파일 시스템
  • Anthos clusters on AWS 설치와 동일한 AWS VPC에 있는 하나 이상의 EFS 마운트 대상
  • 모든 EFS 마운트 대상은 다음에 속해야 합니다.
    • Anthos clusters on AWS 설치의 비공개 서브넷. 기본적으로 Anthos clusters on AWS는 gke-CLUSTER_ID-private-AWS_ZONE이라는 서브넷을 만듭니다. 여기서 CLUSTER_ID는 사용자 클러스터 ID이고 AWS_ZONE은 AWS 가용성 영역입니다.
    • 노드 풀 보안 그룹. 기본적으로 Anthos clusters on AWS는 gke-CLUSTER_ID-nodepool이라는 노드 풀을 만듭니다. 여기서 CLUSTER_ID는 사용자 클러스터 ID입니다.
  • anthos-aws 디렉터리에서 anthos-gke를 사용하여 컨텍스트를 사용자 클러스터로 전환합니다.
    cd anthos-aws
    env HTTPS_PROXY=http://localhost:8118 \
      anthos-gke aws clusters get-credentials CLUSTER_NAME
    CLUSTER_NAME을 사용자 클러스터 이름으로 바꿉니다.

EFS PersistentVolume 사용

사용자 클러스터에서 EFS 파일 시스템을 PersistentVolume으로 사용하려면 먼저 PersistentVolume을 만든 다음 워크로드에서 참조하는 PersistentVolumeClaim을 만듭니다.

PersistentVolume 만들기

EFS CSI 드라이버를 사용하여 PersistentVolume을 만들려면 다음 단계를 수행합니다.

  1. anthos-aws 디렉터리에서 anthos-gke를 사용하여 컨텍스트를 사용자 클러스터로 전환합니다.

    cd anthos-aws
    env HTTPS_PROXY=http://localhost:8118 \
      anthos-gke aws clusters get-credentials CLUSTER_NAME
    CLUSTER_NAME을 사용자 클러스터 이름으로 바꿉니다.

  2. 사용하는 PersistentVolume 구성은 Elastic File System에 직접 연결하는지 또는 액세스 포인트를 통해 연결하는지에 따라 달라집니다. Elastic File System에 직접 연결할지 아니면 액세스 포인트를 통해 연결할지 선택합니다.

    직접 연결하기

    다음 YAML 매니페스트를 efs-volume.yaml이라는 파일에 복사합니다. 매니페스트는 이전에 만든 EFS 스토리지 클래스를 참조합니다.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: VOLUME_NAME
    spec:
      capacity:
        # Note: storage capacity is not used by the EFS CSI driver.
        # It is required by the PersistentVolume spec.
        storage: 5Gi
      volumeMode: Filesystem
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      storageClassName: "" # storageClassName is not required, see note in the following section.
      claimRef:
        name: CLAIM_NAME
        namespace: default
      csi:
        driver: efs.csi.aws.com
        volumeHandle: EFS_FILE_SYSTEM_ID
    

    다음을 바꿉니다.

    • VOLUME_NAME을 영구 볼륨의 이름으로 바꿉니다.
    • CLAIM_NAME을 PersistentVolumeClaim에 사용할 이름으로 바꿉니다.
    • EFS_FILE_SYSTEM_ID를 EFS 파일 시스템 ID로 바꿉니다. 예를 들면 fs-12345678a입니다.

    액세스 포인트

    다음 YAML 매니페스트를 efs-volume.yaml이라는 파일에 복사합니다. 매니페스트는 이전에 만든 EFS 스토리지 클래스를 참조합니다.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: VOLUME_NAME
    spec:
      capacity:
        # Note: storage capacity is not used by the EFS CSI driver.
        # It is required by the PersistentVolume spec.
        storage: 5Gi
      volumeMode: Filesystem
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      storageClassName: "" # storageClassName is not required, see note in the following section.
      claimRef:
        name: CLAIM_NAME
        namespace: default
      csi:
        driver: efs.csi.aws.com
        volumeHandle: EFS_FILE_SYSTEM_ID::ACCESS_POINT_ID
    

    다음을 바꿉니다.

    • VOLUME_NAME을 영구 볼륨의 이름으로 바꿉니다.
    • CLAIM_NAME을 PersistentVolumeClaim에 사용할 이름으로 바꿉니다.
    • EFS_FILE_SYSTEM_ID를 EFS 파일 시스템 ID로 바꿉니다. 예를 들면 fs-12345678a입니다.
    • ACCESS_POINT_ID를 액세스 포인트의 ID로 바꿉니다. 예를 들면 fsap-1234567890abcde입니다.
  3. YAML을 클러스터에 적용합니다.

    env HTTPS_PROXY=http://localhost:8118 \
      kubectl apply -f efs-volume.yaml
    

    출력에서 PersistentVolume의 생성을 확인합니다.

    persistentvolume/VOLUME_NAME created
    

PersistentVolumeClaim 만들기

워크로드에서 EFS 파일 시스템을 사용하려면 PersistentVolumeClaim을 만듭니다.

  1. PersistentVolumeClaim을 만들려면 다음 YAML 매니페스트를 efs-claim.yaml이라는 파일에 복사합니다.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: CLAIM_NAME
    spec:
      accessModes:
        - ReadWriteMany
      storageClassName: ""
      resources:
        requests:
          storage: 5Gi
    

    CLAIM_NAME을 PersistentVolumeClaim 이름으로 바꿉니다. 예를 들면 efs-claim1입니다.

  2. YAML을 클러스터에 적용합니다.

    env HTTPS_PROXY=http://localhost:8118 \
      kubectl apply -f efs-claim.yaml
    

    출력에서 PersistentVolumeClaim의 생성을 확인합니다.

    persistentvolumeclaim/CLAIM_NAME created
    

StatefulSet 만들기

PersistentVolumeClaim을 만든 후 워크로드에서 사용할 수 있습니다. 이 섹션의 단계에서는 EFS 파일 시스템이 마운트된 StatefulSet 예시를 만듭니다. spec.volumes에서 클레임을 참조하여 포드 및 배포와 같은 다른 워크로드 유형과 함께 PersistentVolumeClaim을 사용할 수도 있습니다.

PersistentVolumeClaim에서 참조되는 EFS 파일 시스템을 마운트하는 StatefulSet를 만들려면 다음 단계를 수행합니다.

  1. 다음 YAML 매니페스트를 efs-statefulset.yaml이라는 파일에 복사합니다. 이 예시 매니페스트는 /efs-data에 EFS 파일 시스템을 마운트하는 Ubuntu Linux 컨테이너를 실행합니다. 컨테이너는 5초마다 out.txt이라는 EFS 파일 시스템의 파일에 씁니다.

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: efs-shell
    spec:
      selector:
        matchLabels:
          app: test-efs
      serviceName: efs-app
      replicas: 1
      template:
        metadata:
          labels:
            app: test-efs
        spec:
          terminationGracePeriodSeconds: 10
          containers:
          - name: linux
            image: ubuntu:bionic
            command: ["/bin/sh"]
            args: ["-c", "while true; do echo $(date -u) >> /efs-data/out.txt; sleep 5; done"]
            volumeMounts:
            - name: efs-volume
              mountPath: /efs-data
          volumes:
          - name: efs-volume
            persistentVolumeClaim:
              claimName: CLAIM_NAME
    

    다음을 바꿉니다.

    • CLAIM_NAME을 이전에 지정한 PersistentVolumeClaim 이름으로 바꿉니다. 예를 들면 efs-claim1입니다.
  2. YAML을 클러스터에 적용합니다.

    env HTTPS_PROXY=http://localhost:8118 \
     kubectl apply -f efs-statefulset.yaml
    

    출력에서 StatefulSet의 생성을 확인합니다.

    statefulset.apps/efs-shell created
    

    StatefulSet는 컨테이너 이미지를 다운로드하고 실행하는 데 몇 분 정도 걸릴 수 있습니다.

  3. kubectl get pods로 StatefulSet의 포드가 Running 상태인지 확인합니다.

    env HTTPS_PROXY=http://localhost:8118 \
      kubectl get pods -l app=test-efs
    

    출력에는 포드 이름과 포드 상태가 포함됩니다. 다음 응답에서 포드의 이름은 efs-shell-0입니다.

    NAME          READY   STATUS    RESTARTS   AGE
    efs-shell-0   1/1     Running   0          1m
    
  4. 포드가 실행 중 상태가 되면 kubectl exec를 사용하여 StatefulSet를 호스팅하는 포드에 연결합니다.

    env HTTPS_PROXY=http://localhost:8118 \
      kubectl exec -it efs-shell-0 -- bash
    

    kubectl 명령어는 포드에서 셸을 실행합니다.

  5. EFS 파일 시스템이 마운트되었는지 확인하려면 tail 명령어를 사용하여 out.txt 파일의 콘텐츠를 확인합니다.

    tail /efs-data/out.txt
    

    출력에 UTC의 최근 시간이 포함됩니다.

  6. exit 명령어로 포드 연결을 해제합니다.

    exit
    

    셸이 로컬 머신으로 돌아갑니다.

  7. StatefulSet를 삭제하려면 kubectl delete를 사용합니다.

    env HTTPS_PROXY=http://localhost:8118 \
      kubectl delete -f efs-statefulset.yaml
    

삭제

이전 섹션에서 만든 리소스를 삭제하려면 다음 명령어를 실행합니다.

env HTTPS_PROXY=http://localhost:8118 \
  kubectl delete -f efs-statefulset.yaml
env HTTPS_PROXY=http://localhost:8118 \
  kubectl delete -f efs-claim.yaml
env HTTPS_PROXY=http://localhost:8118 \
  kubectl delete -f efs-volume.yaml

다음 단계