Kubernetes を使って Spark クラスタを立ち上げる
環境
- Mac: OS X Yosemite Version 10.10.5
- Vagrant: 1.7.4 => Download Vagrant - Vagrant
- Virtual Box: 4.3.28 => Download_Old_Builds_4_3 – Oracle VM VirtualBox
- Kubernetes: 1.0.1 (1.0.3 ではバグ発生)
インストール
Kubernetes のインストール (NG)
適当なプロジェクト用ディレクトリに移動し、以下のコマンドを実行。
$ export KUBERNETES_PROVIDER=vagrant $ curl -sS https://get.k8s.io | bash |
早速コケた。
Downloading kubernetes release v1.0.3 to /proj/mogproject/example-spark/kubernetes.tar.gz --2015-08-23 10:39:46-- https://storage.googleapis.com/kubernetes-release/release/v1.0.3/kubernetes.tar.gz Resolving storage.googleapis.com... 216.58.220.176 Connecting to storage.googleapis.com|216.58.220.176|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 121767360 (116M) [application/x-tar] Saving to: ‘kubernetes.tar.gz’ 100%[===============================================================================>] 121,767,360 1.76MB/s in 65s 2015-08-23 10:40:51 (1.80 MB/s) - ‘kubernetes.tar.gz’ saved [121767360/121767360] Unpacking kubernetes release v1.0.3 Creating a kubernetes on vagrant... Starting cluster using provider: vagrant ... calling verify-prereqs ... calling kube-up Using credentials: vagrant:vagrant Bringing machine 'master' up with 'virtualbox' provider... Bringing machine 'minion-1' up with 'virtualbox' provider... ==> master: Box 'kube-fedora21' could not be found. Attempting to find and install... master: Box Provider: virtualbox master: Box Version: >= 0 Request for box's Amazon S3 region was denied. This usually indicates that your user account with access key ID is misconfigured. Ensure your IAM policy allows the "s3:GetBucketLocation" action for your bucket: arn:aws:s3:::opscode-vm-bento |
どうやら vagrant up コマンドに失敗している模様。
認証周りを管理しているプラグイン vagrant-s3auth をアンインストールしたら、先に進んだ。
$ vagrant plugin uninstall vagrant-s3auth |
しかし、今度はこの画面から一向に進まない。
Waiting for each minion to be registered with cloud provider .................................................................. |
1時間待っても、2時間待っても状況変わらず。
どうやら、こちらの certificate 関連の厄介な問題に直面したようだ。
解決策は、1個前のバージョンである v1.0.1 にこちらのパッチを適用し、手動でインストールせよ、とのこと。
- Automated cherry pick of #11390 upstream release 1.0 by jbeda · Pull Request #12237 · kubernetes/kubernetes
- docker - Kubernetes with Vagrant nodes won't register - Stack Overflow
Kubernetes のインストール (リトライ)
まずは VM を初期化。
$ cd kubernetes $ vagrant destroy -f $ vagrant box remove kube-fedora21 $ cd .. $ rm -rf ./kubernetes |
Version 1.0.1 を手動でダウンロードしてから、パッチを適用。その後、インストール。
$ tar zxvf ./kubernetes.tar.gz $ cd kubernetes/cluster/vagrant $ cd ../.. $ export KUBERNETES_PROVIDER=vagrant $ ./cluster/kube-up.sh |
10分ほどで正常終了。ここまで長かった。
Cluster validation succeeded Done, listing cluster services: Kubernetes master is running at https://10.245.1.2 KubeDNS is running at https://10.245.1.2/api/v1/proxy/namespaces/kube-system/services/kube-dns KubeUI is running at https://10.245.1.2/api/v1/proxy/namespaces/kube-system/services/kube-ui |
API との疎通確認
$ ./cluster/kubectl.sh get pods NAME READY STATUS RESTARTS AGE |
Spark クラスタの起動
Spark マスターサービスの起動
$ ./cluster/kubectl.sh create -f ./examples/spark/spark-master.json $ ./cluster/kubectl.sh create -f ./examples/spark/spark-master-service.json |
暫く経つと Running になる。
$ ./cluster/kubectl.sh get pods NAME READY STATUS RESTARTS AGE spark-master 0/1 Pending 0 1m $ ./cluster/kubectl.sh get pods NAME READY STATUS RESTARTS AGE spark-master 1/1 Running 0 15m $ ./cluster/kubectl.sh logs spark-master |
Spark ワーカーの起動
$ ./cluster/kubectl.sh create -f examples/spark/spark-worker-controller.json |
15分経っても、3個中2個は Pending のままだった。
$ ./cluster/kubectl.sh get pods NAME READY STATUS RESTARTS AGE spark-master 1/1 Running 0 34m spark-worker-controller-6cgpd 0/1 Pending 0 15m spark-worker-controller-tqa4b 0/1 Pending 0 15m spark-worker-controller-yl7n2 1/1 Running 0 15m $ ./cluster/kubectl.sh get services NAME LABELS SELECTOR IP(S) PORT(S) kubernetes component=apiserver,provider=kubernetes 10.247.0.1 443/TCP spark-master name=spark-master name=spark-master 10.247.70.164 7077/TCP $ ./cluster/kubectl.sh get nodes NAME LABELS STATUS 10.245.1.3 kubernetes.io/hostname=10.245.1.3 Ready |
Spark を使う
spark-master の IPアドレスとポートを確認。
$ ./cluster/kubectl.sh get service spark-master NAME LABELS SELECTOR IP(S) PORT(S) spark-master name=spark-master name=spark-master 10.247.70.164 7077/TCP |
Kubernetes の minion-1 にログインし、適当な Docker コンテナを起動。
その中で、環境変数や /etc/hosts ファイルを書き換えるユーティリティ用スクリプト setup_client.sh を(同一シェル内で)実行。
[vagrant@kubernetes-minion-1 ~]$ sudo docker run -it gcr.io/google_containers/spark-base root@49cc6b98cb5f:/# . /setup_client.sh 10.247.70.164 7077 |
Kubernetes 上の Spark クラスタへアクセスしていることを確認できた。
root @ 49 cc 6 b 98 cb 5 f : / # spark-shell 15 / 08 / 23 11 : 04 : 18 WARN NativeCodeLoader : Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __ / __ ___ _____ / / __ _ \ \/ _ \/ _ `/ __ / ' _ / / ___ / . __ /\ _ , _ / _ / / _ /\ _ \ version 1.4 . 0 / _ / Using Scala version 2.10 . 4 (OpenJDK 64 -Bit Server VM, Java 1.7 . 0 _ 79 ) Type in expressions to have them evaluated. Type : help for more information. Spark context available as sc. 15 / 08 / 23 11 : 04 : 31 WARN Connection : BoneCP specified but not present in CLASSPATH (or one of dependencies) 15 / 08 / 23 11 : 04 : 33 WARN Connection : BoneCP specified but not present in CLASSPATH (or one of dependencies) 15 / 08 / 23 11 : 04 : 43 WARN ObjectStore : Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 0.13 . 1 aa SQL context available as sqlContext. scala> sc.isLocal res 0 : Boolean = false scala> sc.master res 1 : String = spark : //spark-master:7077 |
Python の API で、Spark ワーカーのホスト名を取得してみる。
root@ 49cc6b98cb5f : / # pyspark Python 2.7 . 9 (default, Mar 1 2015 , 12 : 57 : 24 ) [GCC 4.9 . 2 ] on linux2 Type "help" , "copyright" , "credits" or "license" for more information. 15 / 08 / 23 11 : 12 : 06 WARN NativeCodeLoader: Unable to load native - hadoop library for your platform... using builtin - java classes where applicable Welcome to ____ __ / __ / __ ___ _____ / / __ _\ \ / _ \ / _ ` / __ / '_ / / __ / .__ / \_,_ / _ / / _ / \_\ version 1.4 . 0 / _ / Using Python version 2.7 . 9 (default, Mar 1 2015 12 : 57 : 24 ) SparkContext available as sc, HiveContext available as sqlContext. >>> import socket >>> sc.parallelize( range ( 1000 )). map ( lambda x:socket.gethostname()).distinct().collect() [ 'spark-worker-controller-yl7n2' ] |
0 件のコメント:
コメントを投稿