LoginSignup
5
5

More than 5 years have passed since last update.

Google Cloud Platform上にマルチホストのLatticeを構築する

Last updated at Posted at 2015-05-09

Docker image互換のコンテナ管理システム、Lattice(http://lattice.cf/) を、Google Cloud Platform上に構築する方法を解説します。

事前準備

terraformのセットアップ

Latticeの構築には、HashiCorpのTerraformを利用します。
Terraformのサイトからダウンロードして、セットアップを行っておきます
https://www.terraform.io/downloads.html

本記事では、Terraform 0.5.0を利用します。

Latticeのclone

githubからlatticeをcloneします。

git clone git@github.com:cloudfoundry-incubator/lattice.git

本項ではv0.2.4を利用します。

ltcコマンドのセットアップ

Latticeの操作に必要なltcコマンドのバイナリをダウンロードし、PATHが通っている場所に設置しておきます

OSX https://lattice.s3.amazonaws.com/releases/v0.2.4/darwin-amd64/ltc
Linux https://lattice.s3.amazonaws.com/releases/v0.2.4/linux-amd64/ltc

account fileの準備

以下の手順でGCPからaccount fileをダウンロードします。

gcp1.png

gcp2.png

gcp3.png

ここでダウンロードされたjsonファイルを、latticeのディレクトリにaccount.jsonという名前で保存しておきます。

SSH鍵の作成と登録

GCPで利用するSSH鍵を生成しておきます。ここでは、id_rsa_googleという名前で作成します

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jacopen/.ssh/id_rsa): id_rsa_google
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
以下略

作成が終わったら、公開鍵をGCPに登録しておきます。
gcp4.png

tfファイルの編集

cd lattice
cp terraform/google/example/lattice.google.tf google.tf

GCP向けのtfファイルをexampleからコピーし、編集します。

module "lattice-google" {
    source = "github.com/cloudfoundry-incubator/lattice//terraform//google?ref=v0.2.4-75-g958293d"

    gce_account_file = "account.json"
    gce_project = "local-pier-93718"  # GCPのProject名
    gce_ssh_user = "jacopen" # GCPに登録したSSH鍵のuser名
    gce_ssh_private_key_file = "id_rsa_google"
    num_cells = "3" # コンテナを動かすLattice Cellの数
    gce_region = "asia-east1" # 動作させたいRegion
    gce_zone = "asia-east1-b" # 動作させたいZONE
    gce_machine_type_cell = "n1-standard-1" # CellのMachine type
}

output "lattice_target" {
    value = "${module.lattice-google.lattice_target}"
}

output "lattice_username" {
    value = "${module.lattice-google.lattice_username}"
}

output "lattice_password" {
    value = "${module.lattice-google.lattice_password}"
}

exampleに、 gce_region, gce_zone, gce_machine_type_cell を追加しています。

標準ではus-central1-aとなってしまうため、距離が遠くレイテンシが大きいです。そのため、asia-east1-bを指定しています。

また、標準のMachine Typeはn1-standard-4(4Core 15GB Memory)と、ちょっと試す分には過剰なスペックなので、n1-standard-1を指定しています。その代わり、Cellの数を3としています。

terraform apply

ここまで出来れば、後はterraform get -> applyするだけです。

$ terraform get
$ terraform apply

最後まで通ったら、以下のような情報が表示されてているはずです

Outputs:

  lattice_password = pass
  lattice_target   = 104.155.237.xxx.xip.io
  lattice_username = user

試してみる

ltcコマンドで、実際にLatticeを使ってみましょう。

$ ltc target 104.155.237.xxx.xip.io
Username: user
Password:
Api Location Set

$ ltc create lattice-app cloudfoundry/lattice-app
No port specified, image metadata did not contain exposed ports. Defaulting to 8080.
No working directory specified, using working directory from the image metadata...
Monitoring the app on port 8080...
No start command specified, using start command from the image metadata...
Start command is:
/lattice-app
Creating App: lattice-app
......................09 May 20:19 [APP|0] Successfully created container
09 May 20:19 [APP|0] {"timestamp":"1431170351.597540855","source":"lattice-app","message":"lattice-app.lattice-app.starting","log_level":1,"data":{"port":"8080"}}
09 May 20:19 [APP|0] {"timestamp":"1431170351.597871065","source":"lattice-app","message":"lattice-app.lattice-app.up","log_level":1,"data":{"port":"8080"}}
.09 May 20:19 [HEALTH|0] healthcheck passed
09 May 20:19 [HEALTH|0] Exit status 0
09 May 20:19 [APP|0] Lattice-app. Says Hello. on index: 0

lattice-app is now running.
App is reachable at:
http://lattice-app.104.155.237.xxx.xip.io

最後に表示されているURLにアクセスすると、サンプルアプリに繋がるはずです。簡単ですね!

Terraformで構築が出来るので、AWSやDigital Oceanの場合もそう大差ない操作で構築が可能のはずです。是非一度試してみてください。

関連情報

Lattice深掘り話 http://www.slideshare.net/jacopen/lattice-47937770

5
5
0

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
5
5