<p>I have a spark job that runs via a Kubernetes pod . Till now I was using an Yaml file to run my jobs manually.
Now , I want to schedule my spark jobs via airflow.
This is the first time I am using airflow  and I am unable to figure out how I can add my Yaml file in the airflow.
From what I have read is that I can schedule my jobs via a DAG in Airflow.
A dag example is this :</p>

<pre><code>from airflow.operators import PythonOperator
from airflow.models import DAG
from datetime import datetime, timedelta

args = {'owner':'test', 'start_date' : datetime(2019, 4, 3), 'retries': 2, 'retry_delay': timedelta(minutes=1) }
dag = DAG('test_dag', default_args = args, catchup=False)

def print_text1():
    print("hell-world1")

def print_text():
    print('Hello-World2')

t1 = PythonOperator(task_id='multitask1', python_callable=print_text1, dag=dag)
t2 = PythonOperator(task_id='multitask2', python_callable=print_text, dag=dag)
t1 &gt;&gt; t2
</code></pre>

<p>In this case the above methods will get executed on after the other once I play the DAG.
Now , in case I want to run a spark submit job , what should I do?
I am using Spark 2.4.4</p>

sovan
<p>Airflow has a concept of <a href="https://airflow.apache.org/howto/operator/index.html" rel="noreferrer">operators</a>, which represent Airflow tasks. In your example <a href="https://airflow.apache.org/howto/operator/python.html" rel="noreferrer">PythonOperator</a> is used, which simply executes Python code and most probably not the one you are interested in, unless you submit Spark job within Python code. There are several operators that you can take use of:</p>

<ul>
<li><a href="https://airflow.apache.org/howto/operator/bash.html" rel="noreferrer">BashOperator</a>, which executes the given bash script for you. You may run <code>kubectl</code> or <code>spark-submit</code> using it directly</li>
<li><a href="https://airflow.apache.org/_api/airflow/contrib/operators/spark_submit_operator/index.html?highlight=spark#module-airflow.contrib.operators.spark_submit_operator" rel="noreferrer">SparkSubmitOperator</a>, the specific operator to call <code>spark-submit</code></li>
<li><a href="https://airflow.apache.org/_api/airflow/contrib/operators/kubernetes_pod_operator/index.html?highlight=kubernetes%20operator#module-airflow.contrib.operators.kubernetes_pod_operator" rel="noreferrer">KubernetesPodOperator</a>, creates Kubernetes pod for you, you can launch your Driver pod directly using it</li>
<li>Hybrid solutions, eg. <a href="https://airflow.apache.org/_api/airflow/operators/http_operator/index.html?highlight=http%20operator#module-airflow.operators.http_operator" rel="noreferrer">HttpOperator</a> + <a href="https://github.com/jahstreet/spark-on-kubernetes-helm" rel="noreferrer">Livy on Kubernetes</a>, you spin up Livy server on Kubernetes, which serves as a Spark Job Server and provides REST API to be called by Airflow HttpOperator</li>
</ul>

<p>Note: for each of the operators you need to ensure that your Airflow environment contains all the required dependencies for execution as well as the credentials configured to access the required services.</p>

<p>Also you can refer the existing thread:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/53773678/airflow-sparksubmitoperator-how-to-spark-submit-in-another-server">Airflow SparkSubmitOperator - How to spark-submit in another server</a></li>
</ul>
