Argo

Argo 是一个基于 Kubernetes 的工作流引擎,同时也支持 CI、CD 等丰富的功能。Argo 开源在 https://github.com/argoproj

安装 Argo

使用 argo install

  1. # Download Argo.
  2. curl -sSL -o argo https://github.com/argoproj/argo/releases/download/v2.1.0/argo-linux-amd64
  3. chmod +x argo
  4. sudo mv argo /usr/local/bin/argo
  5. # Deploy to kubernetes
  6. kubectl create namespace argo
  7. argo install -n argo
  1. ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
  2. ACCESS_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
  3. helm install --namespace argo --name argo-artifacts --set accessKey=$ACCESS_KEY,secretKey=$ACCESS_SECRET_KEY,service.type=LoadBalancer stable/minio

创建名为 argo-bucket 的 Bucket(可以通过 kubectl port-forward service/argo-artifacts-minio :9000 访问 Minio UI 来操作):

  1. # download mc client
  2. sudo wget https://dl.minio.io/client/mc/release/linux-amd64/mc -O /usr/local/bin/mc
  3. sudo chmod +x /usr/local/bin/mc
  4. # create argo-bucket
  5. EXTERNAL_IP=$(kubectl -n argo get service argo-artifacts-minio -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  6. mc config host add argo-artifacts-minio-local http://$EXTERNAL_IP:9000 $ACCESS_KEY $ACCESS_SECRET_KEY --api=s3v4
  7. mc mb argo-artifacts-minio-local/argo-bucket

然后修改 Argo 工作流控制器使用 Minio:

  1. $ kubectl -n argo create secret generic argo-artifacts-minio --from-literal=accesskey=$ACCESS_KEY --from-literal=secretkey=$ACCESS_SECRET_KEY
  2. $ kubectl edit configmap workflow-controller-configmap -n argo
  3. ...
  4. executorImage: argoproj/argoexec:v2.0.0
  5. artifactRepository:
  6. s3:
  7. bucket: argo-bucket
  8. endpoint: argo-artifacts-minio.argo:9000
  9. insecure: true
  10. # accessKeySecret and secretKeySecret are secret selectors.
  11. # It references the k8s secret named 'argo-artifacts-minio'
  12. # which was created during the minio helm install. The keys,
  13. # 'accesskey' and 'secretkey', inside that secret are where the
  14. # actual minio credentials are stored.
  15. accessKeySecret:
  16. name: argo-artifacts-minio
  17. key: accesskey
  18. secretKeySecret:
  19. name: argo-artifacts-minio
  20. key: secretkey

使用 Helm

注意:当前 Helm Charts 使用的 Minio 版本较老,部署有可能会失败。

  1. # Download Argo.
  2. curl -sSL -o /usr/local/bin/argo https://github.com/argoproj/argo/releases/download/v2.0.0/argo-linux-amd64
  3. chmod +x /usr/local/bin/argo
  4. # Deploy to kubernetes
  5. helm repo add argo https://argoproj.github.io/argo-helm/
  6. kubectl create clusterrolebinding default-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
  7. helm install argo/argo-ci --name argo-ci --namespace=kube-system

访问 Argo UI

  1. $ kubectl -n argo port-forward service/argo-ui :80
  2. Forwarding from 127.0.0.1:52592 -> 8001
  3. Forwarding from [::1]:52592 -> 8001
  4. # 使用浏览器打开 127.0.0.1:52592

工作流

首先,给默认的 ServiceAccount 授予集群管理权限

  1. # Authz yourself if you are not admin.
  2. kubectl create clusterrolebinding default-admin --clusterrole=cluster-admin --serviceaccount=argo:default

示例1: 最简单的工作流

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: Workflow
  3. metadata:
  4. generateName: hello-world-
  5. spec:
  6. entrypoint: whalesay
  7. templates:
  8. - name: whalesay
  9. container:
  10. image: docker/whalesay:latest
  11. command: [cowsay]
  12. args: ["hello world"]
  1. argo -n argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml

示例2:包含多个容器的工作流

  1. # This example demonstrates the ability to pass artifacts
  2. # from one step to the next.
  3. apiVersion: argoproj.io/v1alpha1
  4. kind: Workflow
  5. metadata:
  6. generateName: artifact-passing-
  7. spec:
  8. entrypoint: artifact-example
  9. templates:
  10. - name: artifact-example
  11. steps:
  12. - - name: generate-artifact
  13. template: whalesay
  14. - - name: consume-artifact
  15. template: print-message
  16. arguments:
  17. artifacts:
  18. - name: message
  19. from: "{{steps.generate-artifact.outputs.artifacts.hello-art}}"
  20. - name: whalesay
  21. container:
  22. image: docker/whalesay:latest
  23. command: [sh, -c]
  24. args: ["cowsay hello world | tee /tmp/hello_world.txt"]
  25. outputs:
  26. artifacts:
  27. - name: hello-art
  28. path: /tmp/hello_world.txt
  29. - name: print-message
  30. inputs:
  31. artifacts:
  32. - name: message
  33. path: /tmp/message
  34. container:
  35. image: alpine:latest
  36. command: [sh, -c]
  37. args: ["cat /tmp/message"]
  1. argo -n argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/artifact-passing.yaml

工作流创建完成后,可以查询它们的状态和日志,并在不需要时删除:

  1. $ argo list
  2. NAME STATUS AGE DURATION
  3. artifact-passing-65p6g Running 6s 4s
  4. hello-world-cdnpq Running 8s 6s
  5. $ argo -n argo logs hello-world-4dhg8
  6. _____________
  7. < hello world >
  8. -------------
  9. \
  10. \
  11. \
  12. ## .
  13. ## ## ## ==
  14. ## ## ## ## ===
  15. /""""""""""""""""___/ ===
  16. ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
  17. \______ o __/
  18. \ \ __/
  19. \____\______/
  20. $ argo -n argo delete hello-world-4dhg8
  21. Workflow 'hello-world-4dhg8' deleted

更多工作流 YAML 的格式见官方文档工作流示例