2017年9月10日日曜日

VagrantでDocker Swarmクラスタを構築する

以下のVagrantfileを使用して、3ノードのDocker Swarmクラスタを構築できます。

Dockerfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "dockerswarm1" do |server|
    server.vm.box = "bento/centos-7.3"
    server.vm.hostname = "dockerswarm1"
    server.vm.network :public_network, ip:"192.168.1.190"
    server.vm.network "private_network", ip: "192.168.55.190", :netmask => "255.255.255.0"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "dockerswarm1"
      vbox.cpus = 2
      vbox.memory = 2048
      vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
    end
    server.vm.provision "shell", inline: <<-SHELL
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --disable docker-ce-edge
yum -y install docker-ce
systemctl enable docker
systemctl start docker

docker swarm init --advertise-addr 192.168.55.190  | grep -e '--token' | sed -e 's/    //' - > /vagrant/joincmd.sh
chmod +x /vagrant/joincmd.sh

SHELL
  end
  #----------------------------------------------------------------------------------------
  config.vm.define "dockerswarm2" do |server|
    server.vm.box = "bento/centos-7.3"
    server.vm.hostname = "dockerswarm2"
    server.vm.network :public_network, ip:"192.168.1.191"
    server.vm.network "private_network", ip: "192.168.55.191", :netmask => "255.255.255.0"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "dockerswarm2"
      vbox.cpus = 2
      vbox.memory = 2048
      vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
    end
    server.vm.provision "shell", inline: <<-SHELL
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --disable docker-ce-edge
yum -y install docker-ce
systemctl enable docker
systemctl start docker
/vagrant/joincmd.sh

SHELL
  end
  #----------------------------------------------------------------------------------------
  config.vm.define "dockerswarm3" do |server|
    server.vm.box = "bento/centos-7.3"
    server.vm.hostname = "dockerswarm3"
    server.vm.network :public_network, ip:"192.168.1.192"
    server.vm.network "private_network", ip: "192.168.55.192", :netmask => "255.255.255.0"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "dockerswarm3"
      vbox.cpus = 2
      vbox.memory = 2048
      vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
    end
    server.vm.provision "shell", inline: <<-SHELL
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --disable docker-ce-edge
yum -y install docker-ce
systemctl enable docker
systemctl start docker
/vagrant/joincmd.sh

SHELL
  end
  #----------------------------------------------------------------------------------------

end

0 件のコメント:

コメントを投稿