gpt4 book ai didi

python - Kubernetespodoperator如何使用cmds或者cmds和arguments运行多条命令

转载 作者:行者123 更新时间:2023-12-05 04:36:15 29 4
gpt4 key购买 nike

我正在使用 GCP composer 运行算法,在流的末尾我想运行一个任务,该任务将执行多个操作,将文件和文件夹从卷复制和删除到存储桶,我正在尝试执行这些操作通过 kubernetespodoperator 复制和删除操作。我很难找到使用“cmds”运行多个命令的正确方法我也尝试过使用“cmds”和“arguments”。这是我的 KubernetesPodOperator 以及我尝试的命令和参数组合:

post_algo_run = kubernetes_pod_operator.KubernetesPodOperator(
task_id="multi-coher-post-operations",
name="multi-coher-post-operations",
namespace="default",
image="google/cloud-sdk:alpine",

### doesn't work ###
cmds=["gsutil", "cp", "/data/splitter-output\*.csv", "gs://my_bucket/data" , "&" , "gsutil", "rm", "-r", "/input"],
#Error:
#[2022-01-27 09:31:38,407] {pod_manager.py:197} INFO - CommandException: Destination URL must name a directory, bucket, or bucket
#[2022-01-27 09:31:38,408] {pod_manager.py:197} INFO - subdirectory for the multiple source form of the cp command.
####################

### doesn't work ###
# cmds=["gsutil", "cp", "/data/splitter-output\*.csv", "gs://my_bucket/data ;","gsutil", "rm", "-r", "/input"],
# [2022-01-27 09:34:06,865] {pod_manager.py:197} INFO - CommandException: Destination URL must name a directory, bucket, or bucket
# [2022-01-27 09:34:06,866] {pod_manager.py:197} INFO - subdirectory for the multiple source form of the cp command.
####################

### only preform the first command - only copying ###
# cmds=["bash", "-cx"],
# arguments=["gsutil cp /data/splitter-output\*.csv gs://my_bucket/data","gsutil rm -r /input"],
# [2022-01-27 09:36:09,164] {pod_manager.py:197} INFO - + gsutil cp '/data/splitter-output*.csv' gs://my_bucket/data
# [2022-01-27 09:36:11,200] {pod_manager.py:197} INFO - Copying file:///data/splitter-output\Coherence Results-26-Jan-2022-1025Part1.csv [Content-Type=text/csv]...
# [2022-01-27 09:36:11,300] {pod_manager.py:197} INFO - / [0 files][ 0.0 B/ 93.0 KiB]
# / [1 files][ 93.0 KiB/ 93.0 KiB]
# [2022-01-27 09:36:11,302] {pod_manager.py:197} INFO - Operation completed over 1 objects/93.0 KiB.
# [20 22-01-27 09:36:12,317] {kubernetes_pod.py:459} INFO - Deleting pod: multi-coher-post-operations.d66b4c91c9024bd289171c4d3ce35fdd
####################


volumes=[
Volume(
name="nfs-pvc",
configs={
"persistentVolumeClaim": {"claimName": "nfs-pvc"}
},
)
],
volume_mounts=[
VolumeMount(
name="nfs-pvc",
mount_path="/data/",
sub_path=None,
read_only=False,
)
],
)

最佳答案

对于您的第一个命令,您需要确保在您的 docker 中您能够到达允许您找到文件 /data/splitter-output\*.csv 的工作目录。 p>

["gsutil", "cp", "/data/splitter-output*.csv", "gs://my_bucket/data"]

您可以使用 docker RUN 在您的 docker 镜像上测试您的命令,这样您就可以验证您是否正确提供了命令。

在第二个语句中,如果您再次引用 docker 镜像中的路径,请使用 run 对其进行测试。如果您指的是谷歌存储,则必须提供完整路径。

["gsutil", "rm", "-r", "/input"]

值得一提的是,一旦容器开始运行,ENTRYPOINT 就会运行,如 understand how cmd and entrypoint interact 中所述。 .如评论中所述,如果您查看 code cmds 它取代了 docker image ENTRYPOINT。它还建议遵循 Define a Command and Arguments for a Container 的指南。

关于python - Kubernetespodoperator如何使用cmds或者cmds和arguments运行多条命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70876473/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com