Spark/k8s How to run spark submit on Kubernetes with client mode
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
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:
- Kubernetes Cluster: A running k8s cluster. Minikube or a managed service like GKE, EKS, or AKS can be used.
- Spark Distribution: Spark version 2.3.0 or later, as Kubernetes support is integrated from these versions onward.
- Kubectl: The Kubernetes command-line tool configured to communicate with your cluster.
- 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.
Related reading
- Specify scheduling order of a Kubernetes DaemonSet
- Specify the order Dockers run on Kubernetes pod
- Spring Boot custom Kubernetes readiness probe
- Spring boot on Kubernetes does not get restarted on java.lang.OutOfMemoryError Java heap space
- Specifying superuser PostgreSQL password for a Docker Container
- Spring Boot containers can not connect to the Kafka container
- Split single DStream into multiple Hive tables
- stopping spark streaming after reading first batch of data

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.