Spark
Kubernetes
Spark Submit
Client Mode
Container Orchestration

Spark/k8s How to run spark submit on Kubernetes with client mode

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Spark on Kubernetes: Client Mode Configuration and Execution

Apache Spark is a powerful open-source analytics engine for big data processing, and Kubernetes (k8s) is a robust platform for managing containerized applications. Running Spark on Kubernetes in client mode can offer flexibility and resource management capabilities. This article will delve into how to run Spark submit on Kubernetes using client mode, with an emphasis on technical details, examples, and practical insights.

Understanding Spark's Deployment Modes

Before diving into Spark submit on Kubernetes, it's essential to understand Spark's deployment modes:

  • Client Mode: In this mode, the driver program runs on the local machine that submits the application. The Executors run on the cluster, making it ideal for interactive applications.
  • Cluster Mode: Here, the driver runs inside the Kubernetes cluster. This mode is more suited for executing batch applications due to its resilience to local client failures.

Prerequisites

To run Spark on Kubernetes, you should have the following:

  1. Kubernetes Cluster: A running k8s cluster. Minikube or a managed service like GKE, EKS, or AKS can be used.
  2. Spark Distribution: Spark version 2.3.0 or later, as Kubernetes support is integrated from these versions onward.
  3. Kubectl: The Kubernetes command-line tool configured to communicate with your cluster.
  4. Docker: To build Docker images if required.

Steps to Run Spark Submit in Client Mode on Kubernetes

Step 1: Build a Docker Image

Create a Docker image containing Spark binaries. If you have specific dependencies or custom configurations, include them in the image.

  • kind: ServiceAccount
  • `--master k8s://`: Specifies the Kubernetes cluster's API server.
  • `--deploy-mode client`: Launches the driver on the local machine.
  • `--conf spark.executor.instances`: Sets the number of executors.
  • `--conf spark.kubernetes.container.image`: The Docker image to use for Spark components.
  • `local:///xyz.jar`: Path to your application's jar file.
  • Security: Network policies, service accounts, and secure API server configurations are crucial for securing your applications.
  • Resource Management: Proper resource limits and requests in Kubernetes ensure balanced load and efficient utilization of your cluster.
  • Logging and Monitoring: Capture logs from the driver and executors. Tools like ELK stack, Prometheus, and Grafana can integrate with Kubernetes for detailed monitoring.

Course illustration
Course illustration

All Rights Reserved.