首页 > 科技 > 在Serverless Kubernetes集群中轻松运行Argo Workflow

在Serverless Kubernetes集群中轻松运行Argo Workflow

导读

Argo是一个基于kubernetes实现的一个Workflow(工作流)开源工具,基于kubernetes的调度能力实现了工作流的控制和任务的运行。
目前阿里云容器服务ACK集群中已经支持工作流的部署和调度,这里我们介绍如果在ASK(Serverless Kubernetes)集群中使用Argo,无需预留节点资源池,即可灵活动态的运行工作流任务,并最大化节省用户的计算成本。

前置条件:

  • 创建ASK集群 https://cs.console.aliyun.com/#/k8s/cluster/create/serverless
    因为argo创建的pod往往需要大规格cpu和mem资源,因此建议创建多可用区ASK集群,当一个可用区库存不足时,后台会在其他可用区尝试创建pod,以缓解单可用区库存不足的情况。
  • 下载ags命令行,可参考https://help.aliyun.com/document_detail/121342.html

部署argo workflow controller

# ags install

# kubectl -n argo get pod
NAME READY STATUS RESTARTS AGE
argo-ui-5c5dbd7d75-hxqfd 1/1 Running 0 60s
workflow-controller-848cf55b64-6pzc9 1/1 Running 0 60s

# kubectl -n argo get configmap
NAME DATA AGE
workflow-controller-configmap 0 4m55s

argo默认使用docker executor api,在serverless集群中我们需要切换成k8sapi才能正常工作。

# kubectl -n argo edit configmap workflow-controller-configmap
apiVersion: v1
kind: ConfigMap
...
data:
config: |
containerRuntimeExecutor: k8sapi

运行Hello-World Workflow示例

下面我们运行Hello-World example:https://github.com/argoproj/argo/blob/master/examples/hello-world.yaml

# ags submit https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml
Name: hello-world-l26sx
Namespace: default
ServiceAccount: default
Status: Pending
Created: Fri Nov 15 14:45:15 +0800 (now)

# kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-world-l26sx 0/2 Completed 0 88s

# ags list
NAME STATUS AGE DURATION PRIORITY
hello-world-l26sx Succeeded 1m 1m 0

当我们需要使用大规格资源来运行workflow时,可以在workflow中给pod指定anntation。

注意此情况不要在container中指定大规格requests/limits,因为argo生成的pod中包含多个container,给单个container指定大规格的requests/limits会导致eci无法给pod分配匹配的资源,进而导致创建失败。我们推荐给pod指定ecs规格或者cpu/mem保证pod正常运行,如下。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
metadata:
annotations:
k8s.aliyun.com/eci-instance-type : "ecs.ic5.3xlarge"
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["hello world"]

结束

当运行结束后,可以清理workflow资源。

# ags delete hello-world-l26sx
Workflow 'hello-world-l26sx' deleted

# kubectl get pod
No resources found.

我们可以看到,因为ASK集群天然无需管理节点资源池,所有pod按需创建,很好的匹配了Argo工作流的任务形态,灵活动态的按需分配计算资源,更好的节省成本。

作者:贤维

本文为云栖社区原创内容,未经允许不得转载。

本文来自投稿,不代表本人立场,如若转载,请注明出处:http://www.souzhinan.com/kj/216459.html