pythonとyamlでgcpをdeploy!「google cloud deployment manager」

34
PythonとYAMLでGCPをDeploy! 「Google Cloud Deployment Manager」 cz! Nbtbtij!Ufsvj!bu!QzDpo!Njoj!Tbqqpsp!3126

Upload: terui-masashi

Post on 09-Jan-2017

1.920 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

PythonとYAMLでGCPをDeploy! 「Google Cloud Deployment Manager」

Page 2: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

2

Page 3: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

3

Page 4: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

Masashi Terui @ marcy_teruiI’m a developer and architect in the operators company (JIG-SAW Inc.)

I'm the organizer on the some of events in sapporo with the theme of "Infrastructure as Code”. I’m a member of JAWS-UG Sapporo and GCPUG Sapporo (Coming soon!)

I develop a IoT application (ServerSide) with Python and more. I’m a husband of my wife. I’m a father of my son and daughter.

ABOUT ME

4

Page 5: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

ABOUT US

5

Coming soon!!

Page 6: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

6

Page 7: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

7

Cloud Deployment Managerは、複雑なクラウドプラットフォームのソリューションを

シンプルな宣言型のテンプレートを使用して、

開発者が容易に設計、共有、展開、管理することを可能とします。

簡単なWebサーバから複雑な高可用性クラスタまで、

Cloud Deployment Managerはチームがインフラの管理に費やす時間を少なくし、

より多くの時間を開発をに向けることができます。

- - 公式ページ(https://cloud.google.com/deployment-manager/) の英文訳(間違ってたらゴメンナサイ) -

Page 8: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

つまり

8

複雑なクラウドプラットフォームのソリューション

シンプルな宣言型のテンプレート

容易に設計、共有、展開、管理

→ GCPを

→ YAMLで

→ アレコレできちゃうわけです

Page 9: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

9

resources: - type: compute.v1.instance name: vm-my-first-deployment properties: zone: us-central1-b machineType: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/zones/us-central1-b/machineTypes/f1-micro disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: diskName: disk-my-first-deployment sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140619 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT

Page 10: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

10

いいえ、違います

YAMLとかJSONとかは”Code”ではありません

あくまでデータ(リソース)の表現方法(フォーマット)

別にあ○しぼーをdisってるわけではありません

個人的見解です

Page 11: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

11

Page 12: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

12

JSON or YAML

CloudFormationはより細かく制御でき、

ほとんどのサービスや機能を網羅しているが表現が冗長

軽く1000行とかのJSONができあがるの、何か間違ってると思うんですよ…

Pythonで書ける

Page 13: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

13

Page 14: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

14

インフラのコード化

自動化

再現可能なインフラ

インフラの世界へ開発のプロセスを持ち込む(TDD, CI etc…)

バズワード・・・?

Page 15: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

15

Page 16: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

16

Page 17: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

17

Page 18: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

18

Page 19: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

19

resources: - type: compute.v1.instance name: vm-my-first-deployment properties: zone: us-central1-b machineType: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/zones/us-central1-b/machineTypes/f1-micro disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: diskName: disk-my-first-deployment sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140619 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT

Page 20: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

20

def GenerateConfig(context): return """ resources: - type: compute.v1.instance name: vm-my-first-deployment properties: zone: us-central1-b machineType: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/zones/us-central1-b/machineTypes/f1-micro <snip> sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140619 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT """

Page 21: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

21

import helpers.common

def GenerateConfig(context): return """ resources: - type: compute.v1.instance name: %(name) properties: zone: %(zone) machineType: %(machine_type) disks: - deviceName: boot <snip> sourceImage: %(source_image) networkInterfaces: - network: %(metwork_project)/global/networks/default <snip> """ % {"name": (common.GenerateMachineName("myFrontend", context.env(“environment")), "zone": context.env("zone"),, "machine_type": common.GenerateMachineTypeURI(zone=context.env("zone"), type=context.env("type")), "project": common.GenerateProjectURI(context.env("project")), "source_image": common.GenerateProjectURI("debian-cloud", "ebian-7-wheezy-v20140619"), "metwork_project": common.GenerateProjectURI("sunlit-arcade-100913")}

Page 22: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

22

Page 23: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

こんな風に

23

よく使う記述をメソッドにまとめる

オブジェクトに属性を与えて、

メソッドコールするだけ的な感じにしたり

使い回しを考えて共通化・部品化

自分(達)のインフラ構築・管理フレームワークを作れる

Page 24: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

24

Page 25: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

25

Page 26: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

26

gcloud deployment-manager deployments create <name> --config <yml>

Page 27: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

27

公式ドキュメント(英語ですw)

https://cloud.google.com/deployment-manager/overview

Page 28: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

28

Page 29: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

29

Page 30: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

30

Page 32: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

32

Page 33: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」

33

Pythonでクラウド(特にGCP)を操りたい イケてるクラウドインフラ上でPythonでIoTサーバサイド開発したい方今のところAWSメイン(Kinesis, DynamoDBとか、コアなプロダクト触れます) GCPは具体的に活用計画有り、Azure他もベンダー問わずメリットあるなら使います。もちろんInfra as CodeやChatOps等も実践しています。

Page 34: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」