반응형
 

Argo Workflows 설치 방법

Argo Workflows를 설치하기 위해서는 Kubernetes 클러스터가 필요합니다. 아래는 Argo Workflows를 설치하는 방법입니다.

1. Kubernetes 클러스터 준비

  • 로컬에서 Kubernetes를 실행하려면 minikube나 kind를 사용할 수 있습니다. 클라우드에서는 Google Kubernetes Engine(GKE), Amazon EKS, Azure AKS 등을 사용할 수 있습니다.

2. Argo Workflows 설치

kubectl 설치: Kubernetes 클러스터에 접근하기 위해 kubectl을 설치합니다.

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
 

Argo CLI 설치: Argo Workflows를 사용하기 위한 CLI를 설치합니다.

curl -sLO https://github.com/argoproj/argo-workflows/releases/latest/download/argo-linux-amd64
chmod +x argo-linux-amd64
sudo mv argo-linux-amd64 /usr/local/bin/argo

Argo Workflows 설치: Helm을 사용하여 Argo Workflows를 설치할 수 있습니다. Helm이 설치되어 있어야 합니다.

# Helm repository 추가
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update

# Argo Workflows 설치
helm install argo argo/argo-workflows --namespace argo --create-namespace

UI 접근: Argo Workflows는 웹 UI를 제공합니다. 포트 포워딩을 통해 UI에 접근할 수 있습니다.이제 브라우저에서 http://localhost:2746로 접근하여 Argo UI를 확인할 수 있습니다.

kubectl port-forward svc/argo-ui -n argo 2746:2746

Argo Workflows 예제 설명

1. Hello World 예제

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-
spec:
  entrypoint: hello-world
  templates:
  - name: hello-world
    steps:
    - - name: say-hello
        template: hello

  - name: hello
    container:
      image: ubuntu:latest
      command: [bash, -c]
      args: ["echo Hello, World!"]
  • 예제 설명:
    • 이 워크플로우는 "Hello, World!"를 출력하는 간단한 작업을 수행합니다.
    • entrypoint에서 hello-world 템플릿을 시작으로 설정하고, steps를 통해 say-hello 작업을 정의합니다.
    • hello 템플릿에서는 Ubuntu 이미지를 사용해 echo 명령어를 실행합니다.

2. 데이터 생성 및 분석 예제

 
  • 예제 설명:
    • 이 워크플로우는 두 개의 작업을 수행합니다: 데이터 생성과 데이터 분석.
    • 첫 번째 작업(generate-data)은 1에서 100 사이의 무작위 숫자 10개를 생성하고 출력합니다.
    • 두 번째 작업(analyze-data)는 첫 번째 작업의 출력을 입력으로 받아 평균값을 계산합니다.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: data-processing-
spec:
  entrypoint: process-data
  templates:
  - name: process-data
    steps:
    - - name: step-1
        template: generate-data
    - - name: step-2
        template: analyze-data
        arguments:
          parameters:
          - name: input-data
            value: "{{steps.step-1.outputs.result}}"

  - name: generate-data
    script:
      image: python:3.8
      command: [python]
      source: |
        import random
        data = [random.randint(1, 100) for _ in range(10)]
        print(data)

  - name: analyze-data
    inputs:
      parameters:
      - name: input-data
    script:
      image: python:3.8
      command: [python]
      source: |
        input_data = {{inputs.parameters.input-data}}
        avg = sum(input_data) / len(input_data)
        print("Average:", avg)

3. 병렬 작업 예제

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: parallel-jobs-with-follow-up-
spec:
  entrypoint: run-jobs
  templates:
  - name: run-jobs
    steps:
    - - name: job-1
        template: process-job
        arguments:
          parameters:
          - name: job-name
            value: "Job 1"
    - - name: job-2
        template: process-job
        arguments:
          parameters:
          - name: job-name
            value: "Job 2"
    - - name: job-3
        template: process-job
        arguments:
          parameters:
          - name: job-name
            value: "Job 3"
    
    # 병렬 작업이 완료된 후 실행할 작업
    - - name: follow-up-job
        template: follow-up

  - name: process-job
    inputs:
      parameters:
      - name: job-name
    container:
      image: ubuntu:latest
      command: [bash, -c]
      args: ["echo Processing {{inputs.parameters.job-name}}"]

  - name: follow-up
    container:
      image: ubuntu:latest
      command: [bash, -c]
      args: ["echo All jobs completed, executing follow-up task."]
  • 예제 설명:
    • 이 워크플로우는 세 개의 작업을 병렬로 실행합니다: Job 1, Job 2, Job 3.
    • 각 작업은 process-job 템플릿을 참조하고, 각 작업 이름을 인자로 전달합니다.
    • 각 작업은 자신에게 할당된 이름을 출력합니다.
    • 병렬 작업이 모두 완료된 후 follow-up-job이라는 후속 작업이 실행됩니다. 이 작업은 follow-up 템플릿을 사용하여 "All jobs completed, executing follow-up task."라는 메시지를 출력합니다.

4. 조건부 실행 예제

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: conditional-execution-
spec:
  entrypoint: conditional-workflow
  templates:
  - name: conditional-workflow
    steps:
    - - name: check-condition
        template: evaluate-condition

    - - name: run-if-true
        template: true-branch
        when: "{{steps.check-condition.outputs.result}} == 'true'"

  - name: evaluate-condition
    script:
      image: python:3.8
      command: [python]
      source: |
        # Here, implement your logic to evaluate a condition
        condition_met = True
        print(condition_met)

  - name: true-branch
    container:
      image: ubuntu:latest
      command: [bash, -c]
      args: ["echo Condition is true, executing this branch."]
  • 예제 설명:
    • 이 워크플로우는 특정 조건을 평가한 후 그 결과에 따라 다음 작업을 실행합니다.
    • evaluate-condition 템플릿에서 조건을 평가하고 결과를 출력합니다.
    • when 절을 사용하여 조건이 참일 때만 run-if-true 작업이 실행됩니다.

5. 재시도 메커니즘 예제

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: retry-job-
spec:
  entrypoint: retry-example
  templates:
  - name: retry-example
    steps:
    - - name: failing-job
        template: fail-with-retry

  - name: fail-with-retry
    retryStrategy:
      limit: 3
    container:
      image: ubuntu:latest
      command: [bash, -c]
      args: ["exit 1"]  # Always fails for demonstration
  • 예제 설명:
    • 이 워크플로우는 실패할 작업을 정의하고, 최대 3회 재시도합니다.
    • retryStrategy를 설정하여, 작업이 실패할 경우 자동으로 재시도하도록 합니다.

결론

Argo Workflows를 통해 Kubernetes 환경에서 복잡한 데이터 처리 및 분석 파이프라인을 효과적으로 관리할 수 있습니다. 위에서 설명한 설치 방법과 다양한 예제를 통해 Argo의 기본 기능을 이해하고, 필요에 맞게 파이프라인을 확장할 수 있습니다. 각 예제는 실제 사용 시나리오에 따라 조정할 수 있으며, 더 복잡한 작업 흐름을 생성하는 데 기초가 될 수 있습니다.

반응형

'Computer Science > linux' 카테고리의 다른 글

Docker Compose 사용하기  (0) 2024.09.20
Dockerfile 작성하기  (1) 2024.09.15
Docker 사용하기  (0) 2024.09.15
Slurm 설치  (0) 2024.06.05
사용자 계정 관리 및 조직의 구조화 툴 (LDAP)  (0) 2024.05.17

+ Recent posts