본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

볼륨 (Volumes)

원문 보기 위키 갱신

워크플로의 단계 사이에서 대용량 데이터를 전달할 때 볼륨이 가장 유용한 도구입니다. 이 문서에서는 워크플로 안에서 볼륨을 동적으로 생성하는 방법, 이미 존재하는 PVC를 재사용하는 방법, 그리고 템플릿 수준에서 볼륨을 선언하는 방법을 예제와 함께 살펴봅니다.

출처: Argo Workflows 문서

본문

다음 예제는 볼륨을 동적으로 생성한 뒤, 두 단계로 구성된 워크플로에서 그 볼륨을 사용하는 방법을 보여줍니다.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: volumes-pvc-
spec:
  entrypoint: volumes-pvc-example
  volumeClaimTemplates:                 # define volume, same syntax as k8s Pod spec
  - metadata:
      name: workdir                     # name of volume claim
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi                  # Gi => 1024 * 1024 * 1024

  templates:
  - name: volumes-pvc-example
    steps:
    - - name: generate
        template: hello-world-to-file
    - - name: print
        template: print-message-from-file

  - name: hello-world-to-file
    container:
      image: busybox
      command: [sh, -c]
      args: ["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"]
      # Mount workdir volume at /mnt/vol before invoking the container
      volumeMounts:                     # same syntax as k8s Pod spec
      - name: workdir
        mountPath: /mnt/vol

  - name: print-message-from-file
    container:
      image: alpine:3.23
      command: [sh, -c]
      args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]
      # Mount workdir volume at /mnt/vol before invoking the container
      volumeMounts:                     # same syntax as k8s Pod spec
      - name: workdir
        mountPath: /mnt/vol

볼륨은 워크플로의 한 단계에서 다른 단계로 대량의 데이터를 옮길 때 매우 유용한 방법입니다. 시스템에 따라서는 여러 단계에서 동시에 접근할 수 있는 볼륨도 있습니다.

어떤 경우에는 볼륨을 동적으로 만들었다 지웠다 하기보다, 이미 존재하는 볼륨에 접근하고 싶을 때가 있습니다.

# Define Kubernetes PVC
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: my-existing-volume
spec:
  accessModes: [ "ReadWriteOnce" ]
  resources:
    requests:
      storage: 1Gi

---
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: volumes-existing-
spec:
  entrypoint: volumes-existing-example
  volumes:
  # Pass my-existing-volume as an argument to the volumes-existing-example template
  # Same syntax as k8s Pod spec
  - name: workdir
    persistentVolumeClaim:
      claimName: my-existing-volume

  templates:
  - name: volumes-existing-example
    steps:
    - - name: generate
        template: hello-world-to-file
    - - name: print
        template: print-message-from-file

  - name: hello-world-to-file
    container:
      image: busybox
      command: [sh, -c]
      args: ["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"]
      volumeMounts:
      - name: workdir
        mountPath: /mnt/vol

  - name: print-message-from-file
    container:
      image: alpine:3.23
      command: [sh, -c]
      args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]
      volumeMounts:
      - name: workdir
        mountPath: /mnt/vol

워크플로 수준이 아니라 템플릿 수준에서 기존 볼륨을 선언하는 것도 가능합니다. 또한 워크플로는 resource 단계를 이용해 볼륨을 생성할 수도 있습니다.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: template-level-volume-
spec:
  entrypoint: generate-and-use-volume
  templates:
  - name: generate-and-use-volume
    steps:
    - - name: generate-volume
        template: generate-volume
        arguments:
          parameters:
            - name: pvc-size
              # In a real-world example, this could be generated by a previous workflow step.
              value: '1Gi'
    - - name: generate
        template: hello-world-to-file
        arguments:
          parameters:
            - name: pvc-name
              value: '{{steps.generate-volume.outputs.parameters.pvc-name}}'
    - - name: print
        template: print-message-from-file
        arguments:
          parameters:
            - name: pvc-name
              value: '{{steps.generate-volume.outputs.parameters.pvc-name}}'

  - name: generate-volume
    inputs:
      parameters:
        - name: pvc-size
    resource:
      action: create
      setOwnerReference: true
      manifest: |
        apiVersion: v1
        kind: PersistentVolumeClaim
        metadata:
          generateName: pvc-example-
        spec:
          accessModes: ['ReadWriteOnce', 'ReadOnlyMany']
          resources:
            requests:
              storage: '{{inputs.parameters.pvc-size}}'
    outputs:
      parameters:
        - name: pvc-name
          valueFrom:
            jsonPath: '{.metadata.name}'

  - name: hello-world-to-file
    inputs:
      parameters:
        - name: pvc-name
    volumes:
      - name: workdir
        persistentVolumeClaim:
          claimName: '{{inputs.parameters.pvc-name}}'
    container:
      image: busybox
      command: [sh, -c]
      args: ["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"]
      volumeMounts:
      - name: workdir
        mountPath: /mnt/vol

  - name: print-message-from-file
    inputs:
        parameters:
          - name: pvc-name
    volumes:
      - name: workdir
        persistentVolumeClaim:
          claimName: '{{inputs.parameters.pvc-name}}'
    container:
      image: alpine:3.23
      command: [sh, -c]
      args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]
      volumeMounts:
      - name: workdir
        mountPath: /mnt/vol

더 알아보기 (Learn more)

  • volumeClaimTemplates는 워크플로와 운명을 같이 하는 임시 PVC를 만들고, volumes 필드는 이미 존재하는 PVC를 재사용합니다. 두 방식의 차이를 기억해 두세요.
  • 템플릿 수준에서 볼륨을 선언하면 단계마다 서로 다른 볼륨을 붙일 수 있어 재사용성이 높아집니다.
  • resource 템플릿으로 PVC를 생성하고 출력 파라미터로 PVC 이름을 넘기는 패턴은 동적 스토리지 프로비저닝에 자주 활용됩니다.