[argo]argo基础

argo基础

1 安装argo workflows

argo一般安装在命名空间argo中

1
kubectl create ns argo

Release v3.6.5 · argoproj/argo-workflows中找到要安装的版本。

1
kubectl apply -n argo -f https://github.com/argoproj/argo-workflows/releases/download/v3.6.5/install.yaml

Workflow Controller负责运行workflow。

Argo Server负责提供用户接口和API。

2 管理RBAC

工作流中的所有Pod都使用在workflow.spec.serviceAccountName中指定的service account运行,如果没有指定,则使用工作流所在命名空间的默认service account。工作流所需的访问权限取决于它需要执行的操作。例如,如果你的工作流需要部署一个资源,那么工作流的服务账户就需要对该资源具有‘创建’权限。

不建议在生产环境中使用默认服务账户。因为这是一个共享账户,可能会添加你不希望拥有的权限。相反,应该为工作流创建一个专门的服务账户。

在argo命名空间中创建一个名为argo-workflow的服务账户。

1
kubectl create serviceaccount argo-workflow -n argo

然后,我们创建一个ClusterRole,允许Argo工作流执行器创建和修改工作流任务结果(workflow task result)(这是成功执行工作流所需的最小权限)。工作流任务结果用于管理工作流在其生命周期中的进度。

然后将ClusterRole绑定到argo service account。

3 Workflow

工作流被定义为Kubernetes资源。每个工作流包含一个或多个模板,其中一个被定义为入口点(entrypoint)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# hello-workflow.yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: hello
spec:
serviceAccountName: argo-workflow # this is the service account that the workflow will run with
entrypoint: main # the first template to run in the workflows
templates:
- name: main
container: # this is a container template
image: busybox # this is the image to run
command: ["echo"]
args: ["hello world"]

创建一个workflow

1
kubectl -n argo apply -f hello-workflow.yaml

4 使用UI

可以通过运行端口转发来查看用户界面:

1
kubectl -n argo port-forward --address 0.0.0.0 svc/argo-server 2746:2746 > /dev/null &

之后,可以访问UI。

5 使用CLI

安装Argo CLI

1
2
3
4
curl -sLO https://github.com/argoproj/argo-workflows/releases/download/v3.6.2/argo-linux-amd64.gz
gunzip argo-linux-amd64.gz
chmod +x argo-linux-amd64
mv ./argo-linux-amd64 /usr/local/bin/argo

运行一个workflow

1
argo submit -n argo --serviceaccount argo-workflow --watch https://raw.githubusercontent.com/argoproj/argo-workflows/master/examples/hello-world.yaml

查看工作流

1
argo list -n argo

查看某个工作流的详细信息,@latest 是最后一个工作流的别名

1
argo get -n argo @latest

查看工作流的日志

1
argo logs -n argo @latest	

[argo]argo基础
https://erlsrnby04.github.io/2025/03/17/argo-argo基础/
作者
ErlsrnBy04
发布于
2025年3月17日
许可协议