Spark on YARN
| Also known as | Running Spark on Hadoop YARN |
|---|---|
| Field | Cluster resource management |
| Key parts | YARN ResourceManager, NodeManagers, containers, the Spark application master, queues |
| Open source implementations | Apache Spark with Apache Hadoop YARN |
| Related | Spark standalone cluster manager, Spark on Kubernetes, spark-submit, Executor |
Spark on YARN is the deployment of Apache Spark applications on Apache Hadoop YARN (Yet Another Resource Negotiator), where the YARN ResourceManager grants containers on cluster nodes and Spark runs its application master, its driver (in cluster mode) and its executors inside those containers.[1] It lets Spark share a Hadoop cluster with other YARN workloads under the same queues and Kerberos security.[1] YARN is one of the three cluster managers supported in Spark 4.3.0, with the standalone manager and Kubernetes.[2]
Is Spark on YARN deprecated?
No. YARN support is not deprecated in Spark 4.3.0; the cluster mode overview lists Hadoop YARN as a supported cluster manager.[2] Individual YARN settings have been deprecated: since Spark 3.5, spark.yarn.max.executor.failures and spark.yarn.executor.failuresValidityInterval are replaced by spark.executor.maxNumFailures and spark.executor.failuresValidityInterval.[3]
History
Spark 0.6.0 added experimental support for running on YARN, then in a separate branch; the Spark documentation dates YARN support to that release.[4][1]
How does Spark run on YARN?
Every Spark application on YARN has an application master (AM), a process managed by YARN that requests executor containers from the ResourceManager; in cluster mode the driver also runs inside it. In YARN terminology, both executors and the AM run inside containers.[1]
Spark does not take the ResourceManager address from --master. The master URL is simply yarn, and Spark reads the cluster location from the Hadoop configuration directory given by HADOOP_CONF_DIR or YARN_CONF_DIR; that configuration is also shipped to every container.[1]
What is the difference between client and cluster mode on YARN?
| Cluster mode | Client mode | |
|---|---|---|
| Where the driver runs | Inside the YARN application master container | In the client process that ran spark-submit
|
| Role of the AM | Runs the driver and requests executors | Only requests executors |
| Can the client exit? | Yes, after the application starts | No, the driver lives in it |
| AM sizing | spark.driver.memory, spark.driver.cores |
spark.yarn.am.memory (default 512m), spark.yarn.am.cores (default 1)
|
| Local directories of the driver | YARN's yarn.nodemanager.local-dirs |
spark.local.dir
|
Source: Running Spark on YARN (Spark 4.3.0).[1]
The Spark documentation runs interactive shells such as spark-shell in client mode, where the console stays attached to the driver. In cluster mode, local files that the driver needs must be shipped with --jars, --files or --archives, because the driver runs on another machine.[1]
export HADOOP_CONF_DIR=/etc/hadoop/conf
./bin/spark-submit \
--master yarn \
--deploy-mode cluster \
--queue analytics \
--driver-memory 4g \
--executor-memory 8g \
--executor-cores 4 \
--num-executors 20 \
etl_job.py
How do queues work?
YARN schedules applications into queues defined by the cluster's YARN scheduler configuration. A Spark application chooses its queue with --queue or spark.yarn.queue, which defaults to default.[1] Whether YARN honors the number of cores requested when placing containers depends on which YARN scheduler is in use and how it is configured.[1] spark.yarn.tags attaches YARN application tags that can be used to filter applications.[1]
How is container memory sized?
Each executor container on YARN holds the executor heap (spark.executor.memory) plus non-heap overhead (spark.executor.memoryOverhead), which defaults to the executor memory times spark.executor.memoryOverheadFactor with a minimum of spark.executor.minMemoryOverhead. The overhead covers JVM overheads, interned strings and other native memory, and includes PySpark worker memory unless spark.executor.pyspark.memory is set.[5] In client mode the AM has its own overhead, spark.yarn.am.memoryOverhead, which defaults to 10% of the AM memory with a minimum of 384 MiB.[1] The Executor article covers the memory layout inside the heap.
On YARN, spark.executor.cores defaults to 1 and spark.executor.instances (--num-executors) to 2.[5][1]
What still matters when running Spark on YARN?
- Java version. Spark 4.0.0 and later need at least Java 17, and Hadoop supports Java 17 from 3.5.0. On a YARN cluster with an older Hadoop, the Spark documentation says to configure a separate JDK for Spark by setting
JAVA_HOMEfor the AM (spark.yarn.appMasterEnv.JAVA_HOME) and executors (spark.executorEnv.JAVA_HOME).[1] - Spark JARs. Unless
spark.yarn.archiveorspark.yarn.jarspoints to a prepared copy, Spark zips every JAR under$SPARK_HOME/jarsand uploads it to the distributed cache for each application.[1] - Hadoop classpath. A Spark distribution built with Hadoop does not add YARN's classpath to the application by default (since Spark 3.1), to avoid dependency conflicts;
spark.yarn.populateHadoopClasspath=truechanges this.[1][3] - Dynamic allocation and shuffle files. To remove executors without losing their shuffle files, Spark needs an external shuffle service, shuffle tracking, shuffle block migration on decommission, or a reliable shuffle storage plugin.[6] On YARN the external shuffle service runs inside each NodeManager as the auxiliary service
spark_shuffle, implemented byorg.apache.spark.network.yarn.YarnShuffleServicefrom thespark-<version>-yarn-shuffle.jar.[1] - Kerberos. On YARN, Spark obtains delegation tokens for the default Hadoop file system and for the service that hosts the application's staging directory; an application can log in to the Kerberos KDC with
--principaland--keytab.[1][7] - Logs. With YARN log aggregation (
yarn.log-aggregation-enable), container logs are copied to HDFS after the application ends and can be read withyarn logs -applicationId <app ID>.[1] - Retries.
spark.yarn.maxAppAttemptssets how many times YARN attempts the application, and must not exceed YARN's ownyarn.resourcemanager.am.max-attempts.[1]
See also
- spark-submit
- Spark on Kubernetes
- Spark standalone cluster manager
- Spark configuration precedence
- Executor
- Driver (Apache Spark)
- Hive on Spark
References
- ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 Running Spark on YARN (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.0 2.1 Cluster Mode Overview (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 3.0 3.1 Migration Guide: Spark Core (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Release 0.6.0. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 5.0 5.1 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Job Scheduling (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SparkSubmitArguments.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.