Problem:

The client faced Spark issues during job submissions through Airflow. Out of 15 max DAGs that got triggered, there were always 3-4 dags getting triggered in the Initial state and never moving to the running state. A few DAGs also got stuck in the ContainerCreate state and never came up and ran.

Process:

Step 1 – Initial investigation and troubleshootingThe expert team initiated the preliminary investigation and promptly requested information from the client. Below is the list of information provided by the client for further issue investigation:

1. Job Submission Statistics:

  • Number of jobs submitted: Not more than 50.
  • Average job duration: Typically around 4 hours.
  • Concurrent jobs: Up to 15 jobs, as mentioned.

2. Kubernetes Resource Usage:

  • Spark application configuration

– Driver:

  • Cores: 2
  • Core Limit: 2000m
  • Memory: 8096m

– Executor:

  • Cores: 1
  • Instances: 1
  • Memory: 8096m
  • Core Limit: 2000m

3. Error and Failure Details:

Client-side (Airflow) and Kubernetes-side issues:

Common Errors:

  • Webhook connection issues – “no route to host” and “context deadline exceeded.”

Job Failures:

  • Failure in driver node setup due to webhook request.
  • Resource mount failures.

4. Logs and Configuration:

Complete logs for one successful and one failed job.

– Configuration Files:

  • Airflow and Kubernetes conf/iguration (YAML, Airflow variables).

– Job Submission Code:

  • Available in the logs.

– Component Versions:

  • Spark Operator: Upgraded from 1.1.19 to 1.1.25.

– Kubernetes:

  • Client Version: 1.22.0
  • Server Version: 1.21.12

5. Cluster Access and Issues:

  • No direct access to the cluster.
  • Specific logs needed for further diagnosis.

6. Diagnosed Problems:

  • Webhook request failures.
  • Routing issues potentially related to the Calico component in Kubernetes.
  • Resource mounting failures.

7. Ongoing Diagnosis:

  • Checking potential issues with Spark Operator Kubernetes.
  • Requesting specific logs for further investigation.

Step 2 – Further investigationAfter the investigation, the experts found that Airflow reads the config from 3 places in the below order:

  1. Configs defined in DAG Python code.
  2. Read the config defined in Airflow environment variables.
  3. Lastly, it reads the config from the Airflow config file/Config name.

The experts concluded that the standard practice was to define everything in the config file/config map at the persistence location and copied in Airflow containers. Exceptional scenarios could be handled in dag Python code. Experts suggested defining everything in a single configMap and handling it during the Airflow deployment pipeline.

Step 3 – Helm chart and executor configurationThe following points were addressed:

  • Configuring Airflow Executor: Instead of changing Airflow’s config map manually, the executor was configured as a Kubernetes executor in the Helm chart as part of the installation.
  • Helm Chart Bug: A bug was identified in Airflow’s Helm chart where the executor value is hardcoded; it was reported to the Airflow project so it can be fixed in future releases.
  • Local executor and Kubernetes executor: Kubernetes executors are managed in the Helm chart, with the related variables exposed in the values.yaml file.
  • Defining environment variables: Environment variables are defined in the values.yaml file; potential conflicts with dynamically generated sections were reviewed.
  • Updating Helm chart: The Helm chart should reference the executor variable from the values.yaml file instead of hardcoding it.

Step 4 – Identified ProblemsThe expert team found the following issues:

1. Global airflow configWhen Job has failed, SparkSession was never invoked. Java job is reading the config file from the local file which we mounted as part of our YML. In many cases, Job started before PVC mounted/failed.

2. Spark history server PVCThe Spark history server PVC didn’t mount on driver pods, which caused “Init:0/1” status. This PVC was an RWX volume based on a cloud file-share CSI driver.

3. Airflow issue with DAGs not visible in UINot all DAGRuns were shown correctly in Airflow UI, and some random jobs used incorrect pod names.

Solution:

Issue 1 – The PVC mount timing problem matches a known Spark Operator issue (an open issue and an earlier closed one):

(Open Issue) https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/issues/1619.

(Previously Closed) https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/issues/784.

Issue 2 – Experts suggested reviewing all pods in the cluster across all namespaces and manually terminating those in the “Init:0/1” status (as well as in other statuses that could lock this PVC).

As an alternative, they recommended considering the removal of the spark-history-server feature (and its associated PVC). They asked the user to decide if it was really necessary:
https://github.com/mesosphere/kudo-spark-operator/blob/master/kudo-spark-operator/docs/latest/history-server.md.
Removing this optional PVC would have significantly improved the cluster’s performance, especially given the large workloads.

Issue 3 – The expert team discussed the received data and made the below change as WA in the helm chart to adopt the suggested fix through the pipeline:

Hard-coded value

        - name: AIRFLOW__CORE__EXECUTOR
          value: LocalExecutor

changed to

        - name: AIRFLOW__CORE__EXECUTOR
          value: {{ .Values.executor }}

In file “airflow-1.6.0\airflow\files\pod-template-file.kubernetes-helm-yaml” inside airflow helm-chart.

The team identified that the Airflow job didn’t show up on the UI, but it is visible in Task Details. Experts created two issues on GitHub to bring it to the maintainers’ attention:

  • Airflow Discussions: #32493 (https://github.com/apache/airflow/discussions/32493).
  • Airflow Issues: #32485 (https://github.com/apache/airflow/issues/32485).

Conclusion:

The client experienced Spark issues during job submissions through Airflow, with several DAGs stuck in the Initial or ContainerCreate states. Initial investigation revealed limited job submissions and common errors like webhook connection issues and resource mount failures. The expert team recommended standardizing configuration management through a single ConfigMap and made changes to the Airflow Helm chart to replace hardcoded executor values with variables. GitHub issues were also opened to address the visibility and configuration problems.