Running Spark on Alluxio in Kubernetes

Slack Docker Pulls GitHub edit source

Alluxio can be run on Kubernetes. This guide demonstrates how to run a Spark job on Alluxio running in a Kubernetes environment.

Overview

Spark running on Kubernetes can use Alluxio as the data access layer. This guide walks through an example Spark job on Alluxio in Kubernetes. The example used in this tutorial is a job to count the number of lines in a file. We refer to this job as count in the following text.

Prerequisites

  • A Kubernetes cluster (version >= 1.8).
  • Alluxio is deployed on the Kubernetes cluster. For instructions on how to deploy Alluxio, refer to this page

Basic Setup

First, we’ll prepare a Spark Docker image including the Alluxio client and any other required jars. This image should be made available on all Kubernetes nodes.

Download Binaries

Download the desired Spark version. We use the pre-built binary for the spark-submit command as well as building the Docker image using Dockerfile included with Alluxio.

  1. $ tar -xf spark-2.4.0-bin-hadoop2.7.tgz
  2. $ cd spark-2.4.0-bin-hadoop2.7

If running the count example, download the Alluxio examples jar.

  1. $ wget https://alluxio-documentation.s3.amazonaws.com/examples/spark/alluxio-examples_2.12-1.0.jar
  2. $ cp <path_to_alluxio_examples>/alluxio-examples_2.12-1.0.jar jars/

Note: Any jar copied to the jars directory is included in the Spark Docker image when built.

Build the Spark Docker Image

Extract the Alluxio client jar from the Alluxio Docker image:

  1. $ id=$(docker create alluxio/alluxio:2.1.2)
  2. $ docker cp $id:/opt/alluxio/client/alluxio-2.1.2-client.jar \
  3. - > alluxio-2.1.2-client.jar
  4. $ docker rm -v $id 1>/dev/null

Add the required Alluxio client jar and build a Docker image used for the Spark driver and executor pods. Run the following from the Spark distribution directory to add the Alluxio client jar.

  1. $ cp <path_to_alluxio_client>/alluxio-2.1.2-client.jar jars/

Build the Spark Docker image

  1. $ docker build -t spark-alluxio -f kubernetes/dockerfiles/spark/Dockerfile .

Example(s)

This section shows how to use the built Docker image to launch a Spark job with Alluxio as the data source.

Short-circuit operations

Short-circuit access enables an Alluxio client in a Spark executor to access the Alluxio worker storage on the host machine directly. This improves performance by not communicating with the Alluxio worker using the networking stack.

If domain sockets were not setup when deploying Alluxio as per instructions on this page, you can skip mounting the hostPath volumes to the Spark executors.

If a domain socket location was setup on hosts running the Alluxio worker process at location /tmp/alluxio-domain with the Alluxio configuration as alluxio.worker.data.server.domain.socket.address=/opt/domain, use the following Spark configuration to mount /tmp/alluxio-domain to /opt/domain in the Spark executor pod. The spark-submit command in the following section includes these properties.

  1. spark.kubernetes.executor.volumes.hostPath.alluxio-domain.mount.path=/opt/domain
  2. spark.kubernetes.executor.volumes.hostPath.alluxio-domain.mount.readOnly=true
  3. spark.kubernetes.executor.volumes.hostPath.alluxio-domain.options.path=/tmp/alluxio-domain
  4. spark.kubernetes.executor.volumes.hostPath.alluxio-domain.options.type=Directory

Note:

  • Volume support in Spark was added in version 2.4.0.
  • You may observe a performance hit when not using short-circuit access via a domain socket.

Run a Spark job

The following command runs an example job to count the number of lines in the Alluxio location /LICENSE. The output and time taken can be seen in the logs for Spark driver pod. Refer to Spark documentation for further instructions.

Create the service account (if required)

  1. $ kubectl create serviceaccount spark
  2. $ kubectl create clusterrolebinding spark-role --clusterrole=edit \
  3. --serviceaccount=default:spark --namespace=default

Run the job from the Spark distribution directory

  1. $ ./bin/spark-submit --master k8s://https://<master>:8443 \
  2. --deploy-mode cluster --name spark-alluxio --conf spark.executor.instances=1 \
  3. --class alluxio.examples.Count --driver-memory 500m --executor-memory 1g \
  4. --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
  5. --conf spark.kubernetes.container.image=spark-alluxio \
  6. --conf spark.kubernetes.executor.volumes.hostPath.alluxio-domain.mount.path=/opt/domain \
  7. --conf spark.kubernetes.executor.volumes.hostPath.alluxio-domain.mount.readOnly=true \
  8. --conf spark.kubernetes.executor.volumes.hostPath.alluxio-domain.options.path=/tmp/alluxio-domain \
  9. --conf spark.kubernetes.executor.volumes.hostPath.alluxio-domain.options.type=Directory \
  10. local:///opt/spark/jars/alluxio-examples_2.12-1.0.jar \
  11. alluxio://alluxio-master.default.svc.cluster.local:19998/LICENSE

Troubleshooting

Accessing Alluxio Client Logs

The Alluxio client logs can be found in the Spark driver and executor logs. Refer to Spark documentation for further instructions.