Integrating Cloudera Workflow Orchestrator with Spark on YARN cluster
Integrate Cloudera Workflow Orchestrator operators and hooks with Spark on the YARN cluster to use Spark from Cloudera Workflow Orchestrator.
- You must have the YARN service available in the Cloudera Runtime environment.
- The default Cloudera Workflow Orchestrator distribution excludes spark-submit binaries. To execute Spark jobs, create a custom Cloudera Workflow Orchestrator image equipped with binaries matching your target Cloudera Runtime environment. For more information about including spark-submit in a custom image, see Including spark-submit in a custom Cloudera Workflow Orchestrator image.
- Sign in to Cloudera Manager.
- In the left navigation, click Clusters.
- Click on the YARN cluster.
-
In the YARN cluster, select the Download Client
Configuration option from the Actions
drop-down menu to download configuration files.
Figure 1. Download Client Configuration option in the Actions menu
-
Create a Cloudera Workflow Orchestrator connection for YARN using either
the Cloudera Workflow Orchestrator UI or the command line.
- In the Cloudera Workflow Orchestrator UI, perform the following
steps:
- Sign in to Cloudera Workflow Orchestrator from Anywhere Cloud Console.
- Click Admin > Connections > Add Connection.
- Add the following configurations:
- Connection ID: Create a unique connection identifier. For example, spark_yarn.
- Connection Type: Select Spark.
- Description: Enter a description about the connection.
- Host: Enter the hostname as yarn.
- Port: Leave it blank.
- YARN queue: Leave it blank.
- Deploy mode: Enter the deployment
mode. Valid values are
clientorcluster. The default value isclient. - Spark binary: Enter the Spark
submit binary to use. Valid values are
spark-submit,spark2-submit, orspark3-submit. The default value isspark-submit.The
spark_binaryvalue must be the same as the spark-submit custom image built in the Prerequisites. - Kubernetes namespace: Leave it blank.
- Principal: Leave it blank.
- Keytab: Leave it blank.
- REST scheme: Leave it blank.
- REST port: Leave it blank.
- YARN ResourceManager webapp address: Leave it blank.
- Extra: Enter additional arguments in the text box.
- Click Save.
- In the Cloudera Workflow Orchestrator UI, perform the following
steps:
- Extract the downloaded YARN configurations (downloaded in step 4) and copy them to the Git repository containing your DAG files. For information about adding extra files, see Adding and accessing static extra files (DAG bundles).
-
Copy the Spark application to the Git repository containing your DAG files. For
information about adding extra files, see Adding and accessing static extra files (DAG
bundles).
-
Create a DAG for your Cloudera Workflow Orchestrator and use the
previously created Cloudera Workflow Orchestrator connection in the
DAG.
Example
from datetime import datetime from airflow.sdk import DAG from airflow.providers.apache.spark.operators.spark_submit import SparkSubmitOperator from kubernetes.client import models as k8s # Increase worker pod memory to avoid OOMKilled state because of high memory usage when running spark-submit executor_config_override = { "pod_override": k8s.V1Pod( spec=k8s.V1PodSpec( containers=[ k8s.V1Container( name="base", resources=k8s.V1ResourceRequirements(requests={"memory": "2G"}, limits={"memory": "2G"}) ) ] ) ) } with DAG( dag_id="example_spark_on_yarn", schedule=None, start_date=datetime(2026, 1, 1), catchup=False ) as dag: yarn_cluster_secure = SparkSubmitOperator( application="{{ task_instance.bundle_instance.path }}/dags/spark/pi.py", task_id="submit_job", deploy_mode="cluster", conn_id="spark_yarn", env_vars={ "HADOOP_USER_NAME": "hdfs", # In Cloudera Runtime, Hadoop user "hdfs" is used to access Hadoop filesystem "YARN_CONF_DIR": "{{ task_instance.bundle_instance.path }}/dags/yarn-conf", "HADOOP_CONF_DIR": "{{ task_instance.bundle_instance.path }}/dags/yarn-conf", }, executor_config=executor_config_override )In this example, the YARN configurations and the Spark application are included in the yarn-conf folder inside the DAG files directory.
