IK.AM

@making's tech note


VirtualBox on Ubuntu 16.04にBOSH v2 CLIでBOSH Liteをインストールする

🗃 {Dev/Infrastructure/BOSH}
🏷 BOSH 🏷 BOSH-Lite 
🗓 Updated at 2018-01-04T18:50:55Z  🗓 Created at 2017-04-22T19:17:37Z   🌎 English Page

メモ

https://www.starkandwayne.com/blog/bosh-lite-on-virtualbox-with-bosh2/

を参考に。

目次

Virtual Boxインストール

echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install virtualbox-5.1 ruby
sudo reboot

BOSH v2 CLIインストール

wget https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-2.0.13-linux-amd64
sudo install bosh-cli-2.0.13-linux-amd64 /usr/local/bin/bosh

bosh-deploymentのclone

git clone https://github.com/cloudfoundry/bosh-deployment  
cd bosh-deployment

BOSH Lite VMの作成

CPU数とRAM,Diskの容量を変えたい場合はvirtualbox/cpi.ymlを変更。

自分は次のように変更した

-    cpus: 2
-    memory: 4096
-    ephemeral_disk: 16_384
+    cpus: 6
+    memory: 30_720
+    ephemeral_disk: 102_400

bosh create-envでbootstrap

bosh2 create-env bosh.yml \
  --state ./state.json \
  -o virtualbox/cpi.yml \
  -o virtualbox/outbound-network.yml \
  -o bosh-lite.yml \
  -o bosh-lite-runc.yml \
  -o jumpbox-user.yml \
  --vars-store ./creds.yml \
  -v director_name="bosh-lite" \
  -v internal_ip=192.168.50.6 \
  -v internal_gw=192.168.50.1 \
  -v internal_cidr=192.168.50.0/24 \
  -v outbound_network_name=NatNetwork

VBoxManageコマンドで作成されたVMとネットワークを確認。

$ VBoxManage list vms --long
Name:            vm
Groups:          /
Guest OS:        Ubuntu (64-bit)
UUID:            ee0bb889-543e-4c4d-8d26-158696fb0080
Config file:     /home/maki/VirtualBox VMs/vm/vm.vbox
Snapshot folder: /home/maki/VirtualBox VMs/vm/Snapshots
Log folder:      /home/maki/VirtualBox VMs/vm/Logs
Hardware UUID:   ee0bb889-543e-4c4d-8d26-158696fb0080
Memory size:     512MB
Page Fusion:     off
VRAM size:       16MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  1
PAE:             on
Long Mode:       on
Triple Fault Reset: off
APIC:            on
X2APIC:          on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
BIOS APIC mode:  APIC
Time offset:     0ms
RTC:             local time
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     off
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State:           powered off (since 2017-04-22T17:53:21.000000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address: 
Teleporter Password: 
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration: 
Autostart Enabled: off
Autostart Delay: 0
Default Frontend: 
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SCSI
Storage Controller Type (1):            LsiLogic
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  16
Storage Controller Port Count (1):      16
Storage Controller Bootable (1):        on
IDE (0, 0): /home/maki/VirtualBox VMs/vm/image-disk1.vmdk (UUID: bfbb1355-7867-4740-b207-7ff65b4b73d7)
NIC 1:           disabled
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           enabled (Driver: ALSA, Controller: AC97, Codec: STAC9700)
Clipboard Mode:  disabled
Drag and drop Mode: disabled
VRDE:            disabled
USB:             disabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:

<none>

Bandwidth groups:  <none>

Shared folders:  <none>

Video capturing:    not active
Capture screens:    0
Capture file:       /home/maki/VirtualBox VMs/vm/vm.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB


Name:            sc-069969e4-a28f-4537-5f66-5ef7413851c2
Groups:          /
Guest OS:        Ubuntu (64-bit)
UUID:            373d3420-9d77-4731-bc3d-56d1dcf0a9fb
Config file:     /home/maki/VirtualBox VMs/sc-069969e4-a28f-4537-5f66-5ef7413851c2/sc-069969e4-a28f-4537-5f66-5ef7413851c2.vbox
Snapshot folder: /home/maki/VirtualBox VMs/sc-069969e4-a28f-4537-5f66-5ef7413851c2/Snapshots
Log folder:      /home/maki/VirtualBox VMs/sc-069969e4-a28f-4537-5f66-5ef7413851c2/Logs
Hardware UUID:   373d3420-9d77-4731-bc3d-56d1dcf0a9fb
Memory size:     512MB
Page Fusion:     off
VRAM size:       16MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  1
PAE:             on
Long Mode:       on
Triple Fault Reset: off
APIC:            on
X2APIC:          on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
BIOS APIC mode:  APIC
Time offset:     0ms
RTC:             local time
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     off
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State:           powered off (since 2017-04-22T17:55:26.838000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address: 
Teleporter Password: 
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration: 
Autostart Enabled: off
Autostart Delay: 0
Default Frontend: 
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SCSI
Storage Controller Type (1):            LsiLogic
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  16
Storage Controller Port Count (1):      16
Storage Controller Bootable (1):        on
IDE (0, 0): /home/maki/VirtualBox VMs/sc-069969e4-a28f-4537-5f66-5ef7413851c2/Snapshots/{6852c207-e4a5-4897-9b63-8588635f567b}.vmdk (UUID: 6852c207-e4a5-4897-9b63-8588635f567b)
NIC 1:           disabled
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           enabled (Driver: ALSA, Controller: AC97, Codec: STAC9700)
Clipboard Mode:  disabled
Drag and drop Mode: disabled
VRDE:            disabled
USB:             disabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:

<none>

Bandwidth groups:  <none>

Shared folders:  <none>

Video capturing:    not active
Capture screens:    0
Capture file:       /home/maki/VirtualBox VMs/sc-069969e4-a28f-4537-5f66-5ef7413851c2/sc-069969e4-a28f-4537-5f66-5ef7413851c2.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB

Snapshots:

   Name: prepared-clone (UUID: b1cbeca8-a079-4578-8c41-16e4d88902ac) *

Name:            vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a
Groups:          /
Guest OS:        Ubuntu (64-bit)
UUID:            f3dd1dd7-961e-409d-7e23-2059bfb6177a
Config file:     /home/maki/VirtualBox VMs/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a.vbox
Snapshot folder: /home/maki/VirtualBox VMs/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a/Snapshots
Log folder:      /home/maki/VirtualBox VMs/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a/Logs
Hardware UUID:   f3dd1dd7-961e-409d-7e23-2059bfb6177a
Memory size:     30720MB
Page Fusion:     off
VRAM size:       16MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  6
PAE:             on
Long Mode:       on
Triple Fault Reset: off
APIC:            on
X2APIC:          on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
BIOS APIC mode:  APIC
Time offset:     0ms
RTC:             local time
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     off
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Minimal
Effective Paravirt. Provider: Minimal
State:           running (since 2017-04-22T17:56:04.929000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address: 
Teleporter Password: 
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration: 
Autostart Enabled: off
Autostart Delay: 0
Default Frontend: 
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SCSI
Storage Controller Type (1):            LsiLogic
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  16
Storage Controller Port Count (1):      16
Storage Controller Bootable (1):        on
IDE (0, 0): /home/maki/VirtualBox VMs/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a/Snapshots/{3cd78cac-40d1-4066-8b19-3d22ff8aec34}.vmdk (UUID: 3cd78cac-40d1-4066-8b19-3d22ff8aec34)
IDE (0, 1): /home/maki/.bosh_virtualbox_cpi/disks/disk-e4498d2b-1430-47a7-7a2f-e56f093fe562/disk.vmdk (UUID: 7e696197-f3b6-445f-b336-1da847eca923)
IDE (1, 0): /home/maki/.bosh_virtualbox_cpi/disks/disk-920919cf-f1c3-415d-5c52-3f32a4978ad3/disk.vmdk (UUID: 70051835-bc7f-4f1b-aa1c-518e88277d57)
SCSI (0, 0): /home/maki/.bosh_virtualbox_cpi/vms/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a/env.iso (UUID: 04aa833b-6c25-46cd-bf40-01a8c0824636)
NIC 1:           MAC: 020F9D01516D, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2:           MAC: 0266EA92C232, Attachment: NAT Network 'NatNetwork', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           enabled (Driver: ALSA, Controller: AC97, Codec: STAC9700)
Clipboard Mode:  disabled
Drag and drop Mode: disabled
Session name:    headless
VRDE:            disabled
USB:             disabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:

<none>

Bandwidth groups:  <none>

Shared folders:  <none>

Video capturing:    not active
Capture screens:    0
Capture file:       /home/maki/VirtualBox VMs/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a/vm-f3dd1dd7-961e-409d-7e23-2059bfb6177a.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB
$ VBoxManage list hostonlyifs
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
DHCP:            Disabled
IPAddress:       192.168.50.1
NetworkMask:     255.255.255.0
IPV6Address:     fe80:0000:0000:0000:0800:27ff:fe00:0000
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
$ VBoxManage natnetwork list
NAT Networks:

Name:        NatNetwork
Network:     10.0.2.0/24
Gateway:     10.0.2.1
IPv6:        No
Enabled:     Yes

1 network found

BOSH環境設定

bosh2 alias-env vbox -e 192.168.50.6 --ca-cert <(bosh2 int ~/bosh-deployment/creds.yml --path /director_ssl/ca)
export BOSH_CLIENT=admin
export BOSH_CLIENT_SECRET=`bosh2 int ~/bosh-deployment/creds.yml --path /admin_password`
export BOSH_ENVIRONMENT=192.168.50.6

Route Tableの設定

sudo route add -net 10.244.0.0/16 gw 192.168.50.6

Stemcellのアップロード

bosh2 upload-stemcell https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-trusty-go_agent

Cloud Configの設定

bosh2 -n update-cloud-config ~/bosh-deployment/warden/cloud-config.yml

サンプルアプリで動作確認

bosh2 -n -d hello-legacy-tomcat deploy <(wget -O- https://raw.githubusercontent.com/making-dev/hello-legacy-tomcat-boshrelease/master/manifest/simple.yml)

bosh vmsで立ち上がったインスタンス(BOSH LiteなのでVMではなくコンテナ)を確認

$ bosh2 vms
Using environment '192.168.50.6' as client 'admin'

Task 5. Done

Deployment 'hello-legacy-tomcat'

Instance                                                  Process State  AZ  IPs         VM CID                                VM Type  
hello-legacy-tomcat/3677118a-33f4-41ce-bca0-174867a733fe  running        z1  10.244.0.2  94e87319-339c-46d8-472c-f6da5ea143d1  default  

1 vms

Succeeded

動作確認

$ curl 10.244.0.2:8080/env
PATH: /bin:/usr/bin:/sbin:/usr/sbin:/var/vcap/packages/java/bin
MONIT_SERVICE: hello-legacy-tomcat
MONIT_PROCESS_PID: 0
JAVA_HOME: /var/vcap/packages/java
MONIT_PROCESS_CHILDREN: 0
XFILESEARCHPATH: /usr/dt/app-defaults/%L/Dt
MONIT_EVENT: Started
MONIT_DESCRIPTION: Started
NLSPATH: /usr/dt/lib/nls/msg/%L/%N.cat
MONIT_PROCESS_CPU_PERCENT: 0
MONIT_HOST: localhost
PWD: /etc/sv/monit
MONIT_PROCESS_MEMORY: 0
SHLVL: 0
MONIT_DATE: Sat, 22 Apr 2017 18:21:49 +0000

HA Proxyで外からのアクセスを可能にする

sudo apt-get install haproxy

/etc/haproxy/haproxy.cfgの末尾に

frontend hello_tomcat_frontend
    bind *:8080
    default_backend	hello_tomcat_backend
backend hello_tomcat_backend
    balance roundrobin
    server hello_tomcat 10.244.0.2:8080

を追加して

sudo service haproxy restart

動作確認

$ curl localhost:8080/env
PATH: /bin:/usr/bin:/sbin:/usr/sbin:/var/vcap/packages/java/bin
MONIT_SERVICE: hello-legacy-tomcat
MONIT_PROCESS_PID: 0
JAVA_HOME: /var/vcap/packages/java
MONIT_PROCESS_CHILDREN: 0
XFILESEARCHPATH: /usr/dt/app-defaults/%L/Dt
MONIT_EVENT: Started
MONIT_DESCRIPTION: Started
NLSPATH: /usr/dt/lib/nls/msg/%L/%N.cat
MONIT_PROCESS_CPU_PERCENT: 0
MONIT_HOST: localhost
PWD: /etc/sv/monit
MONIT_PROCESS_MEMORY: 0
SHLVL: 0
MONIT_DATE: Sat, 22 Apr 2017 18:21:49 +0000

https://www.starkandwayne.com/blog/tag/bosh2/

がおすすめ


✒️️ Edit  ⏰ History  🗑 Delete