27. zem@dev:~$ sudo nomad agent -dev
==> Starting Nomad agent...
==> Nomad agent configuration:
Atlas: <disabled>
Client: true
Log Level: DEBUG
Region: global (DC: dc1)
Server: true
==> Nomad agent started! Log data will stream in below:
2015/10/08 23:02:28 [INFO] serf: EventMemberJoin: dev.docker.jp.global 127.0.0.1
2015/10/08 23:02:28 [INFO] nomad: starting 1 scheduling worker(s) for [service batch _core]
2015/10/08 23:02:28 [INFO] raft: Node at 127.0.0.1:4647 [Follower] entering Follower state
これでテスト用の環境が、すぐ
立ち上がります。
28. zem@dev:~$ nomad node-status
ID DC Name Class Drain Status
2b4b3259-f143-2abf-46d4-62905268263e dc1 dev.docker.jp <none> false ready
zem@dev:~$ nomad server-members
Name Addr Port Status Proto Build DC Region
dev.docker.jp.global 127.0.0.1 4648 alive 2 0.1.2 dc1 global
状態確認のIDですが、エージェ
ントごとにUUIDが割り当てられ
ます。Serf・Consul風のメンバ
管理コマンドです。
29. # There can only be a single job definition per file.
# Create a job with ID and Name 'example'
job "example" {
# Run the job in the global region, which is the default.
# region = "global"
# Specify the datacenters within the region this job can run in.
datacenters = ["dc1"]
# Service type jobs optimize for long-lived services. This is
# the default but we can change to batch for short-lived tasks.
# type = "service"
# Priority controls our access to resources and scheduling priority.
# This can be 1 to 100, inclusively, and defaults to 50.
# priority = 50
# Restrict our job to only linux. We can specify multiple
# constraints as needed.
constraint {
attribute = "$attr.kernel.name"
value = "linux"
}
# Configure the job to do rolling updates
update {
# Stagger updates every 10 seconds
stagger = "10s"
# Update a single task at a time
max_parallel = 1
}
# Create a 'cache' group. Each task in the group will be
# scheduled onto the same machine.
group "cache" {
# Control the number of instances of this groups.
# Defaults to 1
# count = 1
# Define a task to run
task "redis" {
# Use Docker to run the task.
driver = "docker"
# Configure Docker driver with the image
config {
image = "redis:latest"
}
# We must specify the resources required for
# this task to ensure it runs on a machine with
# enough capacity.
resources {
cpu = 500 # 500 Mhz
memory = 256 # 256MB
network {
mbits = 10
dynamic_ports = ["6379"]
}
}
}
}
}
zem@dev:~$ nomad init
Example job file written to example.nomad 設定ファイルのサンプルです。
ここでリソースやジョブを定義
30. zem@dev:~$ nomad run example.nomad
==> Monitoring evaluation "88fc77ac-d878-b27f-925c-c0e131658ac6"
Evaluation triggered by job "example"
Allocation "1170083d-dd2c-92ec-1e29-44f25eb3de75" created: node "2b4b3259-f143-2abf-46d4-629
05268263e", group "cache"
Evaluation status changed: "pending" -> "complete"
==> Evaluation "88fc77ac-d878-b27f-925c-c0e131658ac6" finished with status "complete"
2015/10/08 23:59:57 [DEBUG] driver.docker: docker pull redis:latest succeeded
2015/10/08 23:59:57 [DEBUG] driver.docker: using image 2f2578ff984f013c9a5d6cbb6fe061ed3f73…
2015/10/08 23:59:57 [INFO] driver.docker: identified image redis:latest as 2f2578ff984f013c…
2015/10/08 23:59:57 [DEBUG] driver.docker: using 268435456 bytes memory for redis:latest
2015/10/08 23:59:57 [DEBUG] driver.docker: using 500 cpu shares for redis:latest
2015/10/08 23:59:57 [WARN] driver.docker: no mode specified for networking, defaulting to bridge
2015/10/08 23:59:57 [DEBUG] driver.docker: using bridge as network mode
2015/10/08 23:59:57 [DEBUG] driver.docker: allocated port 128.199.223.107:44054 -> 6379 (mapped)
2015/10/08 23:59:57 [INFO] driver.docker: created container ca2c4efd37e4c5dee82da48fce248e…
2015/10/08 23:59:57 [INFO] driver.docker: started container ca2c4efd37e4c5dee82da48fce248e…
zem@dev:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ca2c4efd37e4 redis:latest "/entrypoint.sh redis" 49 seconds ago Up 49
seconds 128.199.223.107:44054->6379/tcp desperate_mayer
コマンドを実行すると、勝手に
コンテナを起動してくれます。
31. zem@dev:~$ nomad status example
ID = example
Name = example
Type = service
Priority = 50
Datacenters = dc1
Status = <none>
==> Evaluations
ID Priority TriggeredBy Status
88fc77ac-d878-b27f-925c-c0e131658ac6 50 job-register complete
==> Allocations
ID EvalID NodeID
TaskGroup Desired Status
1170083d-dd2c-92ec-1e29-44f25eb3de75 88fc77ac-d878-b27f-925c-c0e131658ac6 2b4b3259-f143-2abf-
46
d4-62905268263e cache run running
こちらは状態確認コマンド。
32. zem@dev:~$ nomad run example.nomad
==> Monitoring evaluation "8a72b095-79fc-f521-acea-463fd049d36c"
Evaluation triggered by job "example"
Allocation "5f4dfa20-ed30-18fb-9a18-300a374f2eac" created: node "2b4b3259-f143-2abf-46d4-
62905268263e", group "cache"
Allocation "fa612324-877a-c589-4c03-87b393a7e721" created: node "2b4b3259-f143-2abf-46d4-
62905268263e", group "cache"
Allocation "1170083d-dd2c-92ec-1e29-44f25eb3de75" modified: node "2b4b3259-f143-2abf-46d4-
62905268263e", group "cache"
Evaluation status changed: "pending" -> "complete"
==> Evaluation "8a72b095-79fc-f521-acea-463fd049d36c" finished with status "complete"
zem@dev:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
376c15af6b8f redis:latest "/entrypoint.sh redis" 1 seconds ago Up Less
than a second 128.199.223.107:58268->6379/tcp prickly_visvesvaraya
2a78baaa8ec7 redis:latest "/entrypoint.sh redis" 1 seconds ago Up Less
than a second 128.199.223.107:29865->6379/tcp mad_fermi
ca2c4efd37e4 redis:latest "/entrypoint.sh redis" 5 minutes ago Up 5
minutes 128.199.223.107:44054->6379/tcp desperate_mayer
スケールするのも簡単。
コンテナが3つになりました。
42. 42
‣ otto dev ( vagrant up 相当 )
otto dev ssh
otto dev address
otto dev destroy
‣ otto infra ( terraform apply 相当 )
‣ otto build ( packer build 相当 )
‣ otto deploy
コマンド実行例 「vagrant up」のかわりに
「otto dev ~」を実行します。
43. 43
Ottoを使うには
‣ 対応OS
Windows, Mac OS X, Linux
‣ ダウンロード
https://ottoproject.io/downloads.html
‣ チュートリアル
https://ottoproject.io/intro/getting-started/install.html
$ cd /tmp
$ wget -O otto.zip https://dl.bintray.com/mitchellh/otto/otto_0.1.1_linux_amd64.zip
$ unzip otto.zip
$ sudo mv otto /usr/bin/
$ sudo chmod 755 /usr/bin/otto
$ otto -v
Otto v0.1.1
HashiCorpの他のツール同様に
コマンド1つを実行するだけ。
44. $ git clone https://github.com/hashicorp/otto-getting-started.git
$ cd otto-getting-started
$ otto compile
==> Loading Appfile...
==> No Appfile found! Detecting project information...
No Appfile was found. If there is no Appfile, Otto will do its best
to detect the type of application this is and set reasonable defaults.
This is a good way to get started with Otto, but over time we recommend
writing a real Appfile since this will allow more complex customizations,
the ability to reference dependencies, versioning, and more.
(省略)
==> Compiling main application...
==> Compilation success!
This means that Otto is now ready to start a development environment,
deploy this application, build the supporting infastructure, and
more. See the help for more information.
Supporting files to enable Otto to manage your application from
development to deployment have been placed in the output directory.
These files can be manually inspected to determine what Otto will do.
チュートリアルが機能を試す
のに非常に分かりやすいです。
45. $ otto status
==> App Info
Application: otto-getting-started (ruby)
Project: otto-getting-started
Infrastructure: aws (simple)
==> Component Status
Dev environment: NOT CREATED
Infra: READY
Build: NOT BUILT
Deploy: NOT DEPLOYED
こちらは状態確認するコマンド
46. $ otto infra
==> Detecting infrastructure credentials for: otto-getting-started (aws)
Cached and encrypted infrastructure credentials found.
Otto will now ask you for the password to decrypt these
credentials.
…
==> otto: Deleting temporary security group...
==> otto: Deleting temporary keypair...
Build 'otto' finished.
==> Builds finished. The artifacts of successful builds are:
--> otto: AMIs were created:
us-east-1: ami-27185642
==> Storing build data in directory...
==> Build success!
The build was completed successfully and stored within
the directory service, meaning other members of your team
don't need to rebuild this same version and can deploy it
immediately.
「aws」環境上に、セキュリ
ティ・グループなどインフラに
関連する情報を読み込みます。
47. $ otto build
…
==> otto: Deleting temporary security group...
==> otto: Deleting temporary keypair...
Build 'otto' finished.
==> Builds finished. The artifacts of successful builds are:
--> otto: AMIs were created:
us-east-1: ami-27185642
==> Storing build data in directory...
==> Build success!
The build was completed successfully and stored within
the directory service, meaning other members of your team
don't need to rebuild this same version and can deploy it
immediately.
こちらはデプロイに向けて
マシン・イメージの自動構築。
後ろでpackerを使っています。