spark

by Helm

Helm chartv1.0.4App 2.4.4

Fast and general-purpose cluster computing system.

About this chart

Apache Spark Helm Chart

Apache Spark is a fast and general-purpose cluster computing system including Apache Zeppelin.

  • http://spark.apache.org/
  • https://zeppelin.apache.org/

Inspired from Helm Classic chart https://github.com/helm/charts

Chart Details

This chart will do the following:

  • 1 x Spark Master with port 8080 exposed on an external LoadBalancer
  • 3 x Spark Workers with HorizontalPodAutoscaler to scale to max 10 pods when CPU hits 50% of 100m. A LoadBalancer on these worker machines exposes ports 8080, 8888, 8889 and 4040 for purposes such as monitoring or serving spark-serving endpoints.
  • 1 x Zeppelin pod (Optional) with port 8080 exposed on an external LoadBalancer
  • 1 x Livy pod (Optional) with port 8998 exposed on an external LoadBalancer
  • All using Kubernetes Deployments

Prerequisites

  • Assumes that serviceAccount tokens are available under hostname metadata. (Works on GKE by default) URL -- http://metadata/computeMetadata/v1/instance/service-accounts/default/token

Installing the Chart

To install the chart with the release name my-release:

$ helm install --name my-release stable/spark

Configuration

The following table lists the configurable parameters of the Spark chart and their default values.

Spark Master

ParameterDescriptionDefault
Master.NameSpark master namespark-master
Master.ImageContainer image namemcr.microsoft.com/mmlspark/spark2.4
Master.ImageTagContainer image tagv4
Master.Replicask8s deployment replicas1
Master.Componentk8s selector keyspark-master
Master.Cpucontainer requested cpu100m
Master.Memorycontainer requested memory1024Mi
Master.ServicePortk8s service port7077
Master.ContainerPortContainer listening port7077
Master.DaemonMemoryMaster JVM Xms and Xmx option1g
Master.ServiceType Kubernetes Service typeLoadBalancer

Spark WebUi

ParameterDescriptionDefault
WebUi.NameSpark webui namespark-webui
WebUi.ServicePortk8s service port8080
WebUi.ContainerPortContainer listening port8080

Spark Worker

ParameterDescriptionDefault
Worker.NameSpark worker namespark-worker
Worker.ImageContainer image namemcr.microsoft.com/mmlspark/spark2.4
Worker.ImageTagContainer image tagv4
Worker.Replicask8s hpa and deployment replicas3
Worker.ReplicasMaxk8s hpa max replicas10
Worker.Componentk8s selector keyspark-worker
Worker.Cpucontainer requested cpu100m
Worker.Memorycontainer requested memory2048Mi
Worker.ContainerPortContainer listening port7077
Worker.CpuTargetPercentagek8s hpa cpu targetPercentage50
Worker.DaemonMemoryWorker JVM Xms and Xmx setting1g
Worker.ExecutorMemoryWorker memory available for executor1g
Worker.AutoscalingEnable horizontal pod autoscalingfalse

Zeppelin

ParameterDescriptionDefault
Zeppelin.NameZeppelin namezeppelin-controller
Zeppelin.Enabledif true enable Zeppelintrue
Zeppelin.ImageContainer image namemcr.microsoft.com/mmlspark/zeppelin
Zeppelin.ImageTagContainer image tagv4
Zeppelin.Replicask8s deployment replicas1
Zeppelin.Componentk8s selector keyzeppelin
Zeppelin.Cpucontainer requested cpu100m
Zeppelin.ServicePortk8s service port8080
Zeppelin.ContainerPortContainer listening port8080
Zeppelin.Ingress.Enabledif true, an ingress is createdfalse
Zeppelin.Ingress.Annotationsannotations for the ingress{}
Zeppelin.Ingress.Paththe ingress path/
Zeppelin.Ingress.Hostsa list of ingress hosts[zeppelin.example.com]
Zeppelin.Ingress.Tlsa list of IngressTLS items[]
Zeppelin.ServiceType Kubernetes Service typeLoadBalancer

Livy

ParameterDescriptionDefault
Livy.NameLivy namelivy-controller
Livy.Enabledif true enable Zeppelintrue
Livy.ImageContainer image namemcr.microsoft.com/mmlspark/livy
Livy.ImageTagContainer image tagv4
Livy.Replicask8s deployment replicas1
Livy.ReplicasMaxk8s max number of replicas3
Liyy.Componentk8s selector keylivy
Livy.Cpucontainer requested cpu100m
Livy.ServicePortk8s service port8998
Livy.ServiceType Kubernetes Service typeLoadBalancer

Specify each parameter using the --set key=value[,key=value] argument to helm install.

Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,

$ helm install --name my-release -f values.yaml stable/spark

Tip: You can use the default values.yaml

Running Spark Jobs

There are two ways to sumbit jobs to the spark cluster.

  1. Using sparks inbuilt support for K8s clusters. This is mostly suited for jobs that don't require any user interaction or monitoring. See https://spark.apache.org/docs/latest/running-on-kubernetes.html#submitting-applications-to-kubernetes. To sumbit a job, typically you would run kubectl proxy to setup a proxy to the cluster at localhost:8001 usually. The you would run call spark-submit. For example, to run the SparkPi sample app https://spark.apache.org/examples.html, you would run bin/spark-submit \ --master k8s://https://localhost:8001 \ --deploy-mode cluster \ --name spark-pi \ --class org.apache.spark.examples.SparkPi \ --conf spark.executor.instances=5 \ --conf spark.kubernetes.container.image=mhamilton723/spark-2.4.0 \ local:///opt/spark/examples/jars/spark-examples_2.11-2.4.0.jar This will create a pod based on the supplied container image and use that as the executor for your job. You can access this pod from the K8s dashboard. A downside to this method is that it requires creating a new pod for jobs and it is less transparent about how its jobs are executing. It is possible to sumbit jobs in client mode but that would require openning ports on the driver machine.

  2. Using the zeppelin pod. The zeppelin pod exists in the cluster and already has its ports readily visible to the master and works pods and as such can run apps in both client and cluster mode. In addition, the pod contains a running instance of the zepplin notebook on port 8080 that can be used to run spark scripts in either scala, python, or as bash scripts. To access the notebook look for the spark-zeppelin service under service on your dashboard. (if you run kubectl proxy you dashboard would be here http://localhost:8001/api/v1/namespaces/kube-system/services/kubernetes-dashboard:/proxy/#!/overview?namespace=default). Click the externel endpoint link.

Because the zeppelin pod is a full debian jessie container with spark 2.4.0 in the /opt/spark folder, you can also call spark-submit via the terminal with the kubectl exec command. For example, to run SparkPi you would first look for the name of your zeppelin pod under pods in the dashboard. This is will be something like spark-zeppelin-76b6998f78-zm8c8. Then run kubectl exec spark-zeppelin-76b6998f78-zm8c8 /opt/spark/bin/run-example SparkPi

  1. Using Livy. See https://livy.incubator.apache.org/docs/latest/. The livy rest endpoint is exposed by the livy loadbalancer service. By default, livy uses the spark-master pod as the master and livy jobs can be monitored from either the spark-webui loadbalancer service on port 8080 or the livy ui endpoint.

Upgrading

To upgrade to this chart from 0.2.2 you will have to update the docker images to point the images in values.yaml. The dockerfiles for these images are here https://github.com/Azure/mmlspark/tree/master/tools/helm/docker_images. To enable livy, you will need to create a livy deployment with a load balancer and optional pod scaler as described in spark-livy-deployment.yaml and spark-livy-hpa.yaml. Ensure that your livy pods have the right SPARK_MASTER environment variables.

Deploy spark with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has spark on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartspark is pinned at v1.0.4 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply