Introduction to Magnum (JP)

47
Introduction to Magnum NEC Solution Innovators, OpenStack Community Team

Transcript of Introduction to Magnum (JP)

Page 1: Introduction to Magnum (JP)

Introduction to MagnumNEC Solution Innovators, OpenStack Community Team

Page 2: Introduction to Magnum (JP)
Page 3: Introduction to Magnum (JP)

目次

• 私は誰?

• Magnum とは?

• Magnum の使い方

• アーキテクチャ

• 開発環境

• デモ

Page 4: Introduction to Magnum (JP)

私は誰?

Page 5: Introduction to Magnum (JP)

5 © NEC Corporation 2015

私は誰?

▌Motohiro/Yuanying OtsukaTwitter @yuanyinghttp://www.fraction.jp

▌NEC ソリューションイノベータOpenStack コミュニティ対応チーム

▌OpenStack コミュニティMagnum コア開発者 (2014/12/31~)

▌言語Ruby (2007~)Python (2014~)

▌趣味ロードバイク (2009~)トライアスロン (2010~)

Page 6: Introduction to Magnum (JP)

6 © NEC Corporation 2015

趣味 : ロードバイク沼 (2009 – 2015)

Colnago em Willier La Triestina Bianchi Via Nirone Cervelo S1

Cervelo Soloist Carbon Cannondale CAAD9 Cervelo P3 Cervelo Super Prodigy

Cervelo P4 Cervelo S5 Team Speedvagen CX Team Speedvagen Road

Page 7: Introduction to Magnum (JP)

7 © NEC Corporation 2015

当社 OpenStack コミュニティ対応チーム

▌グループ員日本人開発者 5 名中国人開発者 1 名インド人開発者 3 名

▌OpenStack コア開発者Nova 1 名Tempest 3 名Magnum 2 名 1 名Ironic-inspector 1 名Senlin 1 名

Page 8: Introduction to Magnum (JP)

8 © NEC Corporation 2015

OpenStack との関わり

▌2011/10Cloud Foundry の調査業務

• OpenStack 上にて Cloud Foundry の構築。

▌2014/06グループ方針として Cloud Foundry から戦略的撤退

• 昨今の Cloud Foundry の盛り上がりを見ると、なぜこの時期に撤退したのか意味不明。

▌2014/07OpenStack コミュニティ対応チームに配属

• Python? なにそれ。• コミュニティの人間関係その他さっぱりわからない状態。

TripleO の調査

▌2014/11Magnum の調査・開発

▌2014/12Magnum コア開発者

Page 9: Introduction to Magnum (JP)

9 © NEC Corporation 2015

OpenStack との関わり

17:47 yuanying: at least one hour.17:47 sdake: think I am unblocked and have stack working17:47 sdake: so I'll start tackling the baremetal launch17:47 yuanying: using larks/kube?17:48 yuanying: if you have heat-template knowledge, I think its easy.17:48 sdake: I was ptl of heat for 3 cycles17:48 sdake: led team that wrote heat initially17:48 sdake: fairly well versed ;-)17:48 yuanying: really??17:48 sdake: yup17:49 yuanying: cool17:49 sdake: thanks :)

Page 10: Introduction to Magnum (JP)

Magnum とは?

Page 11: Introduction to Magnum (JP)

11 © NEC Corporation 2015

関連技術 -- Docker

Docker Engine▌ コンテナ型仮想化ソフトウェア

Namespace• マウント名前空間、 PID 名前空間、ユーザ名前空間 …

cgroup• cpu, memory, devices …

chroot• ディレクトリの隔離

netns• ネットワークの隔離

▌ アプリケーションのポータビリティWrite Once, Run Anywhere !Docker コンテナ = アプリケーション + 実行環境

これらの Linux がもともと持っていた技術を組みわせて利用している。

テスト環境

実行環境

Applibrary

1library

2

ステージング環境

実行環境

Applibrary

1library

2

商用環境

実行環境

Applibrary

1library

2

Page 12: Introduction to Magnum (JP)

12 © NEC Corporation 2015

関連技術 – コンテナ管理

Kubernetes▌複数ホストに配備された Docker コンテナをどう管理するか?

コンテナをどこに配備するべきか? ( スケジューリング )配備したコンテナはどのホストにいるのか?コンテナ間の連携は?

• アプリケーションコンテナはデータベースコンテナがどこに配備されたのかを知りたい。コンテナのオートスケールはどう対応する?

Page 13: Introduction to Magnum (JP)

13 © NEC Corporation 2015

Magnum とは

▌2013/11OpenStack におけるコンテナ対応について言及

▌2014/08コンテナ API に関するドラフト

• https://etherpad.openstack.org/p/openstack-containers-service-apiNova にてコンテナ対応 API にて提案

• https://review.openstack.org/#/c/114044▌2014/11

OpenStack Summit Paris のデザインサミットにて Magnum プロジェクトが始動NEC の OpenStack 対応チームが Magnum にジョイン

▌2014/12NEC からコア開発者が選出

▌2015/03Magnum が OpenStack プロジェクトに昇格

▌2015/05OpenStack Summit Vancouver にて次期 Experimental プロジェクトとして

Magnum が Keynote にて紹介

Page 14: Introduction to Magnum (JP)

14 © NEC Corporation 2015

Magnum とは

▌Container as a Service ??Magnum 当初の提案されたスペック

• Nova と同じように Compute Host を配備、 magnum-agent が container を管理。– magnum から直接 container を制御– Container as a Service !!

Page 15: Introduction to Magnum (JP)

15 © NEC Corporation 2015

Magnum とは

▌現状 : Container Orchestration Tools Installation as a ServiceKubernetes / Swarm などのコンテナ管理システムのインストレーションサービス。

• 例えばデータベースでいう Trove の位置付け。• gcloud の container サブコマンド相当。

Kubernetes / Swarm のクラスターを管理する。• Kubernetes / Swarm のクラスターを 「 Bay 」 と呼ぶ。

ユーザーテナント

Bay (Kubernetes Type)

KubernetesMaster

KubernetesMinion 1

KubernetesMinion 2

Service

Pod PodReplicationController Pod

Container ContainerContainer Container

Container Container

Bay (Swarm Type)

SwarmMaster Docker Node 2

Container Container Container Container

Container Container Container Container

Container Container Container Container

Container Container Container Container

Docker Node 1

Container Container Container Container

Container Container Container Container

Container Container Container Container

Container Container Container Container

Magnum

Kubernetes TypeBaymodel

image: fedora-atomickeypair: my_public_key

external-network: $NIC_IDdns-nameserver: 8.8.8.8

flavor: baremetaltype-of-bay: kubernetes

Swarm TypeBaymodel

image: fedora-atomickeypair: my_public_key

external-network: $NIC_IDdns-nameserver: 8.8.8.8

flavor: baremetaltype-of-bay: swarm

Page 16: Introduction to Magnum (JP)

16 © NEC Corporation 2015

Magnum でなにができるのか?

▌プロダクションユース可能な Kunernetes クラスターの管理 ( 予定 )そもそもプロダクションユース可能って何、という話はありますが…。優先度は低いが、 Docker-Swarm の管理も可能。

▌コンテナ管理のアブストラクションレイヤー提供 ( 予定 )Pod/Service/ReplicationController などの Kubernetes リソースを抽象化?現状は場当たり的な実装があるのみ、しかも Kubernetes にしか対応していない。

Page 17: Introduction to Magnum (JP)

17 © NEC Corporation 2015

当チームにおける Magnum に対する貢献

▌Bay 実装の First cut を担当Heat を利用したアーキテクチャの提案および実装はじめて通った magnum bay-create コマンド

▌Ironic サポートしかし現在、絶賛デグレード中…

▌Python Kubernetes ClientSwagger のスペックからクライアントを生成、、しかし動かないので手作業で修正。。

▌TLS-AuthMagnum でインストールされた k8s/swarm クラスターへの認証に利用。

Page 18: Introduction to Magnum (JP)

Magnum の使い方

Page 19: Introduction to Magnum (JP)

19 © NEC Corporation 2015

Swarm TypeKubernetes Type

Magnum の管理するリソース

▌Baymodel▌Bay

Kubernetes Type BaySwarm Type Bay

▌Kubernetes Type BayServiceReplicationControllerPod

▌Swarm Type BayContainer

Bay

Baymodel

Pod Service ContainerRC

Page 20: Introduction to Magnum (JP)

20 © NEC Corporation 2015

使い方

1. Baymodel の作成Bay のテンプレート。Bay 構築時に共通で使うパラメータをまとめておく。

2. Bay の作成Bay (Kubernetes Cluster)Baymodel と名前の指定。

3. Pod の作成1. Magnum Client を利用2. Native Client を利用

• Kubernetes 利用時の認証の設定。– TLS Auth 用 Private Key / Cert ファイルの取得。– TLS Auth 用 CA Cert の取得。

Page 21: Introduction to Magnum (JP)

21 © NEC Corporation 2015

使い方 : Baymodel の作成

# Baymodel の作成$ magnum baymodel-create --name kubernetes \ --image-id fedora-21-atomic-5 \ --keypair-id default \ --external-network-id public \ --dns-nameserver 8.8.8.8 --flavor-id m1.small \ --docker-volume-size 5 --coe kubernetes

Page 22: Introduction to Magnum (JP)

22 © NEC Corporation 2015

閑話休題 : Baymodel の ( よく分からない ) パラメータ

パラメータ 用途

--fixed-network Cluster が利用するプライベートネットワークのネットワークアドレス。 ex: 10.0.0.0/24

--network-driver コンテナのネットワークで利用されるネットワークドライバー。 k8s: flannel, swarm: docker がデフォルト。

--ssh-authorized-key クラスターのホスト OS が coreos の場合に、ユーザが ssh でログインするための public key を指定。

--tls-disabled Bay の TLS Auth を無効化する。

Page 23: Introduction to Magnum (JP)

23 © NEC Corporation 2015

使い方 : Bay (Kubernetes Cluster) の作成

# Bay の作成$ magnum bay-create --name k8sbay \ --baymodel kubernetes \ --node-count 2 \ --master-count 2

Page 24: Introduction to Magnum (JP)

24 © NEC Corporation 2015

使い方 : Pod/Service の作成 (magnum client 利用 )

Page 25: Introduction to Magnum (JP)

25 © NEC Corporation 2015

使い方 : Pod の作成 (magnum client 利用 )# あらかじめ Kubernetes をダウンロードし、 example を入手$ cd ~/kubernetes/examples/redis/v1beta3/

# Pod の作成$ magnum pod-create --manifest ./redis-master.yaml \ --bay k8sbay

Page 26: Introduction to Magnum (JP)

26 © NEC Corporation 2015

使い方 : Pod の作成 (native client 利用 )

Page 27: Introduction to Magnum (JP)

27 © NEC Corporation 2015

使い方 : Pod の作成 (native client 利用 ) (1)

# あらかじめ kubectl をインストールしておく。# api_address の値をメモ$ magnum bay-show k8sbay +----------------+------------------------------------------------------------+

| Property | Value |

+----------------+------------------------------------------------------------+

| status | CREATE_COMPLETE |

| uuid | d332bb21-e47a-49bb-bfa5-a4f1df60c51f |

| created_at | 2015-08-04T06:17:16+00:00 |

| updated_at | 2015-08-04T06:18:53+00:00 |

| api_address | https://192.168.19.92:8080 |

| baymodel_id | 9df7e273-374d-4e5c-9588-7c54aed1fb91 |

| node_count | None |

| node_addresses | [u'192.168.19.94'] |

| status_reason | Stack CREATE completed successfully |

| discovery_url | https://discovery.etcd.io/95a6db244e0bd14774757d88f2c5d412 |

| name | k8sbay |

+----------------+------------------------------------------------------------+

Page 28: Introduction to Magnum (JP)

28 © NEC Corporation 2015

使い方 : Pod の作成 (native client 利用 ) (2)# TLS-Auth 用の Certificate を入手

# 1. private key の作成$ openssl genrsa -out client.key 4096

# 2. csr の作成$ cat > client.conf << END[req]distinguished_name = req_distinguished_namereq_extensions = req_extprompt = no[req_distinguished_name]CN = Your Name[req_ext]extendedKeyUsage = clientAuthEND$ openssl req -new -days 365 \ -config client.conf \ -key client.key \ -out client.csr

`gcloud container cluster` では隠蔽されている作業を手作業で行

わなければならない。

Page 29: Introduction to Magnum (JP)

29 © NEC Corporation 2015

使い方 : Pod の作成 (native client 利用 ) (3)# 3. client certificate の要求$ magnum ca-sign --bay secure-k8sbay \ --csr client.csr > client.crt

# 4. CA cert の要求$ magnum ca-show --bay secure-k8sbay > ca.crt

# 5. Pod の作成$ kubectl create -f redis-master.yaml \ --certificate-authority=ca.crt \ --client-key=client.key \ --client-certificate=client.crt \ -s https://192.168.19.92:8080

# https://blueprints.launchpad.net/magnum/+spec/client-tls-auth-configuration

Page 30: Introduction to Magnum (JP)

アーキテクチャ

Page 31: Introduction to Magnum (JP)

31 © NEC Corporation 2015

アーキテクチャ

magnum_conductor

k8s_conductor

bay_conductor

magnum_api

heat

neutron neutronLBaaS glance cinder

TemplateDefinition

k8s_template_definition

swarm_template_definition

Bay (k8s)

k8smaster

k8sminion

Pod

Container Container

Pod

Container Container

Pod

Container Container

pythonk8s_client

Barbican

nova

bay Pod… CA

Page 32: Introduction to Magnum (JP)

32 © NEC Corporation 2015

アーキテクチャ (Bay 管理時 )

magnum_conductor

bay_conductor

magnum_api

heat

neutron neutronLBaaS glance cinder

TemplateDefinition

k8s_template_definition

swarm_template_definition

Bay (k8s)

k8smaster

k8sminion

Pod

Container Container

Pod

Container Container

Pod

Container Container

Barbican

nova

k8sheat

templateParameters

bay Pod… CAcert

cert

REST API 提供1. Bay

2. k8s resources3. CA

1. Heat に Stack の生成を要求

2. データベースにデータを保存

ユーザの要求 (baymodel) に従って Heat のテンプレート及

びパラメータを生成

k8s の TLS 接続に利用する Key の管理 Bay 構築のために必要な

OpenStack リソースの生成

cloud-init を利用した Kubernetes クラスターの設定

Page 33: Introduction to Magnum (JP)

33 © NEC Corporation 2015

Page 34: Introduction to Magnum (JP)

34 © NEC Corporation 2015

アーキテクチャ (K8S リソース管理時 )

magnum_conductor

k8s_conductor

magnum_api

Bay (k8s)

k8smaster

k8sminion

Pod

Container Container

Pod

Container Container

Pod

Container Container

pythonk8s_client

Page 35: Introduction to Magnum (JP)

開発環境

Page 36: Introduction to Magnum (JP)

36 © NEC Corporation 2015

開発環境

devstack

nova

neutron

heat

neutron-lbaas

barbican

ceilometer

magnum

magnum-api

magnum-conductor

192.168.11.0/24

197 198

devstack は構築済みとし、Magnum を別ノードに構築する。

Page 37: Introduction to Magnum (JP)

37 © NEC Corporation 2015

開発環境のセットアップ

https://gist.github.com/yuanying/f27cef22738acf8b1db5

1. 依存パッケージのインストール2. magnum, python-magnumclient のインストール3. magnum の設定4. データベースの作成5. magnum の起動

6. keystone への登録7. イメージの登録

8. keypair の登録

Page 38: Introduction to Magnum (JP)

38 © NEC Corporation 2015

開発環境のセットアップ (1) – 依存パッケージのインストール$ sudo apt-get install libffi-dev libssl-dev git vim build-essential \ libxml2-dev libsqlite3-dev libxslt1-dev python-dev libmysqlclient-dev –y

$ curl -s https://bootstrap.pypa.io/get-pip.py | sudo python$ sudo pip install virtualenv flake8 tox testrepository git-review

Page 39: Introduction to Magnum (JP)

39 © NEC Corporation 2015

開発環境のセットアップ (2) – magnum, magumclient

$ cd ~$ git clone https://github.com/openstack/magnum.git$ cd magnum# 以下コマンドで依存ライブラリおよび Magnum が# ~/magnum/.tox/venv にインストールされる。$ tox -evenv -- echo 'done’

$ cd ~$ git clone https://github.com/openstack/python-magnumclient.git$ cd python-magnumclient$ tox -evenv -- echo 'done'

Page 40: Introduction to Magnum (JP)

40 © NEC Corporation 2015

開発環境のセットアップ (3) – magnum の設定

$ cat > ~/magnum/etc/magnum/magnum.conf << END[DEFAULT]rabbit_userid=stackrabbitrabbit_password = stackqueuerabbit_hosts = 192.168.11.197rpc_backend = rabbit

[database]connection = mysql://root:[email protected]/magnum

[keystone_authtoken]admin_password = openstackadmin_user = novaadmin_tenant_name = serviceidentity_uri = http://192.168.11.197:35357auth_uri=http://192.168.11.197:5000/v3END

Page 41: Introduction to Magnum (JP)

41 © NEC Corporation 2015

開発環境のセットアップ (4) – データベースの作成

# データベースの作成$ mysql -h 192.168.11.197 -u root -pstackdb mysql <<EOFCREATE DATABASE IF NOT EXISTS magnum DEFAULT CHARACTER SET utf8;EOF

# テーブルの生成$ cd ~/magnum$ source .tox/venv/bin/activate$ pip install mysql-python$ magnum-db-manage --config-dir etc/magnum/ upgrade

Page 42: Introduction to Magnum (JP)

42 © NEC Corporation 2015

開発環境のセットアップ (5) – magnum の起動

# magnum-api$ cd ~/magnum$ source .tox/venv/bin/activate$ magnum-api --config-dir etc/magnum/

# magnum-conductor$ cd ~/magnum$ source .tox/venv/bin/activate$ magnum-api --config-dir etc/magnum/

Page 43: Introduction to Magnum (JP)

43 © NEC Corporation 2015

開発環境のセットアップ (6) – keystone への登録

# devstack のホストにて$ export HOST_IP=192.168.11.197$ source ~/devstack/openrc admin admin$ keystone service-create --name=magnum \ --type=container \ --description="Magnum Container Service"$ keystone endpoint-create --service=magnum \ --publicurl=http://192.168.11.198:9511/v1 \ --internalurl=http://192.168.11.198:9511/v1 \ --adminurl=http://192.168.11.198:9511/v1 \ --region RegionOne

Page 44: Introduction to Magnum (JP)

44 © NEC Corporation 2015

開発環境のセットアップ (7) – イメージの登録

# devstack のホストにて$ source ~/devstack/openrc admin admin

$ wget https://fedorapeople.org/groups/magnum/fedora-21-atomic-5.qcow2$ glance image-create --name fedora-21-atomic-5 \ --is-public True \ --disk-format qcow2 \ --property os_distro='fedora-atomic'\ --container-format bare \ < fedora-21-atomic-3.qcow2

Page 45: Introduction to Magnum (JP)

45 © NEC Corporation 2015

開発環境のセットアップ (8) – keypair の登録

# devstack のホストにて$ source ~/devstack/openrc demo demo

$ ssh-keygen$ nova keypair-add --pub-key ~/.ssh/id_rsa.pub testkey

Page 46: Introduction to Magnum (JP)

デモ

Page 47: Introduction to Magnum (JP)