工作流workflow任务调度工具argo

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q383965374/article/details/88037991

转载请注明出处:工作流workflow任务调度工具argo

argo简介和原理

argo是一个基于 kubernetes CRD(自定义资源) 实现的一个 Workflow(工作流) 开源工具,基于 kubernetes 的调度能力实现了工作流的控制和任务的运行。

argo官网
github源码地址

一种资源就是Kubernetes API中的一个端点,它存储着某种API 对象的集合。
例如,内建的pods资源包含Pod对象的集合。
自定义资源CRD是用来扩展kubernetes的功能的,可以自定义一些api的实现。
在一个运行中的集群内,自定义资源可以通过动态注册出现和消失,集群管理员可以独立于集群本身更新自定义资源。
一旦安装了自定义资源,用户就可以通过kubectl创建和访问他的对象,就像操作内建资源pods那样。
如下就是一个自定义资源的例子:

例如,如果将以下的CRD保存到resourcedefinition.yaml中:
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # version name to use for REST API: /apis/<group>/<version>
  version: v1
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

创建它:

kubectl create -f resourcedefinition.yaml

然后一个新的区分命名空间的RESTful API 端点被创建了:

/apis/stable.example.com/v1/namespaces/*/crontabs/...

然后可以使用此端点URL来创建和管理自定义对象。 这些对象的kind就是你在上面创建的CRD中指定的CronTab对象。

自定义资源是对Kubernetes API的扩展,kubernetes中的每个资源都是一个API对象的集合,例如我们在YAML文件里定义的那些spec都是对kubernetes中的资源对象的定义。

Kubernetes1.6版本中包含一个内建的资源叫做CRD(CustomResourceDefinition),可以用它来创建自定义资源,但该资源在kubernetes1.7中版本已被TRD(ThirdPartyResource)取代。在1.8版本中又启用了CustomResourceDefinition。

更多自定义资源的信息可参考:
自定义资源
使用CRD(CustomResourceDefinitions)扩展Kubernetes API

argo就是根据CRD自定义的一个扩展功能,主要实现工作流的控制。是一个任务调度的工具,同时提供了一个 UI 来方便我们查看任务的进程和详情等。
如图:

argo的特点

1、argo是基于容器的,不需要传统的虚拟机机系统和环境
2、argo是云无关的,可以在任意的k8s集群中运行
3、argo能定制计算资源,让云端的资源在我们的掌握之中

谁在使用argo

Adobe
BlackRock
CoreFiling
Cyrus Biotechnology
Datadog
Gladly
Google
Interline Technologies
Intuit
Localytics
NVIDIA

#开始使用

准备环境

1、需要运行在Kubernetes 1.9或者1.9+的版本之上
2、下载有kubectl命令行客户端
3、配置好kubeconfig文件(配置文件默认路径~/.kube/config)

详情参考文章:
kubernetes—CentOS7安装kubernetes1.11.2图文完整版

##下载安装argo

Mac环境:

brew install argoproj/tap/argo

Linux环境

curl -sSL -o /usr/local/bin/argo https://github.com/argoproj/argo/releases/download/v2.2.0/argo-linux-amd64
chmod +x /usr/local/bin/argo

安装控制器和UI

使用命令

kubectl create ns argo
kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo/v2.2.0/manifests/install.yaml

如果我们的k8s集群式运行在GKE (Google Kubernetes Engine)上的,则还需要授权账号可以创造集群的角色使用命令如下,非GKE集群不需要运行:

kubectl create clusterrolebinding YOURNAME-cluster-admin-binding --clusterrole=cluster-admin [email protected]

配置服务账户用于运行workflows

当集群是基于RBAC(Role-Based Access Control,基于角色的访问控制)时,默认账户有很多的限制,比如不能支持组件,输出等等。
执行以下命令授权默认的服务账户在默认的namespace中拥有admin的权限

kubectl create rolebinding default-admin --clusterrole=admin --serviceaccount=default:default

或者你可以在提交workflow时指定服务账户,使用命令如下:

argo submit --serviceaccount <name>

尝试运行argo例子

这是一个类似于helloword的小例子,使用命令如下:

argo submit --watch https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml
argo submit --watch https://raw.githubusercontent.com/argoproj/argo/master/examples/coinflip.yaml
argo submit --watch https://raw.githubusercontent.com/argoproj/argo/master/examples/loops-maps.yaml
argo list
argo get xxx-workflow-name-xxx
argo logs xxx-pod-name-xxx #from get command above

我们也可以使用kubectl命令进行workflow的提交,不过相对于argo命令来说,kubectl命令缺少了很多功能,比如yaml的验证,workflow的可视化,参数验证,重试和重新提交等等。

使用命令如下:

kubectl create -f https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml
kubectl get wf
kubectl get wf hello-world-xxx
kubectl get po --selector=workflows.argoproj.io/workflow=hello-world-xxx --show-all
kubectl logs hello-world-yyy -c main

公开Argo的UI

默认情况下argo的UI服务是没对外网开放的,需要进行设置对外公布,有三种方法

方法一:kubectl port-forward

使用命令

kubectl -n argo port-forward deployment/argo-ui 8001:8001

则 在可以使用 链接访问: http://127.0.0.1:8001

方式二:kubectl proxy
使用命令

kubectl proxy

则使用如下链接可以访问:

http://127.0.0.1:8001/api/v1/namespaces/argo/services/argo-ui/proxy/

注意,组件下载和web控制台不支持使用这种方法

方法三:使用loadBalancer

把argo-ui service 设置成 loadBalancer类型的服务

使用命令

kubectl patch svc argo-ui -n argo -p '{"spec": {"type": "LoadBalancer"}}'

等待分配外网地址
使用命令查看如下:

kubectl get svc argo-ui -n argo
NAME      TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
argo-ui   LoadBalancer   10.19.255.205   35.197.49.167   8080:31768/TCP   1m

访问方式

35.197.49.167:8080

35.197.49.167对应EXTERNAL-IP
8080对应PORT(S)

还有一种是分配的域名
如果EXTERNAL-IP比较长会显示省略号如下:

zhangxiaofans-MacBook-Pro:report-api joe$ kubectl get svc argo-ui -n argo
NAME      TYPE           CLUSTER-IP      EXTERNAL-IP        PORT(S)        AGE
argo-ui   LoadBalancer   10.19.255.205     a4c2851a9b3fd...   80:31768/TCP   10m

解决方法使用describe

zhangxiaofans-MacBook-Pro:report-api joe$ kubectl describe svc argo-ui -n argo
Name:                     argo-ui
Namespace:                argo
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"argo-ui","namespace":"argo"},"spec":{"ports":[{"port":80,"targetPort":8001}],"...
Selector:                 app=argo-ui
Type:                     LoadBalancer
IP:                       10.19.255.205
LoadBalancer Ingress:     a4c2851a9b3fd11efassadfdsads-35sdffsdgfsd.cn-northwest-1.elb.amazonaws.com.cn
Port:                     <unset>  80/TCP
TargetPort:               8001/TCP
NodePort:                 <unset>  31768/TCP
Endpoints:               10.19.255.205:8001
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  Type                  9m    service-controller  ClusterIP -> LoadBalancer
  Normal  EnsuringLoadBalancer  9m    service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   9m    service-controller  Ensured load balancer
zhangxiaofans-MacBook-Pro:report-api joe$ 

如果输出中Port是80则不需要带端口,直接使用LoadBalancer Ingress访问即可:

a4c2851a9b3fd11efassadfdsads-35sdffsdgfsd.cn-northwest-1.elb.amazonaws.com.cn

注意,在Minikube集群中,不会自动获取到外网ip,会一直显示pending。 使用如下命令确定argo的ui链接:

minikube service -n argo --url argo-ui

怎么写工作流
更多使用示例
https://zhuanlan.zhihu.com/p/40301198

capture the dependencies between tasks using a graph (DAG)

怎么配置组件(S3, Artifactory, HTTP, Git, raw)
https://github.com/argoproj/argo/blob/master/ARTIFACT_REPO.md

转载请注明出处:工作流workflow任务调度工具argo

猜你喜欢

转载自blog.csdn.net/q383965374/article/details/88037991