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
6
# Deploy to kubernetes
7
kubectl create namespace argo
8
argo install -n argo
Copied!
1
ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
2
ACCESS_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
3
4
helm install --namespace argo --name argo-artifacts --set accessKey=$ACCESS_KEY,secretKey=$ACCESS_SECRET_KEY,service.type=LoadBalancer stable/minio
Copied!
创建名为 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
5
# create argo-bucket
6
EXTERNAL_IP=$(kubectl -n argo get service argo-artifacts-minio -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
7
mc config host add argo-artifacts-minio-local http://$EXTERNAL_IP:9000 $ACCESS_KEY $ACCESS_SECRET_KEY --api=s3v4
8
mc mb argo-artifacts-minio-local/argo-bucket
Copied!
然后修改 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
Copied!

使用 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
5
# Deploy to kubernetes
6
helm repo add argo https://argoproj.github.io/argo-helm/
7
kubectl create clusterrolebinding default-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
8
helm install argo/argo-ci --name argo-ci --namespace=kube-system
Copied!

访问 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
5
# 使用浏览器打开 127.0.0.1:52592
Copied!

工作流

首先,给默认的 ServiceAccount 授予集群管理权限
1
# Authz yourself if you are not admin.
2
kubectl create clusterrolebinding default-admin --clusterrole=cluster-admin --serviceaccount=argo:default
Copied!
示例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"]
Copied!
1
argo -n argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml
Copied!
示例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
21
- name: whalesay
22
container:
23
image: docker/whalesay:latest
24
command: [sh, -c]
25
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
26
outputs:
27
artifacts:
28
- name: hello-art
29
path: /tmp/hello_world.txt
30
31
- name: print-message
32
inputs:
33
artifacts:
34
- name: message
35
path: /tmp/message
36
container:
37
image: alpine:latest
38
command: [sh, -c]
39
args: ["cat /tmp/message"]
Copied!
1
argo -n argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/artifact-passing.yaml
Copied!
工作流创建完成后,可以查询它们的状态和日志,并在不需要时删除:
1
$ argo list
2
NAME STATUS AGE DURATION
3
artifact-passing-65p6g Running 6s 4s
4
hello-world-cdnpq Running 8s 6s
5
6
$ argo -n argo logs hello-world-4dhg8
7
_____________
8
< hello world >
9
-------------
10
\
11
\
12
\
13
## .
14
## ## ## ==
15
## ## ## ## ===
16
/""""""""""""""""___/ ===
17
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
18
\______ o __/
19
\ \ __/
20
\____\______/
21
22
$ argo -n argo delete hello-world-4dhg8
23
Workflow 'hello-world-4dhg8' deleted
Copied!
更多工作流 YAML 的格式见官方文档
最近更新 1mo ago