아티팩트 (Artifacts)
워크플로우를 실행하다 보면 어떤 스텝은 결과물을 만들고, 다른 스텝은 그 결과물을 가져다 쓰는 일이 아주 흔해요. 이 문서는 아티팩트를 만들고 전달하는 기본 예제부터 보관(archive) 전략, 파일 권한, 가비지 컬렉션, 보안까지 아티팩트를 다루는 핵심을 짚어 줘요.
본문
!!! Note 아티팩트 예제를 실행하려면 아티팩트 저장소 구성을 먼저 해 둬야 해요.
기본 예제 (Basic Example)
워크플로우를 실행하다 보면 아티팩트를 생성하거나 소비하는 스텝이 등장하는 일이 아주 흔해요. 한 스텝의 출력 아티팩트가 뒤이은 스텝의 입력 아티팩트로 쓰이는 경우가 많죠.
아래 워크플로우 스펙은 순서대로 실행되는 두 스텝으로 이루어져 있어요. generate-artifact라는 이름의 첫 번째 스텝이 hello-world-to-file 템플릿으로 아티팩트를 만들고, 두 번째 스텝 print-message-from-file이 만들어진 아티팩트를 소비해요.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-passing-
spec:
entrypoint: artifact-example
templates:
- name: artifact-example
steps:
- - name: generate-artifact
template: hello-world-to-file
- - name: consume-artifact
template: print-message-from-file
arguments:
artifacts:
# bind message to the hello-art artifact
# generated by the generate-artifact step
- name: message
from: "{{steps.generate-artifact.outputs.artifacts.hello-art}}"
- name: hello-world-to-file
container:
image: busybox
command: [sh, -c]
args: ["echo hello world | tee /tmp/hello_world.txt"]
outputs:
artifacts:
# generate hello-art artifact from /tmp/hello_world.txt
# artifacts can be directories as well as files
- name: hello-art
path: /tmp/hello_world.txt
- name: print-message-from-file
inputs:
artifacts:
# unpack the message input artifact
# and put it at /tmp/message
- name: message
path: /tmp/message
container:
image: alpine:3.23
command: [sh, -c]
args: ["cat /tmp/message"]
이 워크플로우에서는:
hello-world-to-file템플릿이echo명령으로/tmp/hello-world.txt라는 이름의 파일을 만들어요.hello-world-to-file템플릿이 이 파일을hello-art라는 이름의 아티팩트로outputs해요. 일반적으로 아티팩트의path는 파일 하나가 아니라 디렉터리여도 돼요.print-message-from-file템플릿이message라는 입력 아티팩트를 받아path에 지정된/tmp/message에 풀어 놓고,cat명령으로/tmp/message내용을 출력해요.artifact-example템플릿이generate-artifact스텝의 출력으로 만들어진hello-art아티팩트를print-message-from-file스텝의message입력 아티팩트로 전달해요. DAG 템플릿은 tasks 접두사로 다른 태스크를 참조하는데, 예를 들어{{tasks.generate-artifact.outputs.artifacts.hello-art}}처럼 써요.
아티팩트가 크다면 선택적으로 워크플로우 스펙에 podSpecPatch를 설정해 init 컨테이너의 리소스 요청을 늘리고 Out of memory 문제를 피할 수 있어요.
# <... snipped ...>
- name: large-artifact
# below patch gets merged with the actual pod spec and increases the memory
# request of the init container.
podSpecPatch: |
initContainers:
- name: init
resources:
requests:
memory: 2Gi
cpu: 300m
inputs:
artifacts:
- name: data
path: /tmp/large-file
container:
image: alpine:3.23
command: [sh, -c]
args: ["cat /tmp/large-file"]
# <... snipped ...>
파일 동작 설정하기 (Setting File Behavior)
보관 전략 (Archive Strategy)
아티팩트는 기본적으로 타르볼(tarball)로 묶인 뒤 gzip으로 압축돼요. archive 필드로 보관 전략(archive strategy)을 지정해 이 동작을 바꿀 수 있어요. 예를 들면:
# <... snipped ...>
outputs:
artifacts:
# default behavior - tar+gzip default compression.
- name: hello-art-1
path: /tmp/hello_world.txt
# disable archiving entirely - upload the file / directory as is.
# this is useful when the container layout matches the desired target repository layout.
- name: hello-art-2
path: /tmp/hello_world.txt
archive:
none: {}
# customize the compression behavior (disabling it here).
# this is useful for files with varying compression benefits,
# e.g. disabling compression for a cached build workspace and large binaries,
# or increasing compression for "perfect" textual data - like a json/xml export of a large database.
- name: hello-art-3
path: /tmp/hello_world.txt
archive:
tar:
# no compression (also accepts the standard gzip 1 to 9 values)
compressionLevel: 0
# <... snipped ...>
파일 권한 (mode)
입력 파일의 mode를 지정해 두면 컨테이너 코드가 항상 기대한 대로(읽기/쓰기/실행) 파일을 다룰 수 있어서 좋은 습관이에요. 이 글이 파일 권한과 8진수 값을 설명해 줘요.
예를 들어 사용자가 /bin/kubectl을 실행할 수 있게 하려면 mode: 0755로 설정해요.
# <... snipped ...>
templates:
- name: executable-artifact
inputs:
artifacts:
# Download kubectl 1.8.0 and place it at /bin/kubectl
- name: kubectl
path: /bin/kubectl
mode: 0755
http:
url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl
# <... snipped ...>
!!! Note
0755는 YAML 형식의 8진수 값이에요(YAML 스펙 1.2에서는 0o755도 허용돼요). Kubernetes API가 8진수 mode 값을 받아 검증하면 10진수로 저장돼요. 그래서 클러스터의 YAML에서, 그리고 Argo UI에서도 mode: 493으로 보여요. 10진수 493은 8진수 0755와 같으니 파일 권한은 여전히 올바르게 적용돼요.
아티팩트 가비지 컬렉션 (Artifact Garbage Collection)
버전 3.4부터는 필요 없어진 아티팩트를 워크플로우가 자동으로 삭제하도록 구성할 수 있어요(현재 지원되는 저장소 엔진은 아티팩트 저장소 기능을 확인하세요).
아티팩트는 OnWorkflowCompletion 또는 OnWorkflowDeletion 시점에 삭제될 수 있어요. 가비지 컬렉션 전략은 워크플로우 수준과 아티팩트 수준 양쪽에 지정할 수 있어서, 예를 들어 바로 지워도 되는 임시 아티팩트와 남겨 둬야 할 최종 출력을 섞어 쓸 수 있어요:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-gc-
spec:
entrypoint: main
artifactGC:
strategy: OnWorkflowDeletion # default Strategy set here applies to all Artifacts by default
templates:
- name: main
container:
image: argoproj/argosay:v2
command:
- sh
- -c
args:
- |
echo "can throw this away" > /tmp/temporary-artifact.txt
echo "keep this" > /tmp/keep-this.txt
outputs:
artifacts:
- name: temporary-artifact
path: /tmp/temporary-artifact.txt
s3:
key: temporary-artifact.txt
- name: keep-this
path: /tmp/keep-this.txt
s3:
key: keep-this.txt
artifactGC:
strategy: Never # optional override for an Artifact
아티팩트 이름 짓기 (Artifact Naming)
같은 스펙의 워크플로우가 동시에 여러 개 실행될 가능성이 있다면, 위 예제처럼 S3 키를 {{workflow.uid}} 등으로 파라미터화하는 걸 고려하세요. 그렇지 않으면 한 워크플로우의 아티팩트가 삭제되는 동안 같은 S3 키가 다른 워크플로우를 위해 만들어지는 상황이 생길 수 있어요.
디렉터리 전체를 S3 키로 쓰는 경우라면 키 값에 특히 주의하세요. 두 가지 예가 있어요:
- (A) 기본 보관 옵션을 none으로 바꿀 때는 키가 반드시 "/"로 끝나야 해요. 그렇지 않으면 S3에는 디렉터리가 만들어지지만 GC 파드가 그 디렉터리를 지우지 못해요.
- (B) 기본 보관 옵션인
.tgz를 그대로 쓸 때는 반대로 키가 "/"로 끝나면 안 돼요. 그렇지 않으면 Argo가 보관 파일(archive file)을 만들지 못해요.
.tgz로 묶지 않는 예제 (A)
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-gc-dir-key-
spec:
entrypoint: main
artifactGC:
strategy: OnWorkflowDeletion # default Strategy set here applies to all Artifacts by default
templates:
- name: main
container:
image: argoproj/argosay:v2
command:
- sh
- -c
args:
- |
mkdir /tmp/tmp-directory
echo "can throw this away" > /tmp/tmp-directory/delete-this.txt
echo "and this too" > /tmp/tmp-directory/delete-this-too.txt
outputs:
artifacts:
- name: temporary-artifact
path: /tmp/tmp-directory
archive:
# Avoid having tgz file.
none: {}
s3:
key: "{{workflow.name}}/directory/" # IMPORTANT! ends with "/"
.tgz로 묶는 예제 (B)
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-gc-dir-key-
spec:
entrypoint: main
artifactGC:
strategy: OnWorkflowDeletion # default Strategy set here applies to all Artifacts by default
templates:
- name: main
container:
image: argoproj/argosay:v2
command:
- sh
- -c
args:
- |
mkdir /tmp/tmp-directory
echo "can throw this away" > /tmp/tmp-directory/delete-this.txt
echo "and this too" > /tmp/tmp-directory/delete-this-too.txt
outputs:
artifacts:
- name: temporary-artifact
path: /tmp/tmp-directory
archive:
tar:
compressionLevel: 1
s3:
key: "{{workflow.name}}/archive.tgz" # IMPORTANT! must not end with "/"
서비스 어카운트와 어노테이션 (Service Accounts and Annotations)
S3 버킷 때문에 특별한 서비스 어카운트나 IAM 롤 어노테이션을 붙여서 실행해야 하나요? 아티팩트를 만들 때 쓰는 것과 같은 것을 쓰거나, 삭제 권한만 가진 새 어카운트를 만들 수도 있어요. 보통은 워크플로우의 모든 아티팩트에 적용할 서비스 어카운트나 IAM 롤 하나면 충분하지만, 필요하다면 아티팩트 수준에서 따로 지정할 수도 있어요:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-gc-
spec:
entrypoint: main
artifactGC:
strategy: OnWorkflowDeletion
##############################################################################################
# Workflow Level Service Account and Metadata
##############################################################################################
serviceAccountName: my-sa
podMetadata:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/my-iam-role
templates:
- name: main
container:
image: argoproj/argosay:v2
command:
- sh
- -c
args:
- |
echo "can throw this away" > /tmp/temporary-artifact.txt
echo "keep this" > /tmp/keep-this.txt
outputs:
artifacts:
- name: temporary-artifact
path: /tmp/temporary-artifact.txt
s3:
key: temporary-artifact-{{workflow.uid}}.txt
artifactGC:
####################################################################################
# Optional override capability
####################################################################################
serviceAccountName: artifact-specific-sa
podMetadata:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/artifact-specific-iam-role
- name: keep-this
path: /tmp/keep-this.txt
s3:
key: keep-this-{{workflow.uid}}.txt
artifactGC:
strategy: Never
자기만의 서비스 어카운트를 쓴다면, 그 어카운트를 아래 같은 롤과 묶는 RoleBinding을 만들어야 해요:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
annotations:
workflows.argoproj.io/description: |
This is the minimum recommended permissions needed if you want to use artifact GC.
name: artifactgc
rules:
- apiGroups:
- argoproj.io
resources:
- workflowartifactgctasks
verbs:
- list
- watch
- apiGroups:
- argoproj.io
resources:
- workflowartifactgctasks/status
verbs:
- patch
quick-start 매니페스트 파일 중 하나로 설치했다면 이것이 artifactgc 롤이에요. 릴리스의 install.yaml 파일로 설치했다면 같은 권한이 argo-cluster-role에 들어 있어요.
자기만의 ServiceAccount를 쓰지 않고 default 서비스 어카운트만 쓴다면, 그 롤에 default 서비스 어카운트로 가는 RoleBinding이나 ClusterRoleBinding이 필요해요.
가비지 컬렉션이 실패하면 어떻게 되나요? (What happens if Garbage Collection fails?)
어떤 이유로든 아티팩트 삭제가 실패하면(이미 삭제된 아티팩트는 실패로 치지 않아요) 워크플로우 상태에 "Artifact GC Failure"라는 새 Condition이 표시되고, Kubernetes 이벤트가 발행되며, Argo Server UI에도 실패가 표시돼요. 추가로 디버깅하려면 <wfName>-artgc-* 이름의 파드를 한 개 이상 찾아 로그를 보면 돼요.
컨트롤러가 아티팩트 GC를 아예 시작하지 못하는 경우, 예를 들어 GC 파드가 어드미션 웹훅에 막히거나 Kubernetes API를 쓸 수 없는 경우에도 같은 Condition과 이벤트를 기록하고 이후 리컨실레이션 때 재시도해요. 워크플로우가 완료(또는 OnWorkflowDeletion의 경우 삭제)된 지 ARGO_ARTIFACT_GC_RETRY_WINDOW(기본 60분, 환경 변수 참고)보다 오래될 때까지 재시도를 계속하고, 그 시점이 지나면 전략을 포기하며 Condition에 그 사실이 표시돼요. 워크플로우가 아무리 오래됐어도 컨트롤러가 발견하면 최소 한 번은 시도해요.
사용자가 워크플로우와 그 자식 CRD 객체를 직접 지워야 한다면, 삭제를 막고 있는 finalizer를 워크플로우에서 패치로 제거해야 해요:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
finalizers:
- workflows.argoproj.io/artifact-gc
finalizer는 이렇게 지울 수 있어요:
kubectl patch workflow my-wf \
--type json \
--patch='[ { "op": "remove", "path": "/metadata/finalizers" } ]'
또는 간단히 Argo CLI의 argo delete 명령에 --force 플래그를 쓰세요. 내부적으로 finalizer를 제거한 뒤 삭제를 진행해 줘요.
릴리스 버전 3.5 이상 (Release Versions >= 3.5)
Artifact GC가 실패하더라도 finalizer를 강제로 제거하는 forceFinalizerRemoval 플래그가 워크플로우 스펙에 새로 생겼어요(여기 참고). 실행됐지만 실패한 GC 파드와, 컨트롤러가 아예 시작하지 못해 포기한 전략 모두를 커버해요:
spec:
artifactGC:
strategy: OnWorkflowDeletion
forceFinalizerRemoval: true
보안 (Security)
워크플로우에 제공하는 크리덴셜이, 사용자가 접근할 수 있기를 원하는 아티팩트에만 접근을 허용하도록 제한하는지 꼭 확인하세요.
Argo Workflows는 경로 탐색(path traversal)을 명시적으로 허용하기 때문에 "../"가 포함된 키로 사용자가 "디렉터리 구조"를 거슬러 올라갈 수 있어요.
더 알아보기 (Learn more)
- 아티팩트가 크면
podSpecPatch로 init 컨테이너의 메모리 요청을 늘려 Out of memory를 피하세요. - 동시에 여러 워크플로우가 돌 가능성이 있다면 S3 키를 {{workflow.uid}} 등으로 파라미터화해 충돌을 막으세요.
- GC 실패 시에는
<wfName>-artgc-*파드 로그와 워크플로우 Condition, Kubernetes 이벤트를 확인하세요.