【问题标题】:Airflow - Kubernetes Executor : How to only mount only a directory of a Persistent Volume Claim that correspond to the run_idAirflow - Kubernetes Executor:如何仅挂载与 run_id 对应的持久卷声明的目录
【发布时间】:2020-03-22 02:24:48
【问题描述】:

我正在将气流与 kubernetes 执行器一起使用。

当我使用 executor_config 挂载 PersistentVolumeClaim 时,它可以工作。

但是,我只想安装一个动态的 subPath,如下所示:

executor_config={
    "KubernetesExecutor":
    {"volumes": [
                {
                    "name": "workdir-volume",
                    "persistentVolumeClaim": {"claimName": "my-volume-claim"},
                },
            ],
     "volume_mounts": [
                {
                    "mountPath": "/app/workdir/",
                    "name": "workdir-volume",
                    "subPath": "{{ run_id }}_{{ ds }}"
                },
            ]}
},

它不起作用有两个原因:

  • executor_config 不在 template_fields 中。因此,我创建了一个包含 executor_config 的新运算符。

  • 我的理解是渲染只在 pod 启动后完成,因为当我从仪表板查看渲染的任务时,它很好,但是挂载的目录没有渲染

有人知道如何做到这一点吗?

【问题讨论】:

    标签: python kubernetes airflow


    【解决方案1】:

    这是不可行的 AFAIK,因为 run_idds 仅适用于每个 DAG/任务运行。您需要在脚本中通过在任务定义中传入参数来处理此问题。示例:

    t1 = BashOperator(
            task_id='t1',
            bash_command="extract.py --path='{{run_id}}'")
    ...
    

    使用参数,让脚本创建子目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 2019-08-11
      • 1970-01-01
      • 2020-11-08
      • 2019-10-29
      相关资源
      最近更新 更多