Running Apache Spark applications on Kubernetes has a lot ofbenefits, but operating and managing Kubernetes at scale hassignificant challengesfor data teams. With the recent addition of Ocean for Apache Spark to Spot's suite of Kubernetes solutions, data teams have the power and flexibility of Kubernetes without the complexities. A cloud-native managed service, Ocean Spark automates cloud infrastructure and application management for Spark-on-Kubernetes.

Designed to be developer-friendly, Ocean Spark comes with built-in integrations with popular data tools, including scheduling solutions like Airflow and Jupyter notebooks. There are multiple ways to run a Spark application onOcean for Apache Spark:

  • You can connect Jupyter Notebooks to work with Spark interactively
  • You can submit Spark applications using schedulers like Airflow, Azure Data Factory, Kubeflow, Argo, Prefect, or just a simple CRON job.
  • You can also directly call the Ocean SparkREST APIto submit Spark applications from anywhere, thereby enabling custom integrations with your infrastructure, CI/CD tools, and more.

In this tutorial, we're going to show you how to connect the orchestration service most popular among enterprise customers, Apache Airflow, and illustrate how you can schedule and monitor your workflows and pipelines on Ocean for Apache Spark.

We're going to use the AWS service Managed Workflows for Apache Airflow (MWAA) as our main example, because it is easy to set up and handles the management of the underlying infrastructure for scalability, availability and security. But these instructions are easy to adapt to alternative ways of running Airflow.

(Optional) Set up Amazon Managed Workflows for Apache Airflow (MWAA)

An Amazon S3 bucket is used to store Apache Airflow Directed Acyclic Graphs (DAGs), custom plugins in a plugins.zipfile, and Python dependencies in a requirements.txtfile. Please make sure that the S3 bucket is configured to Block all public access, with Bucket Versioningenabled and located in the same AWS Region as the Amazon MWAA environment.

The following image shows how to setup the locations on S3 to store different artifacts.

[Link]

Please follow the instructions here to sync the files between your git repository and S3

Install and Configure the Ocean Spark Airflow Provider

In MWAA, you can provide a requirements.txt file listing all the python packages you want to install. You should include the ocean-spark-airflow-providerpackage, which is available here.On other distributions of Airflow, you can simply install this package by running pip install ocean-spark-airflow-provider.

This open-source package (seegithub repository) provides an OceanSparkOperator that we will show you later, and a connection to configure how to talk to Ocean Spark.

Please enter the connection details as shown below. You may access it from Admin -> Connections -> Add a new record (+ sign) and select Ocean For Apache Spark from Connection Type dropdown.

[Link]

Enter the following details in the connection window, and then click Save.

  • Connection Id: Use ocean_spark_default by default. You may use a different name.
  • Connection Type: Select "Ocean For Apache Spark" from the dropdown
  • Description: Enter any optional text to describe the connection.
  • Cluster Id: The ID of your Ocean Spark cluster
  • Account Id: The Spot Account ID the cluster belongs to, which corresponds to a cloud provider account.
  • API token: Your Spot by NetApp API token (seeHow to create an API token)

Using the Ocean Spark Operator in your Airflow DAGs

In Airflow, a DAG - or a Directed Acyclic Graph - is a collection of the tasks that you want to run, organized in a way that reflects their relationships and dependencies as a graph. Airflow will only start running a task, once all its upstream tasks are finished.

When you define an Airflow task using the Ocean Spark Operator, the task consists of running a Spark application on Ocean Spark. For example, you can run multiple independent Spark pipelines in parallel, and only run a final Spark (or non-Spark) application once the parallel pipelines have completed.

[Link]

The final Spark job in this DAG will be executed once the two parallel jobs are finished.

A DAG is defined in a Python script, which represents the DAGs structure (tasks and their dependencies) as code. When using MWAA, you should upload the DAG python script into the S3 DAGs folder. Here's an example DAG consisting of a single Spark job.


[Link]

Once the file is uploaded into the S3 DAGs folder, the DAG will appear in the MWAA environment within a few minutes

[Link]

Click on Run to run the DAG. The Spark application will start running in your Spot environment in a couple of minutes (Note: you can reduce this startup time by configuringheadroom).

[Link]

Once the application is completed, you should see the DAG completed successfully in the MWAA environment.

[Link]

Note: If you want to give a different name to the connection other than the default name (ocean_spark_default), please use the conn_id parameter of OceanSparkOperator.

[Link]

Start using Ocean for Apache Spark

Airflow is just one of several built-in integrations that Ocean for Apache Spark supports to help data teams run their Spark applications with Kubernetes. Learn how you can easily set up, configure and scale Spark applications and Kubernetes clusters with Ocean Spark.Schedule an initial meetingwith our team of Apache Spark Solutions Architects, so we can discuss your use case and help you with a successful onboarding of our platform.

Attachments

  • Original Link
  • Original Document
  • Permalink

Disclaimer

NetApp Inc. published this content on 23 February 2022 and is solely responsible for the information contained therein. Distributed by Public, unedited and unaltered, on 24 February 2022 05:21:03 UTC.