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.
  1. Sign in to Cloudera Manager.
  2. In the left navigation, click Clusters.
  3. Click on the YARN cluster.
  4. 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
  5. 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:
      1. Sign in to Cloudera Workflow Orchestrator from Anywhere Cloud Console.
      2. Click Admin > Connections > Add Connection.
      3. 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 client or cluster. The default value is client.
        • Spark binary: Enter the Spark submit binary to use. Valid values are spark-submit, spark2-submit, or spark3-submit. The default value is spark-submit.

          The spark_binary value 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.
      4. Click Save.
  6. 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).
  7. 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).
  8. 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.