如何将 folder/file 挂载到 KubernetesPodOperator Airflow
How to mount folder/file to KubernetesPodOperator Airflow
我需要 运行 来自 KubernetesPodOperator 的 python 脚本,所以我想将 python 文件装载到 Python docker 图像中。阅读一些帖子
- Mounting folders with KubernetesPodOperator on Google Composer/Airflow
- https://github.com/apache/airflow/blob/main/airflow/providers/cncf/kubernetes/example_dags/example_kubernetes.py#L107
- https://www.aylakhan.tech/?p=655
我一点都不清楚。
python 文件位于路径 /opt/airflow/dags/test_dag
中,所以我想挂载整个文件夹,而不仅仅是脚本。我试过:
vol1 = k8s.V1VolumeMount(
name='test_volume', mount_path='/opt/airflow/dags/test_dag'
)
volume = k8s.V1Volume(
name='test-volume',
persistent_volume_claim=k8s.V1PersistentVolumeClaimVolumeSource(claim_name='test-volume'),
)
k = KubernetesPodOperator(
task_id="dry_run_demo",
cluster_name="eks",
namespace="data",
image="python:3.9-buster",
volumes=[volume],
volume_mounts=[vol1],
arguments=["echo", "10"],
)
但我收到错误消息:
Pod "pod.388baaaa7c27489c9dd5f7f37ee8ce5b" is invalid: spec.containers[0].volumeMounts[0].name: Not found: "test_volume\
我正在使用部署在 EC2 中的 Airflow 2.1.1 docker-compose 和 apache-airflow-providers-cncf-kubernetes==3.0.1
编辑:根据 Elad 的建议,问题已“解决”。然后我得到错误 Pod Event: FailedScheduling - persistentvolumeclaim "test-volume" not found
,所以我只是取出 persistent_volume_claim
参数并且我没有得到任何错误,但是我在 POD 中得到一个空目录,没有任何文件。我已经阅读了一些关于在命名空间中创建 persistentvolumeclain 的内容,但是手动创建它而不是使用每个运算符动态创建它会非常方便
错误意味着名称不匹配。
您为 V1VolumeMount
定义了 name='test_volume'
,为 V1Volume
定义了 name='test-volume
。
要解决您的问题,名称应该相同。
vol1 = k8s.V1VolumeMount(
name='test-volume', mount_path='/opt/airflow/dags/test_dag'
)
volume = k8s.V1Volume(
name='test-volume',
persistent_volume_claim=k8s.V1PersistentVolumeClaimVolumeSource(claim_name='test-volume'),
)
我需要 运行 来自 KubernetesPodOperator 的 python 脚本,所以我想将 python 文件装载到 Python docker 图像中。阅读一些帖子
- Mounting folders with KubernetesPodOperator on Google Composer/Airflow
- https://github.com/apache/airflow/blob/main/airflow/providers/cncf/kubernetes/example_dags/example_kubernetes.py#L107
- https://www.aylakhan.tech/?p=655
我一点都不清楚。
python 文件位于路径 /opt/airflow/dags/test_dag
中,所以我想挂载整个文件夹,而不仅仅是脚本。我试过:
vol1 = k8s.V1VolumeMount(
name='test_volume', mount_path='/opt/airflow/dags/test_dag'
)
volume = k8s.V1Volume(
name='test-volume',
persistent_volume_claim=k8s.V1PersistentVolumeClaimVolumeSource(claim_name='test-volume'),
)
k = KubernetesPodOperator(
task_id="dry_run_demo",
cluster_name="eks",
namespace="data",
image="python:3.9-buster",
volumes=[volume],
volume_mounts=[vol1],
arguments=["echo", "10"],
)
但我收到错误消息:
Pod "pod.388baaaa7c27489c9dd5f7f37ee8ce5b" is invalid: spec.containers[0].volumeMounts[0].name: Not found: "test_volume\
我正在使用部署在 EC2 中的 Airflow 2.1.1 docker-compose 和 apache-airflow-providers-cncf-kubernetes==3.0.1
编辑:根据 Elad 的建议,问题已“解决”。然后我得到错误 Pod Event: FailedScheduling - persistentvolumeclaim "test-volume" not found
,所以我只是取出 persistent_volume_claim
参数并且我没有得到任何错误,但是我在 POD 中得到一个空目录,没有任何文件。我已经阅读了一些关于在命名空间中创建 persistentvolumeclain 的内容,但是手动创建它而不是使用每个运算符动态创建它会非常方便
错误意味着名称不匹配。
您为 V1VolumeMount
定义了 name='test_volume'
,为 V1Volume
定义了 name='test-volume
。
要解决您的问题,名称应该相同。
vol1 = k8s.V1VolumeMount(
name='test-volume', mount_path='/opt/airflow/dags/test_dag'
)
volume = k8s.V1Volume(
name='test-volume',
persistent_volume_claim=k8s.V1PersistentVolumeClaimVolumeSource(claim_name='test-volume'),
)