apiVersion:argoproj.io/v1alpha1kind:Workflowmetadata:generateName:artifact-passing-spec:entrypoint:artifact-exampletemplates:- name:artifact-examplesteps:- - name:generate-artifacttemplate:whalesay- - name:consume-artifacttemplate:print-messagearguments:artifacts:# bind message to the hello-art artifact# generated by the generate-artifact step- name:messagefrom:"{{steps.generate-artifact.outputs.artifacts.hello-art}}"- name:whalesaycontainer:image:docker/whalesay:latestcommand:[sh, -c]args:["cowsay hello world | tee /tmp/hello_world.txt"]outputs:artifacts:# generate hello-art artifact from /tmp/hello_world.txt# artifacts can be directories as well as files- name:hello-artpath:/tmp/hello_world.txt- name:print-messageinputs:artifacts:# unpack the message input artifact# and put it at /tmp/message- name:messagepath:/tmp/messagecontainer:image:alpine:latestcommand:[sh, -c]args:["cat /tmp/message"]
可以看到,artifact 方式共享文件步骤间传递参数是比较类似。
导出 artifact
1
2
3
4
5
6
outputs:artifacts:# generate hello-art artifact from /tmp/hello_world.txt# artifacts can be directories as well as files- name:hello-artpath:/tmp/hello_world.txt
后续步骤引用导出的 artifact
1
2
3
4
5
6
arguments:artifacts:# bind message to the hello-art artifact# generated by the generate-artifact step- name:messagefrom:"{{steps.generate-artifact.outputs.artifacts.hello-art}}"
apiVersion:argoproj.io/v1alpha1kind:Workflowmetadata:generateName:volumes-pvc-spec:entrypoint:volumes-pvc-examplevolumeClaimTemplates:# define volume, same syntax as k8s Pod spec- metadata:name:workdir # name of volume claimspec:accessModes:["ReadWriteOnce"]resources:requests:storage:1Gi # Gi => 1024 * 1024 * 1024templates:- name:volumes-pvc-examplesteps:- - name:generatetemplate:whalesay- - name:printtemplate:print-message- name:whalesaycontainer:image:docker/whalesay:latestcommand:[sh, -c]args:["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]# Mount workdir volume at /mnt/vol before invoking docker/whalesayvolumeMounts:# same syntax as k8s Pod spec- name:workdirmountPath:/mnt/vol- name:print-messagecontainer:image:alpine:latestcommand:[sh, -c]args:["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]# Mount workdir volume at /mnt/vol before invoking docker/whalesayvolumeMounts:# same syntax as k8s Pod spec- name:workdirmountPath:/mnt/vol
首先定义了一个 PVC 模版,Workflow 运行时就会使用该模版创建一个 PVC
1
2
3
4
5
6
7
8
9
10
spec:entrypoint:volumes-pvc-examplevolumeClaimTemplates:# define volume, same syntax as k8s Pod spec- metadata:name:workdir # name of volume claimspec:accessModes:["ReadWriteOnce"]resources:requests:storage:1Gi # Gi => 1024 * 1024 * 1024
然后其他步骤需要将该 PVC 挂载到对应目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- name:whalesaycontainer:image:docker/whalesay:latestcommand:[sh, -c]args:["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]# Mount workdir volume at /mnt/vol before invoking docker/whalesayvolumeMounts:# same syntax as k8s Pod spec- name:workdirmountPath:/mnt/vol- name:print-messagecontainer:image:alpine:latestcommand:[sh, -c]args:["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]# Mount workdir volume at /mnt/vol before invoking docker/whalesayvolumeMounts:# same syntax as k8s Pod spec- name:workdirmountPath:/mnt/vol
# Define Kubernetes PVCkind:PersistentVolumeClaimapiVersion:v1metadata:name:my-existing-volumespec:accessModes:["ReadWriteOnce"]resources:requests:storage:1Gi---apiVersion:argoproj.io/v1alpha1kind:Workflowmetadata:generateName:volumes-existing-spec:entrypoint:volumes-existing-examplevolumes:# Pass my-existing-volume as an argument to the volumes-existing-example template# Same syntax as k8s Pod spec- name:workdirpersistentVolumeClaim:claimName:my-existing-volumetemplates:- name:volumes-existing-examplesteps:- - name:generatetemplate:whalesay- - name:printtemplate:print-message- name:whalesaycontainer:image:docker/whalesay:latestcommand:[sh, -c]args:["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]volumeMounts:- name:workdirmountPath:/mnt/vol- name:print-messagecontainer:image:alpine:latestcommand:[sh, -c]args:["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]volumeMounts:- name:workdirmountPath:/mnt/vol
apiVersion:argoproj.io/v1alpha1kind:Workflowmetadata:generateName:volumes-existing-spec:entrypoint:volumes-existing-examplevolumes:# Pass my-existing-volume as an argument to the volumes-existing-example template# Same syntax as k8s Pod spec- name:workdirpersistentVolumeClaim:claimName:my-existing-volume