gpt4 book ai didi

kubernetes - 将自定义 volumeMount 添加到 Airflow worker pod 中(使用 k8s Executor)

转载 作者:行者123 更新时间:2023-12-02 11:39:25 26 4
gpt4 key购买 nike

在 airflow.conf 的 kubernetes 部分下,有一个为 dag 和日志安装 volumeMount 的选项,例如

[kubernetes]
airflow_configmap = airflow_config
worker_container_repository = airflow
worker_container_tag = runner2
worker_container_image_pull_policy = IfNotPresent
delete_worker_pods = true
dags_volume_claim = airflow-dags-pvc
dags_volume_subpath = airflow/development/dags
logs_volume_claim = airflow-logs-pvc
logs_volume_subpath = airflow/development/logs
namespace = development

这按预期工作。这意味着我可以看到 worker pod 成功地将这两个卷及其相关的 volumeMounts 安装在容器内。

   "volumeMounts": [
{
"name": "airflow-dags",
"readOnly": true,
"mountPath": "/usr/local/airflow/dags",
"subPath": "airflow/development/dags"
},
{
"name": "airflow-logs",
"mountPath": "/usr/local/airflow/logs",
"subPath": "airflow/development/logs"
},

但是,我的 worker pod 依赖于从目录 airflow/development/pluginsairflow/development/libs 中获取自定义 Airflow 插件。因此,我需要使用来自 NFS 服务器的相关子路径将更多 volumeMount 添加到 worker pod 中。我怎样才能做到这一点?我尝试搜索任何相关的配置值,但找不到。

更新:我将 executor_config 作为 executor_config={"KubernetesExecutor": {"image": "airflow: runner2"}}。通过查看代码 airflow/contrib/kubernetes/worker_configuration.py ,似乎如果我将 volumes 和 volumeMounts 作为此配置的一部分传入,它应该可以工作。我会试试这个并在这里更新。

最佳答案

抱歉,我要回答我自己的问题。也许会帮助某人。在我定义任务的 dag 文件中,我只需按如下方式添加 executor_config;

        IngestionStatusSensor(
task_id=...,
executor_config={"KubernetesExecutor": {
"image": "airflow:runner2",
"volume_mounts": [
{
"name": "airflow-dags",
"mountPath": "/usr/local/airflow/libs",
"subPath": "airflow/development/libs"
},
{
"name": "airflow-dags",
"mountPath": "/usr/local/airflow/plugins",
"subPath": "airflow/development/plugins"
}],
}
},
dag=dag,
ingestion_feed=table,
poke_interval=60 * 30,
offset=0,
start_date=start_date
)

其中 airflow-dags volume 已经由 pod 创建者定义,该 pod 创建者声明在 airflow.conf 的 kubernetes 部分下的配置中定义的 PVC,例如dags_volume_claim = airflow-pvc

关于kubernetes - 将自定义 volumeMount 添加到 Airflow worker pod 中(使用 k8s Executor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57393490/

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