Skip to content

How do I troubleshoot Amazon EMR on EKS Spark driver and executor pod failures?

9 minute read
0

I want to troubleshoot why Amazon EMR on Amazon Elastic Kubernetes Service (Amazon EKS) terminates, evicts, or preempts my Spark driver and executor pods after my job starts running.

Short description

After an Amazon EMR on Amazon EKS job transitions to a RUNNING state, the Spark driver and executor pods might terminate. Possible causes of the termination include memory exhaustion, ephemeral-storage pressure, node termination, or external factors.

You might receive one of the following error messages:

  • "JobRun failed. Job Driver pod was killed, evicted or preempted"
  • "JobRun failed. Main Spark container terminated with errors" with exit code 137 (out of memory) or 143 (SIGTERM)
  • "Lost executor N on : The executor with id N was deleted by a user or the framework"
  • "MetadataFetchFailedException: Missing an output location for shuffle 0 partition N"

To resolve these issues, identify the failure type, collect the right logs, and read the pod exit code. Then, apply the resolution for the root cause.

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.

Identify the failure type

To check the job status and failure reason, run the following describe-job-run AWS CLI command:

aws emr-containers describe-job-run \
  --virtual-cluster-id VIRTUAL_CLUSTER_ID \
  --id JOB_RUN_ID \
  --query 'jobRun.{state:state,stateDetails:stateDetails,failureReason:failureReason}'

Note: Replace VIRTUAL_CLUSTER_ID with your virtual cluster ID and JOB_RUN_ID with your job run ID.

Collect driver and executor logs

If the pod is still running, then retrieve live logs from the driver and executor pods.

Note: After Kubernetes deletes or cleans up pods, you can't run kubectl commands against them.

To list all the pods in your namespace, run the following command:

kubectl get pods -n NAMESPACE

Note: Replace NAMESPACE with your Amazon EMR namespace.

To retrieve the logs from the Spark driver container, run the following command:

kubectl logs DRIVER_POD -n NAMESPACE -c spark-kubernetes-driver

Note: Replace DRIVER_POD with your driver pod name and NAMESPACE with your Amazon EMR namespace.

To retrieve logs from a Spark executor pod, run the following command:

kubectl logs EXECUTOR_POD -n NAMESPACE

Note: Replace EXECUTOR_POD with your executor pod name and NAMESPACE with your Amazon EMR namespace.

To see detailed information about your pod, run the following command:

kubectl describe pod POD -n NAMESPACE

Note: Replace POD with your affected pod name and NAMESPACE with your Amazon EMR namespace.

If Kubernetes terminated the pod, then check the Amazon Simple Storage Service (Amazon S3) logging location that's configured in your job's monitoringConfiguration.

Use the following path to review your logs:

s3://S3_BUCKET/VIRTUAL_CLUSTER_ID/jobs/JOB_RUN_ID/containers/

Note: Replace VIRTUAL_CLUSTER_ID with your virtual cluster ID and JOB_RUN_ID with your job run ID.

If logs don't exist in Amazon S3, then Kubernetes terminated the job before logs completed. This shows a pod-level issue such as a resource constraint or an eviction.

To check the fluentd sidecar container for errors, run the following command:

kubectl logs POD -n NAMESPACE -c emr-container-fluentd

Note: Replace POD with your affected pod name and NAMESPACE with your Amazon EMR namespace.

Then, check the Spark History Server to confirm whether the Spark stages completed or failed. For more information, see Connect to the Spark UI running on the driver pod.

Diagnose by exit code

If the kernel or the kubelet forcibly stopped the pod because it exceeded its memory or ephemeral-storage limit, then you receive the "Exit code 137 (SIGKILL)".

To check whether the pod stopped because it ran out of memory, run the following command:

kubectl describe pod POD -n NAMESPACE | grep -A 3 "Last State"

Note: Replace POD with your affected pod name and NAMESPACE with your Amazon EMR namespace.

In the output, look under Reason for the OOMKilled code. If the output doesn't show OOMKilled, then ephemeral-storage eviction, Spot Instance reclamation, or an external factor terminated the pod.

If a Spot Instance is reclaimed, then you receive an "Exit code 143 (SIGTERM)" that shows the pod received a graceful termination signal. Then, Karpenter expires or disrupts the node, an external automation system ends the pod, or the node is drained for maintenance. To identify the cause, check the node events:

kubectl get events -n NAMESPACE --sort-by=.lastTimestamp | grep POD
kubectl get nodes | grep NODE

Note: Replace NAMESPACE with your Amazon EMR namespace, POD with the affected pod name, and NODE with the affected node name.

Resolve memory (out of memory) failures

If executors or drivers stopped with "Exit code 137" because of memory exhaustion, then increase the memory and overhead values in your Spark configuration. It's a best practice to maintain an overhead memory value between 10 and 20% of the executor memory value.

For example:

{
  "classification": "spark-defaults",
  "properties": {
    "spark.executor.memory": "50g",
    "spark.executor.memoryOverhead": "10g",
    "spark.driver.memory": "32g",
    "spark.driver.memoryOverhead": "6g"
  }
}

If you must reduce memory pressure per executor, then lower the number of cores and increase the number of executor instances to spread the workload.

If you see a "MetadataFetchFailedException" error, then executors that held shuffle data stopped before downstream stages could read the data. Because an out-of-memory termination is a SIGKILL, the executor has no opportunity to preserve its shuffle data. Reduce the input data size per batch, or increase executor memory so that the executors survive the stage. 

Resolve ephemeral-storage evictions

Spark shuffle and spill operations write temporary data to the local disk. If the data exceeds the available ephemeral storage that's on the node, then the kubelet evicts the pod.

To check for disk pressure on the affected node, run the following command:

kubectl describe node NODE | grep -A 5 "Conditions"

Note: Replace NODE with the affected node name.

If DiskPressure has a True value in the output, then increase the data volume size in your launch template or Karpenter NodePool configuration. Identify the volume by its mount point or Amazon Elastic Block Store (Amazon EBS) device mapping. Don't identify the volume by the device name because NVMe enumeration order isn't guaranteed

Note: On Bottlerocket operating system (OS) nodes, container ephemeral storage uses a separate data volume, not the root volume. If you increase the root volume, then there's no reduction of disk pressure.

To prevent evictions, add ephemeral-storage requests and limits to your pod template:

resources:
  requests:
    ephemeral-storage: "50Gi"
  limits:
    ephemeral-storage: "100Gi"

To preserve logs when Kubernetes evicts your pods, turn on Spark event logging to Amazon S3:

"spark.eventLog.enabled": "true",
"spark.eventLog.dir": "s3://S3_BUCKET/spark-event-logs/"

Resolve Spot Instance termination and executor replacement

When AWS reclaims Spot Instances, it terminates executor pods. Kubernetes doesn't recreate them, because Spark executor pods aren't managed by a controller such as a Deployment or StatefulSet. Instead, the Spark driver requests replacement executors.

A replacement executor starts only if there's capacity to schedule it. If your node group or Karpenter NodePool can't provision a new node, then the executor count stays below the target for the rest of the job. For example, your node group or Karpenter node might not provision a new node because the Spot capacity pool is exhausted, or because a custom scaler doesn't react.

Amazon EMR on EKS has no built-in monitoring to detect a zero-executor stall. If the driver pod is running, then Amazon EMR considers the job active, so a job can sit with no executors indefinitely. Amazon EMR doesn't mark the job  as failed.

For Spark to automatically request replacements, turn on dynamic allocation with a minimum executor count. Spark then continues to request executors as capacity becomes available. Pass these settings in the configurationOverrides parameter of your StartJobRun API call. For more information, see Running Spark jobs with Amazon EMR on EKS.

To improve resilience, take the following actions:

  • Diversify Spot Instance types in your Karpenter NodePool or node group to reduce the risk of simultaneous reclamation.
  • Use pod templates with a node selector to place driver pods on On-Demand Instances. For example, use karpenter.sh/capacity-type: on-demand.
  • For structured streaming jobs, use Amazon CloudWatch or Prometheus monitoring to alert when the executor count drops to zero for more than 5 minutes. Also, use Spark structured streaming checkpointing to Amazon S3 for fault tolerance.

For more information, see Run fault-tolerant and cost-optimized Spark clusters using Amazon EMR on EKS and Amazon EC2 Spot Instances.

Resolve Karpenter node expiration

If the Karpenter expireAfter setting is too low, then the nodes terminate regardless of running pods. Then, the executor loses mid-job and "MetadataFetchFailedException" error messages. To check the expireAfter setting, run the following command:

kubectl get nodepools -o yaml | grep expireAfter

Set expireAfter to an appropriate value. For batch workloads, it's a best practice to set the value to 720h. For streaming workloads, set to Never to prevent mid-stream node disruptions.

Example expireAfter parameter for a NodePool:

apiVersion: karpenter.sh/v1
kind: NodePool
spec:
  template:
    expireAfter: 720h

For more information, see Disruption on the Karpenter website.

Resolve external automation that ends driver pods

If a custom health checker, heartbeat monitor, or orchestration tool ends the driver pod based on an inactivity timeout, then the job fails with the following error message:

"JobRun failed. Job Driver pod was killed, evicted or preempted."

Review external monitoring that sends SIGTERM or SIGKILL signals to pods, and increase heartbeat timeouts to accommodate long-running Spark stages. If you use Karpenter or Cluster Autoscaler, then add an annotation to the job-submitter pod to prevent autoscaler disruption.

For Karpenter, set the following configuration:

{
  "classification": "emr-job-submitter",
  "properties": {
    "jobsubmitter.annotation.karpenter.sh/do-not-disrupt": "true"
  }
}

For Cluster Autoscaler, set the following configuration:

{
  "classification": "emr-job-submitter",
  "properties": {
    "jobsubmitter.annotation.cluster-autoscaler.kubernetes.io/safe-to-evict": "false"
  }
}

Resolve streaming errors from Amazon Managed Streaming for Apache Kafka (Amazon MSK) or Apache Kafka

In streaming jobs, you might receive an "OffsetNotAvailableException" or a "TimeoutException" error message that references a recent leader election or records that are expiring. The error messages show that Amazon MSK or Apache Kafka have broker health problems, not an Amazon EMR on EKS issue. The driver is correctly reporting a Kafka failure. To resolve, investigate the Amazon MSK cluster independently.

Check if a job FAILED even though the Spark application completed successfully, with no failed stages in the Spark History Server. If you see this behavior, then contact AWS Support with your virtual cluster ID and job run ID.

Related information

Troubleshooting Amazon EMR on EKS

Using pod templates

Monitoring jobs

EMR on EKS Best Practices Guide

How do I troubleshoot Amazon EMR on EKS Spark job configuration and completion issues?

AWS OFFICIALUpdated a month ago