How do I troubleshoot Amazon EMR on EKS Spark job configuration and completion issues?
I want to troubleshoot Amazon EMR on Amazon Elastic Kubernetes Service (Amazon EKS) Spark jobs. The jobs are on the wrong nodes, fail to start, or never report completion.
Short description
An Amazon EMR on Amazon EKS Spark job can run on unintended nodes, fail to start, or stay in RUNNING state indefinitely. This might happen for one of the following reasons:
- An incorrect node selector property name that Spark silently ignores
- A Docker image that doesn't match the node CPU architecture
- A custom JAR that an executor can't load at startup
- A third-party shuffle plugin that prevents idle executors from scaling down
- A service mesh sidecar container that prevents the pod from reporting completion
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Resolve node selector syntax errors
The Spark on Kubernetes node selector configuration uses a specific property naming convention. An incorrect property name causes Spark to silently ignore the node selector, to not raise an error, and to schedule pods on unintended nodes.
For Spark 3.3 or later for versions on Amazon EMR on EKS 6.9 and later, the token is node.selector. The role-scoped form specifically targets executors.
Make sure that you use the following correct property name in the configuration:
spark.kubernetes.executor.node.selector.karpenter.sh/nodepool
For Spark 3.2 or earlier for versions on Amazon EMR on EKS 6.8 and earlier, use the combined property that applies to both driver and executor pods.
Example property name:
spark.kubernetes.node.selector.karpenter.sh/nodepool
Note: If you don't know the Amazon EMR version or you don't choose to separately target the driver and executor pods, then use the combined spark.kubernetes.node.selector.* form.
Resolve Docker image platform mismatch
If your Karpenter NodePool provisions ARM64 AWS Graviton instances but your Docker image is for only AMD64, then the container runtime can't run the image. The pod then immediately fails.
To resolve, run the following command to rebuild your image as a multi-platform image:
docker buildx build --platform linux/amd64,linux/arm64 -t IMAGE
Note: Replace IMAGE with your container image tag.
Resolve custom JAR ClassNotFoundException
If you use a custom JAR such as a third-party shuffle manager, then the driver and executor JVMs load the referenced class during SparkEnv initialization. This attempt to load happens before Spark downloads the JAR that spark.jars specifies, so the class isn't available yet and initialization fails. To resolve this failure, make the JAR part of the container image so that it's present before the JVM starts. Build a custom Docker image with the JAR in /usr/lib/spark/jars/. This path is already on the default Spark classpath and requires no additional configuration.
If you place the JAR at a different path in the image, or mount it from a volume, then add that path to the classpath for both the driver and the executors. To specify the class path, use the following path:
"spark.driver.extraClassPath": "/opt/jars/your-plugin.jar" "spark.executor.extraClassPath": "/opt/jars/your-plugin.jar"
Note: Replace your-plugin.jar with the name of your JAR.
Resolve idle executors with third-party shuffle plugins
If you use a custom shuffle manager, then the Spark ExecutorAllocationManager might not recognize it as a valid external shuffle service. The allocator then operates in a conservative mode, refuses to scale down idle executors, and leaves hundreds of idle pods running.
With dynamic allocation turned on, Spark requires a mechanism to preserve shuffle data before it can decommission an executor. Amazon EMR on EKS has no external shuffle service, so Spark relies on one of the remaining mechanisms. If none is configured, the driver fails at startup with the error "org.apache.spark.SparkException: Dynamic allocation of executors". Because of this requirement, don't disable shuffle tracking on its own. If you set only spark.dynamicAllocation.shuffleTracking.enabled=false with dynamic allocation turned on, then none of the required conditions are satisfied. The job fails before an executor starts. Instead, use one of the following options to pass settings in the applicationConfiguration of the spark-defaults classification in your StartJobRun API calls.
Option 1 (recommended): Keep shuffle tracking on with a timeout
To let Spark release idle executors after a timeout with shuffle tracking, pass the following settings:
`"spark.dynamicAllocation.enabled": "true",` "spark.dynamicAllocation.shuffleTracking.enabled": "true", "spark.dynamicAllocation.shuffleTracking.timeout": "300s", "spark.dynamicAllocation.minExecutors": "1", "spark.dynamicAllocation.maxExecutors": "5"
Option 2: Turn off shuffle tracking but turn on shuffle-block decommissioning
To shuffle blocks off an executor before it's removed, pass the following settings:
"spark.dynamicAllocation.enabled": "true", "spark.dynamicAllocation.shuffleTracking.enabled": "false", "spark.decommission.enabled": "true", "spark.storage.decommission.enabled": "true", "spark.storage.decommission.shuffleBlocks.enabled": "true", "spark.dynamicAllocation.minExecutors": "1", "spark.dynamicAllocation.maxExecutors": "5"
Pass these settings in the applicationConfiguration of the spark-defaults classification in your StartJobRun API call.
Note: Amazon EMR doesn't officially support third-party Spark plugins. The spark.storage.decommission.shuffleBlocks.enabled setting requires Spark 3.1 or later.
Resolve a service mesh (Istio) sidecar that prevents job completion
Your sidecar proxy container istio-proxy can continue to run after the Spark driver container completes. If a container is active, then Kubernetes considers a pod to be running and Amazon EMR on EKS doesn't detect job completion. The job stays in the RUNNING state.
To check container statuses on the driver pod, run the following command:
kubectl get pod DRIVER_POD -n NAMESPACE -o jsonpath='{range .status.containerStatuses[*]}{.name}{"\t"}{.state}{"\n"}{end}'
Note: Replace DRIVER_POD with your driver pod name and NAMESPACE with your Amazon EMR namespace.
In the output, if spark-kubernetes-driver and emr-container-fluentd show a terminated state with 0 but istio-proxy shows a RUNNING state, then Istio prevents the completion.
To resolve, run the following command to turn off Istio injection on the Amazon EMR on EKS namespace:
kubectl label namespace NAMESPACE istio-injection=disabled
Note: Replace NAMESPACE with your Amazon EMR namespace.
Or, to resolve, if the namespace requires Istio, then use Istio native sidecar container support to automatically stop sidecars when the main container exits. See Kubernetes Native Sidecars in Istio on the Istio website.
Note: Istio's native sidecar container support is available for Kubernetes versions 1.28 and later.
Resolve VPC CNI IP address assignment failures
If the Amazon Virtual Private Cloud (Amazon VPC) CNI plugin can't assign an IP address to the driver pod, then the pod stays in ContainerCreating state. The plugin then times out. For troubleshooting steps, see How do I troubleshoot the Amazon VPC CNI add-on?
Related information
Troubleshooting Amazon EMR on EKS
Using pod templates with Amazon EMR on EKS
Running Spark jobs with Amazon EMR on EKS
EMR on EKS Best Practices Guide
How do I troubleshoot Amazon EMR on EKS Spark driver and executor pod failures?
- Topics
- Analytics
- Tags
- Amazon EMR
- Language
- English

Relevant content
asked 4 years ago
AWS OFFICIALUpdated 2 years ago