Giter Site home page Giter Site logo

pyspark-k8s-example's Introduction

Pyspark on kubernetes

This repository serves as an example of how you could run a pyspark app on kubernetes.

Using the spark base docker images, you can install your python code in it and then use that image to run your code.

Requirements

  • docker
  • minikube (with at least 3 cpu and 4096mb ram, minikube start --cpus 3 --memory 4096)
  • pyspark-2.4.1 or regular spark installation (install via pip, brew... , needed for spark submit)
  • docker containers with spark 2.4.1 (prebuild at: sdehaes/spark:v2.4.1-hadoop-2.9.2, sdehaes/spark-py:v2.4.1-hadoop-2.9.2 )

To build the docker containers yourself you need to checkout spark at the release tag v2.4.1, the you need to use the following command to build it:

./build/mvn -Pkubernetes -DskipTests clean package -Phadoop-2.7 -Dhadoop.version=2.9.2
bin/docker-image-tool.sh -r <docker repo> -t v2.4.1 build
bin/docker-image-tool.sh -r <docker repo> -t v2.4.1 push

How to run

The launch.sh script combines all necessary steps.

Add rbac roles for spark on kubernetes:

kubectl create serviceaccount spark
kubectl create clusterrolebinding spark-role --clusterrole=edit --serviceaccount=default:spark --namespace=default

Build the docker image:

eval $(minikube docker-env)
docker build . -t pyspark-k8s-example:2.4.1

In the docker image --no-cache-dir is used as an option for pip install. This disables caching making your docker image smaller.

The first command makes certain the docker image is build in the minikube environment.

Launch the spark submit:

spark-submit \
    --master k8s://https://$(minikube ip):8443 \
    --deploy-mode cluster \
    --name spark-example \
    --conf spark.executor.instances=1 \
    --conf spark.kubernetes.container.image=pyspark-k8s-example:2.4.1 \
    --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
    --conf spark.kubernetes.pyspark.pythonVersion=3 \
    /usr/bin/run.py

If you get an error Could not find valid SPARK_HOME while searching ... then you should set spark home to the directory where pip installed pyspark. For mac with a homebrew version of python this is:

export SPARK_HOME=/usr/local/lib/python3.7/site-packages/pyspark

On ubuntu this will be:

export SPARK_HOME=//usr/local/lib/python3.7/dist-packages/pyspark

pyspark-k8s-example's People

Contributors

stijndehaes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.