ArgoWorkflow教程(一)---DevOps 另一选择?云原生 CICD: ArgoWorkflow 初体验

来自:探索云原生 https://www.lixueduan.com

原文:https://www.lixueduan.com/posts/devops/argo-workflow/01-deploy-argo-workflows/

本文主要记录了如何在 k8s 上快速部署云原生的工作流引擎 ArgoWorkflow。

ArgoWorkflow 是什么

Argo Workflows 是一个开源的云原生工作流引擎,用于在 Kubernetes 上编排并行作业。Argo 工作流作为Kubernetes CRD 实现。

  • 定义工作流,其中工作流中的每个步骤都是一个容器。
  • 将多步骤工作流建模为一系列任务,或使用 DAG 来捕获任务之间的依赖关系图。
  • 使用 Argo 可以在很短的时间内在 Kubernetes 上轻松运行机器学习或数据处理的计算密集型作业

一句话描述:ArgoWorkflow 是一个用于在 Kubernetes 上编排并行作业的开源云原生工作流引擎

组件

相对于 Tekton 来说,ArgoWorkflow 组件比较少,整体架构比较简单。

核心组件:

  • argo-server:为工作流提供 API 和 UI 界面。
  • workflow-controller:真正干活的组件,解析用户创建的 CR 对象并启动 Pod 来真正运行流水线

部署

官方提供helm chart可以一键部署,完整命令如下:

Bash 复制代码
# 添加参考并更新
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update

# 部署
# -set server.authMode=server 配置切换认证模式,便于免token 登录 UI 界面
helm install argo-workflows argo/argo-workflows -n argo --create-namespace --set server.authMode=server

部署完成后会启动两个 Pod

Bash 复制代码
[root@argo ~]# kubectl -n argo get po
NAME                                   READY   STATUS    RESTARTS   AGE
argo-server-84fd55bfc-hd6qp            1/1     Running   0          2m16s
workflow-controller-557756b7c8-blmp7   1/1     Running   0          2m16s

然后将 Service 切换为 NodePort 便于访问

Bash 复制代码
kubectl patch svc argo-workflows-server -n argo -p '{"spec": {"type": "NodePort"}}'

最后通过 NodePort 访问即可,就像这样:http://172.20.148.126:31691

Bash 复制代码
[root@argo ~]# kubectl -n argo get svc argo-workflows-server
NAME                    TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
argo-workflows-server   NodePort   10.108.150.173   <none>        2746:31691/TCP   2m3s

UI 界面如下,整体和 ArgoCD 挺像的:

Demo

简单启动一个 Workflow 测试一下 ArgoWorkflow 能否正常运行。

使用以下命令创建一个 Workflow 对象:

YAML 复制代码
kubectl create -f - << EOF
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: steps-
spec:
  entrypoint: hello           # We reference our first "template" here
  templates:
  - name: hello               # The first "template" in this Workflow, it is referenced by "entrypoint"
    steps:                    # The type of this "template" is "steps"
    - - name: hello
        template: whalesay    # We reference our second "template" here
        arguments:
          parameters: [{name: message, value: "Hello ArgoWorkflow!"}]

  - name: whalesay             # The second "template" in this Workflow, it is referenced by "hello"
    inputs:
      parameters:
      - name: message
    container:                # The type of this "template" is "container"
      image: docker/whalesay
      command: [cowsay]
      args: ["{{inputs.parameters.message}}"]
EOF

功能也很简单,就是打印 Hello ArgoWorkflow! 这句话。

查看状态

Bash 复制代码
[root@argo ~]# kubectl get workflow
NAME          STATUS    AGE   MESSAGE
steps-75xmq   Running   6s

可以看到,当前处于 Running 状态,不过这是一个非常简单的任务,因此很快就会结束,时间应该是耗费在拉取镜像上。

查看 Pod 运行情况

Bash 复制代码
[root@argo ~]# kubectl get po -w
NAME                              READY   STATUS            RESTARTS   AGE
steps-75xmq-whalesay-1542601109   0/2     PodInitializing   0          96s

看起来正在拉取镜像,等一下

Bash 复制代码
[root@argo ~]# kubectl get po
NAME                              READY   STATUS      RESTARTS   AGE
steps-75xmq-whalesay-1542601109   0/2     Completed   0          2m58s
[root@argo ~]# kubectl get workflow
NAME          STATUS      AGE    MESSAGE
steps-75xmq   Succeeded   3m6s

Pod 已经运行完成了,Workflow 也进行 Successed 状态,查看 Pod 日志,确认是否真的执行了

Bash 复制代码
[root@argo ~]# kubectl logs -f steps-75xmq-whalesay-1542601109
 _____________________
< Hello ArgoWorkflow! >
 ---------------------
    \
     \
      \
                    ##        .
              ## ## ##       ==
           ## ## ## ##      ===
       /""""""""""""""""___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
       \______ o          __/
        \    \        __/
          \____\______/
time="2023-10-20T08:48:32.163Z" level=info msg="sub-process exited" argo=true error="<nil>"

可以看到,确实打印出了 "Hello ArgoWorkflow" 这句话,至此说明我们部署的 ArgoWorkflow 是能够正常运行的。

到这里 ArgoWorkflow 的部署就完成了,如果理解不了这个 demo 中做的事情也没关系,后续会有 ArgoWorkflow 的使用教程,敬请期待~

下期预告:Workflow & Template 概念模型, 构建 ArgoWorkflow 流水线

相关推荐
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS2 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
AI职业加油站2 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
codeejun2 天前
每日一Go·MySQL-5、锁机制全解析
云原生·golang
此冬歌咏2 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
-梅2 天前
linux(8) 软硬链接
linux·运维·服务器
张洛闻Eren2 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github
其实防守也摸鱼2 天前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
布裘2 天前
【银河麒麟】V4桌面图标消失,右击鼠标没反应排查
运维·银河麒麟·桌面环境
懂软件的胡子个哥2 天前
微信机器人为什么需要“回复候选”而不是所有 AI 内容直接发送
运维·微信·自动化·wechatapi·个人微信号二次开发