<p>I am trying to create and run a pod using Airflow kubernetes pod operator.
The command below is tried and confirmed to be working and I am trying to replicate the same using the kubernetes pod operator locally</p>
<pre><code>kubectl run sparkairflow -n test-namespace --image=some-docker-repo.com:hello-world --serviceaccount=airflow --restart=Never -- spark-submit --deploy-mode cluster --master k8s://kubernetes.default.cluster.local:123 \
                 --name sparkairflow \
                 --conf spark.kubernetes.namespace=test-namespace \
                 --conf spark.kubernetes.container.image=some-docker-repo.com:hello-world \
                 --conf spark.kubernetes.authenticate.driver.serviceAccountName=airflow \
...
</code></pre>
<p>Running into a wall here because there does not seem to be a way pass the --serviceaccount flag using airflow and that is required for my implementation and that throws the error on my side.</p>
<blockquote>
<p>Exception in thread &quot;main&quot; io.fabric8.kubernetes.client.KubernetesClientException: pods &quot;sparkairflow-155252344-driver&quot; is forbidden: User &quot;system:serviceaccount:test-namespace:default&quot; cannot watch resource &quot;pods&quot; in API group &quot;&quot; in the namespace &quot;test-namespace&quot;: access denied</p>
</blockquote>
<p>The solutions I found up until now mostly focus on adding the default user to the namespace role but that is not possible for my case.</p>
<p>Any way to pass in the serviceaccount flag to airflow kubernetes operator?</p>
<p>Thanks!</p>

<p>The KubernetesPodOperator contains a parameter <code>service_account_name</code> with which which you can specify the K8s service account. It is available for both Airflow v2 and v1.10, the latter is just not documented.</p>
<p>Example call (mostly taken from <a href="https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes/stable/operators.html" rel="nofollow noreferrer">https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes/stable/operators.html</a>):</p>
<pre class="lang-py prettyprint-override"><code>quay_k8s = KubernetesPodOperator(
    namespace='default',
    image='quay.io/apache/bash',
    service_account_name=&quot;my_k8s_svc_acct&quot;,
    cmds=[&quot;bash&quot;, &quot;-cx&quot;],
    name=&quot;airflow-private-image-pod&quot;,
    task_id=&quot;task-two&quot;,
)
</code></pre>
