Vagrantで複数のVMを起動する
コンニチハ、千葉です。
K8sの勉強環境として、インターネット接続なしでガチャガチャいじれる環境が欲しくなり、VirtualBox + Vagrantを利用しました。 で、複数VM起動できるの?ってちょっと調べたのでアウトプットしておきます。
やってみた
調べたところ、公式でMulti-Machineがサポートされていたのでやってみました。 Vagrantfileに複数のVMを指定するだけでいけそうです。
1 2 3 4 5 6 7 8 9 | Vagrant.configure( "2" ) do |config| config.vm.define "k8s_master" do |k8s_master| k8s_master.vm.box = "ubuntu/trusty64" end config.vm.define "k8s_node_1" do |k8s_node_1| k8s_node_1.vm.box = "ubuntu/trusty64" end end |
これだけです。起動してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $ vagrant up Bringing machine 'k8s_master' up with 'virtualbox' provider... Bringing machine 'k8s_node_1' up with 'virtualbox' provider... Bringing machine 'test' up with 'virtualbox' provider... ・・・省略 $ vagrant status Current machine states: k8s_master running (virtualbox) k8s_node_1 running (virtualbox) This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`. |
起動できてます!
sshで接続するにはsshの後ろにVMの名前を入れます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | $ vagrant ssh k8s_master Welcome to Ubuntu 14.04.5 LTS (GNU /Linux 3.13.0-145-generic x86_64) * Documentation: https: //help .ubuntu.com/ System information as of Mon Apr 30 04:53:36 UTC 2018 System load: 0.78 Processes: 82 Usage of /: 3.6% of 39.34GB Users logged in : 0 Memory usage: 25% IP address for eth0: 10.0.2.15 Swap usage: 0% Graph this data and manage this system at: https: //landscape .canonical.com/ Get cloud support with Ubuntu Advantage Cloud Guest: http: //www .ubuntu.com /business/services/cloud 0 packages can be updated. 0 updates are security updates. New release '16.04.4 LTS' available. Run 'do-release-upgrade' to upgrade to it. |
接続できました!
最後に
Vagrantを使って複数VMを起動してみました。K8s用のローカル環境が用意できたので、ガチャガチャ作っては壊して試して見ます。