Kubernetes 리소스 (Kubernetes Resources)
resource 템플릿을 사용하면 Argo 워크플로에서 직접 Kubernetes 리소스를 생성, 삭제, 갱신할 수 있습니다. CRD를 포함한 임의의 k8s 매니페스트를 다루는 방법과 mergeStrategy 옵션을 살펴봅니다.
본문
많은 경우 Argo 워크플로에서 Kubernetes 리소스를 관리하고 싶을 것입니다. resource 템플릿은 어떤 타입의 Kubernetes 리소스든 생성, 삭제 또는 갱신할 수 있게 해 줍니다.
# in a workflow. The resource template type accepts any k8s manifest
# (including CRDs) and can perform any `kubectl` action against it (e.g. create,
# apply, delete, patch).
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: k8s-jobs-
spec:
entrypoint: pi-tmpl
templates:
- name: pi-tmpl
resource: # indicates that this is a resource template
action: create # can be any kubectl action (e.g. create, delete, apply, patch)
# The successCondition and failureCondition are optional expressions.
# If failureCondition is true, the step is considered failed.
# If successCondition is true, the step is considered successful.
# They use kubernetes label selection syntax and can be applied against any field
# of the resource (not just labels). Multiple AND conditions can be represented by comma
# delimited expressions.
# For more details: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
successCondition: status.succeeded > 0
failureCondition: status.failed > 3
manifest: | #put your kubernetes spec here
apiVersion: batch/v1
kind: Job
metadata:
generateName: pi-job-
spec:
template:
metadata:
name: pi
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
참고:
현재 리소스 템플릿은 단일 리소스만 관리할 수 있으므로, 리소스의 메타데이터에 generateName 또는 name이 반드시 제공되어야 합니다.
이렇게 생성된 리소스는 워크플로와 독립적입니다. 워크플로가 삭제될 때 리소스도 함께 삭제되기를 원한다면, 워크플로 리소스를 오너 참조(owner reference)로 삼는 Kubernetes 가비지 컬렉션을 사용할 수 있습니다(예제).
출력 파라미터로 리소스에 대한 데이터를 수집할 수도 있습니다 (자세한 내용은 k8s-jobs.yaml 참고)
참고:
패칭(patch) 시 리소스는 mergeStrategy라는 또 다른 속성을 받을 수 있으며, 값은 strategic, merge, json 중 하나입니다. 이 속성이 제공되지 않으면 기본값은 strategic입니다. 커스텀 리소스(Custom Resources)는 strategic으로 패치할 수 없으므로 다른 전략을 선택해야 한다는 점에 유의하세요. 예를 들어 CronTab CRD가 정의되어 있고 다음과 같은 CronTab 인스턴스가 있다고 가정해 봅시다:
apiVersion: "stable.example.com/v1"
kind: CronTab
spec:
cronSpec: "* * * * */5"
image: my-awesome-cron-image
이 CronTab은 다음 Argo Workflow로 수정할 수 있습니다:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: k8s-patch-
spec:
entrypoint: cront-tmpl
templates:
- name: cront-tmpl
resource:
action: patch
mergeStrategy: merge # Must be one of [strategic merge json]
manifest: |
apiVersion: "stable.example.com/v1"
kind: CronTab
spec:
cronSpec: "* * * * */10"
image: my-awesome-cron-image
더 알아보기 (Learn more)
action필드는 create, delete, apply, patch 등 임의의 kubectl 동작을 받습니다.successCondition/failureCondition은 k8s 라벨 선택 문법으로 임의 필드에 적용할 수 있는 선택적 표현식입니다.- 커스텀 리소스는
strategic병합을 지원하지 않으므로 patch 시merge또는json을 명시하세요.