LoginSignup
1

More than 3 years have passed since last update.

Docker for Macを使ったローカルのKubernetesクラスタ上でSparkジョブを実行する

Last updated at Posted at 2019-08-11

Docker for Macをインストールする

以下を参照ください。
https://docs.docker.com/docker-for-mac/install/

Kubernetesクラスタを有効にする

Preferences -> Kubernetes -> Enable Kubernetesをクリックします。
Screen Shot 2019-08-11 at 4.52.56 PM.png

SparkのDockerイメージを作成する

以下の記事を参照ください。
https://qiita.com/yohei1126@github/items/efcc906b8609d78274ff

Sparkジョブを実行する

サンプルとして提供されている spark-examples_2.11-2.4.3.jar を実行します。これはπを計算するプログラムです。
まずクラスタのURLを確認します。

 $ kubectl cluster-info
Kubernetes master is running at https://localhost:6443
KubeDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

サービスアカウントの作成

  • 今回は、次の記事を参考にπを計算するSparkジョブを実行します。 https://qiita.com/ysakashita/items/1f87646ae804ba509d07
  • 引用した記事の通り、ジョブの認証・認可はKubernetesのサービスアカウントで行うため、ジョブで使うサービスアカウントを作成しておきます。
$ kubectl create serviceaccount spark
$ kubectl create clusterrolebinding spark-role --clusterrole=edit --serviceaccount=default:spark --namespace=default

ジョブの実行にはSpark-submitコマンドが必要なため、リポジトリから取得して以下のコマンドを実行します。

$ wget https://www-us.apache.org/dist/spark/spark-2.4.3/spark-2.4.3-bin-hadoop2.7.tgz
$ tar zxvf spark-2.4.3-bin-hadoop2.7.tgz
$ cd spark-2.4.3-bin-hadoop2.7
$ bin/spark-submit \
  --master k8s://https://localhost:6443 \
  --deploy-mode cluster \
  --conf spark.executor.instances=3 \
  --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
  --conf spark.kubernetes.container.image=yohei1126/spark:v2.4.3 \
  --class org.apache.spark.examples.SparkPi \
  --name spark-pi \
  local:///opt/spark/examples/jars/spark-examples_2.11-2.4.3.jar

Sparkジョブの結果を確認する

  • Sparkジョブはpodのなかで実行されるため、podの一覧を取得します。
  • kubectl logs でpodの中のログを確認すると、πが計算されています。
$ kubectl get pods
NAME                                               READY     STATUS      RESTARTS   AGE
spark-pi-2e689dc329e934f38c1017d59635da59-driver   0/1       Completed   0          46m
$ kubectl logs spark-pi-2e689dc329e934f38c1017d59635da59-driver
...
Pi is roughly 3.1442157210786053
...

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1