ArgoWorkflow教程(七)---高效的步骤间文件共享策略

之前我们分析了使用 artifact 实现步骤间文件共享,今天分享一下如何使用 PVC 实现高效的步骤间文件共享。
1. 概述
之前在 artifact 篇我们演示了如何使用 artifact 实现步骤间文件传递,今天介绍一种更为简单的文件传递方式:PVC 共享。
artifact 毕竟是借助 S3 实现中转,效率上肯定是低于直接共享 PVC 的,而且 artifact 一般用于结果输出,将最终结果保存到 S3,而不是单纯的用来共享文件。
2. 使用 artifact 共享文件
之前已经分享过了怎么通过 artifact 在不同步骤之间传递文件,这里在回顾一下。
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-passing-
spec:
entrypoint: artifact-example
templates:
- name: artifact-example
steps:
- - name: generate-artifact
template: whalesay
- - name: consume-artifact
template: print-message
arguments:
artifacts:
# bind message to the hello-art artifact
# generated by the generate-artifact step
- name: message
from: "{{steps.generate-artifact.outputs.artifacts.hello-art}}"
- name: whalesay
container:
image: docker/whalesay:latest
command: [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-art
path: /tmp/hello_world.txt
- name: print-message
inputs:
artifacts:
# unpack the message input artifact
# and put it at /tmp/message
- name: message
path: /tmp/message
container:
image: alpine:latest
command: [sh, -c]
args: ["cat /tmp/message"]
可以看到,artifact 方式共享文件步骤间传递参数是比较类似。
导出 artifact
outputs:
artifacts:
# generate hello-art artifact from /tmp/hello_world.txt
# artifacts can be directories as well as files
- name: hello-art
path: /tmp/hello_world.txt
后续步骤引用导出的 artifact
arguments:
artifacts:
# bind message to the hello-art artifact
# generated by the generate-artifact step
- name: message
from: "{{steps.generate-artifact.outputs.artifacts.hello-art}}"
以及步骤中怎么将 artifact 引入,比如下面 demo 则是将 artifact 做为 /tmp/message 挂载到 Pod 中。
inputs:
artifacts:
# unpack the message input artifact
# and put it at /tmp/message
- name: message
path: /tmp/message
3. 使用 PVC 高效共享文件
顾名思义,就是不同步骤都挂载同一个 PVC,这样自然就实现了文件共享。
ArgoWorkflow 中的每一步都会单独启动一个 Pod 来运行
也有两种方式:
- 1)动态创建 PVC:Workflow 运行时创建 PVC,运行结束后删除 PVC
- 2)使用已有 PVC:不会创建也不会删除
动态创建 PVC
完整 Demo 如下:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: volumes-pvc-
spec:
entrypoint: volumes-pvc-example
volumeClaimTemplates: # define volume, same syntax as k8s Pod spec
- metadata:
name: workdir # name of volume claim
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi # Gi => 1024 * 1024 * 1024
templates:
- name: volumes-pvc-example
steps:
- - name: generate
template: whalesay
- - name: print
template: print-message
- name: whalesay
container:
image: docker/whalesay:latest
command: [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/whalesay
volumeMounts: # same syntax as k8s Pod spec
- name: workdir
mountPath: /mnt/vol
- name: print-message
container:
image: alpine:latest
command: [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/whalesay
volumeMounts: # same syntax as k8s Pod spec
- name: workdir
mountPath: /mnt/vol
首先定义了一个 PVC 模版,Workflow 运行时就会使用该模版创建一个 PVC
spec:
entrypoint: volumes-pvc-example
volumeClaimTemplates: # define volume, same syntax as k8s Pod spec
- metadata:
name: workdir # name of volume claim
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi # Gi => 1024 * 1024 * 1024
然后其他步骤需要将该 PVC 挂载到对应目录
- name: whalesay
container:
image: docker/whalesay:latest
command: [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/whalesay
volumeMounts: # same syntax as k8s Pod spec
- name: workdir
mountPath: /mnt/vol
- name: print-message
container:
image: alpine:latest
command: [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/whalesay
volumeMounts: # same syntax as k8s Pod spec
- name: workdir
mountPath: /mnt/vol
这样就实现了文件共享,非常简单。
等 Workflow 运行结束后,Argo 会自动将创建出的 PVC 删除。
使用已有 PVC
在某些情况下,我们可以希望访问已经存在的卷,而不是动态创建/销毁卷。
完整 Demo 如下:
# Define Kubernetes PVC
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-existing-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
---
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: volumes-existing-
spec:
entrypoint: volumes-existing-example
volumes:
# Pass my-existing-volume as an argument to the volumes-existing-example template
# Same syntax as k8s Pod spec
- name: workdir
persistentVolumeClaim:
claimName: my-existing-volume
templates:
- name: volumes-existing-example
steps:
- - name: generate
template: whalesay
- - name: print
template: print-message
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]
volumeMounts:
- name: workdir
mountPath: /mnt/vol
- name: print-message
container:
image: alpine:latest
command: [sh, -c]
args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]
volumeMounts:
- name: workdir
mountPath: /mnt/vol
首先就是手动创建一个 PVC
# Define Kubernetes PVC
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-existing-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
然后在 Workflow 中定义要使用这个 PVC
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: volumes-existing-
spec:
entrypoint: volumes-existing-example
volumes:
# Pass my-existing-volume as an argument to the volumes-existing-example template
# Same syntax as k8s Pod spec
- name: workdir
persistentVolumeClaim:
claimName: my-existing-volume
可以看做是使用 persistentVolumeClaim 来替换了之前的 volumeClaimTemplates
然后就是步骤将这个 PVC 挂载到对应目录
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]
volumeMounts:
- name: workdir
mountPath: /mnt/vol
- name: print-message
container:
image: alpine:latest
command: [sh, -c]
args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"]
volumeMounts:
- name: workdir
mountPath: /mnt/vol
这一步和使用动态创建 PVC 时没有任何变化。
【ArgoWorkflow 系列】持续更新中,搜索公众号【探索云原生】订阅,阅读更多文章。

4. 小结
本文主要分析了 Argo 中的 Workflow 中怎么使用 PVC 共享文件。
- 1)定义 PVC 模版或者指定使用已有的 PVC
- 2)步骤中将 PVC 挂载到对应目录使用
ArgoWorkflow教程(七)---高效的步骤间文件共享策略的更多相关文章
- android 7.0 应用间文件共享FileProvider
1.官方教程 Android 7.0 以后安全系数提高,应用间文件共享要使用FileProvider.原来的 file:/// Uri 替换为 content://Uri https://devel ...
- CRL快速开发框架系列教程七(使用事务)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- ASP.NET 5系列教程(七)完结篇-解读代码
在本文中,我们将一起查看TodoController 类代码. [Route] 属性定义了Controller的URL 模板: [Route("api/[controller]") ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block 使用企业库异常处理应用程序模块的 ...
- SpringBoot进阶教程(七十四)整合ELK
在上一篇文章<SpringBoot进阶教程(七十三)整合elasticsearch >,已经详细介绍了关于elasticsearch的安装与使用,现在主要来看看关于ELK的定义.安装及使用 ...
- Laravel教程 七:表单验证 Validation
Laravel教程 七:表单验证 Validation 此文章为原创文章,未经同意,禁止转载. Laravel Form 终于要更新这个Laravel系列教程的第七篇了,期间去写了一点其他的东西. 就 ...
- 无废话ExtJs 入门教程七[登陆窗体Demo:Login]
无废话ExtJs 入门教程七[登陆窗体Demo:Login] extjs技术交流,欢迎加群(201926085) 在这节我们通过前几节讲的内容做一个登陆页面,把前几节讲的内容贯穿一下. 1.代码如下: ...
- webpack4 系列教程(七): SCSS提取和懒加载
教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步>>> (原文)webpack4 系列教程(七): SCSS 提取和懒加载. 个人技术小站: https://god ...
- (转)NGUI系列教程七(序列帧动画UITexture 和 UIsprit)
NGUI系列教程七(序列帧动画) 今天我给大家讲一下如何使用NGUI做序列帧动画.本节主要包括两方面内容,分别是使用UIspirit和使用UITexture 做序列帧动画.废话不说了,下面开始.还 ...
- WPF教程002 - 实现Step步骤条控件
原文:WPF教程002 - 实现Step步骤条控件 在网上看到这么一个效果,刚好在用WPF做控件,就想着用WPF来实现一下 1.实现原理 1.1.该控件分为2个模块,类似ComboBox控件分为Ste ...
随机推荐
- 在Ubuntu18.04系统中源码安装 gcc7.3.0
本文给出源码安装gcc7.3.0的方法. 依赖的环境安装到自建文件夹下, 给出下面操作中环境的安装文件夹: /home/devilmaycry/anaconda3/mindspore_envs这个路径 ...
- A3C与GA3C的收敛性分析
G-A3C的代码: https://gitee.com/devilmaycry812839668/gpu_a3c 论文: <Reinforcement Learning thorugh Asyn ...
- IntelliJ IDEA 2024.2 发布:Spring Data JPA即时查询、自动补全cron表达式
今早看到,IntelliJ IDEA 2024.2 发布的邮件提示,看了一眼这个版本更新的新特性真的太适合我了!也许这些能力对关注DD的小伙伴也有帮助,所以搞篇博客介绍和推荐一下.下面就来一起看看这个 ...
- Python-目标检测-将xml文件转换成.txt文件
代码说明:labels文件夹是工程下的一个文件夹,里面存放的是一些xml文件. 然后我们将这些xml文件中的内容取出来,放在路径path1的文件名下.这样也就完成了xml文件到txt文件的转化. 该代 ...
- 【单调栈+倍增】[P7167 [eJOI2020 Day1] Fountain
[单调栈+倍增][P7167 [eJOI2020 Day1] Fountain 思路 用单调栈处理每个圆盘溢出后流到的第一个位置,然后倍增优化. 代码 #include <bits/stdc++ ...
- AtCoder Beginner Contest 362
AtCoder Beginner Contest 362 前言 vp 的时候出了四题,被 C 题卡了一会,很久才出,D 题是 dijkstra 的板子,改下条件即可,E 题是个计数 dp,这类题一直不 ...
- 巴特沃斯LPF设计(硬件电路实现)
高阶 (2n) VSVC单位增益巴特沃斯低通滤波器设计,可分解为 n 个二阶低通,通过对这多个二阶低通的组合优化,可提高滤波器的低通特性和稳定性. 串联的传递函数是各个二阶滤波器传递函数的乘积:\({ ...
- webpack高版本抽离css样式报错[已解决]
全局安装的webpack版本是5.51.1,webpack-cli是4.9的版本; 本来想用 extract-text-webpack-plugin 的,但是报错了,查了一下文档 发现,已经不支持新版 ...
- 小tips:前端容易读错的单词列表
排名第一的是width,音标/wɪdθ/,发/i/的音,不是发/ai/的音: hidden音标/ˈhɪdn/发/i/的音,不是发/ai/的音: hide音标/haɪd/,发/ai/的音: float音 ...
- Angular 18+ 高级教程 – Angular 的局限 の Query Elements
前言 熟悉 Angular 的朋友都知道,Angular 有非常多的局限,许多事情它都做不好,打开 Github 一堆 2016 - 2017 的 Issues,时至今日都没有解决. 原因也很简单 - ...