<p>I need to run a python script from a KubernetesPodOperator, so I want to mount the python file into the Python docker Image. Reading some posts</p>
<ul>
<li><a href="https://stackoverflow.com/questions/57754521/how-to-mount-volume-of-airflow-worker-to-airflow-kubernetes-pod-operator">How to mount volume of airflow worker to airflow kubernetes pod operator?</a></li>
<li><a href="https://stackoverflow.com/questions/60950206/mounting-volume-issue-through-kubernetespodoperator-in-gke-airflow">Mounting volume issue through KubernetesPodOperator in GKE airflow</a></li>
<li><a href="https://stackoverflow.com/questions/69539197/mounting-folders-with-kubernetespodoperator-on-google-composer-airflow">Mounting folders with KubernetesPodOperator on Google Composer/Airflow</a></li>
<li><a href="https://github.com/apache/airflow/blob/main/airflow/providers/cncf/kubernetes/example_dags/example_kubernetes.py#L107" rel="nofollow noreferrer">https://github.com/apache/airflow/blob/main/airflow/providers/cncf/kubernetes/example_dags/example_kubernetes.py#L107</a></li>
<li><a href="https://www.aylakhan.tech/?p=655" rel="nofollow noreferrer">https://www.aylakhan.tech/?p=655</a></li>
</ul>
<p>it doesn't get clear at all for me.</p>
<p>The python file is located in the route <code>/opt/airflow/dags/test_dag</code>, so I would like to mount the entire folder and not only the script. I have tried with:</p>
<pre><code>    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=&quot;dry_run_demo&quot;,
        cluster_name=&quot;eks&quot;,
        namespace=&quot;data&quot;,
        image=&quot;python:3.9-buster&quot;,
        volumes=[volume],
        volume_mounts=[vol1],
        arguments=[&quot;echo&quot;, &quot;10&quot;],
    )
</code></pre>
<p>But I am getting the error:</p>
<blockquote>
<p>Pod &quot;pod.388baaaa7c27489c9dd5f7f37ee8ce5b&quot; is invalid: spec.containers[0].volumeMounts[0].name: Not found: &quot;test_volume\</p>
</blockquote>
<p>I am using Airflow 2.1.1 deployed in a EC2 with docker-compose and <code>apache-airflow-providers-cncf-kubernetes==3.0.1</code></p>
<p>EDIT: with Elad's suggestion the question was &quot;solved&quot;. Then I got the error <code>Pod Event: FailedScheduling - persistentvolumeclaim &quot;test-volume&quot; not found</code>, so I just took out the <code>persistent_volume_claim</code> argument and I didn't get any error, but I am getting an empty directory in the POD, without any file. I have read something about creating the persistentvolumeclain in the namespace, but it would be very convenient to create it manually instead of dynamically with every operator</p>

<p>The error means that the names don't match.
you defined <code>name='test_volume'</code> for <code>V1VolumeMount</code> and <code>name='test-volume</code> for <code>V1Volume</code>.</p>
<p>To solve your issue names should be identical.</p>
<pre><code>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'),
)
</code></pre>
