随着Kubernetes越来越普遍的使用,基于K8S的workflow工具Argo也受到越来越多的关注。
Argo官方已经给出了很多不同的Workflow的编写方法,但是如果你需要不止一种的方法应该怎么处理呢?
本文以steps和kubernetes resource这两种流程的结合,给大家提供一个思路。
废话不多说,直接上yaml:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-
spec:
serviceAccountName: workflow
entrypoint: create-hello-delete
templates:
- name: create-hello-delete
steps:
- - name: create
template: createdp
- - name: hello
template: whalesay
arguments:
parameters:
- name: message
value: "hello2a"
- - name: delete
template: deletedp
- name: whalesay
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
- name: createdp
resource: # indicates that this is a resource template
action: create # can be any kubectl action (e.g. create, delete, apply, patch)
manifest: | #put your kubernetes spec here
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: brokerclinet
spec:
selector:
matchLabels:
app: brokerclinet
replicas: 1 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: brokerclinet
spec:
containers:
- name: brokerclinet
image: brokerclient:1.0.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5000
- name: deletedp
resource: # indicates that this is a resource template
action: delete # can be any kubectl action (e.g. create, delete, apply, patch)
manifest: | #put your kubernetes spec here
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: brokerclinet
这里,我希望argo生成一个包含三步的workflow,第一步,创建一个名叫brokerclinet的deployment,然后生成一个以docker/whalesay为基础镜像的容器,并打印一些语句,最后,删除第一步创建的brokerclinet。
需要注意,对于官方给出的steps的yaml文件,不要直接把k8s资源的那个例子直接填充到每个step里面,而是把k8s资源的部分单独提出来,做一个template,而只在每一个step的里面调用该template即可,否则argo submit的时候会报resource字段不能识别的问题。
基于此,如果需要组合多种workflow的方法,要考虑把一些方法做成template,然后再调用template,这样可以满足多种方法的混合。
网友评论