在 Argo Workflow 中,可以使用 sh
容器步骤来执行命令,并将命令的输出重定向到文件而不打印。
下面是一个示例的 Argo Workflow YAML 文件:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: redirect-echo-example-
spec:
entrypoint: redirect-echo-example
templates:
- name: redirect-echo-example
steps:
- - name: echo-to-file
template: echo-to-file
# 定义 echo-to-file 步骤的模板
- name: echo-to-file
container:
image: alpine:latest
command: [sh, -c]
args:
- echo "Hello, World!" > /path/to/output.txt
在这个示例中,我们定义了一个名为 redirect-echo-example
的 Workflow,其中包含一个名为 echo-to-file
的步骤模板。
步骤模板中的容器使用 Alpine Linux 镜像,并执行 echo "Hello, World!" > /path/to/output.txt
命令将输出重定向到 /path/to/output.txt
文件。
要在 Argo Workflow 中运行这个示例,可以使用以下命令:
kubectl create -f workflow.yaml
这将创建一个名为 redirect-echo-example-xxxxx
的 Workflow。你可以使用以下命令来查看 Workflow 的状态:
argo get
当 Workflow 完成后,你可以使用以下命令来查看输出文件的内容:
argo logs redirect-echo-example-xxxxx-xxxxx -c echo-to-file
这将显示输出文件 /path/to/output.txt
的内容。
希望这个示例对你有帮助!