关于swarm集群:72-创建一个三节点的swarm集群

41次阅读

共计 1941 个字符,预计需要花费 5 分钟才能阅读完成。

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
    {
        :name => "swarm-manager",
        :eth1 => "192.168.205.10",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "swarm-work1",
        :eth1 => "192.168.205.11",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "swarm-work2",
        :eth1 => "192.168.205.12",
        :mem => "1024",
        :cpu => "1"
    }
]

Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"
  boxes.each do |opts|
    config.vm.define opts[:name] do |config|
      config.vm.hostname = opts[:name]
      config.vm.provider "virtualbox" do |v|
        v.customize ["modifyvm", :id, "--memory", opts[:mem]]
        v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
      end
      config.vm.network :private_network, ip: opts[:eth1]
    end
  end
  config.vm.synced_folder ".", "/vagrant", :disabled => true
  config.vm.synced_folder "./labs", "/home/vagrant/labs", :nfs => true
  config.vm.provision "shell", privileged: true, path: "./setup.sh"
end

创立 manager 节点

vagrant ssh swarm-manager
docker swarm init --advertise-addr=192.168.205.10
Swarm initialized: current node (xk4srb722hwekv4vhkzgaq1ti) is now a manager.
To add a worker to this swarm, run the following command:
    docker swarm join --token SWMTKN-1-0c8b3a47nnjzclttnhhgdnl5mhfh8qic89wvq65yuddmgw46d5-43luksaph5upfe7b7gkx9t3ss 192.168.205.10:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

创立 worker 节点

如果报错:Error response from daemon: rpc error: code = Unavailable desc = grpc: the connection is unavailable,可能是因为有其余章节正在启动的虚拟机用了与 swarm-manager 雷同的 ip

vagrant ssh swarm-work1
docker swarm join --token SWMTKN-1-0c8b3a47nnjzclttnhhgdnl5mhfh8qic89wvq65yuddmgw46d5-43luksaph5upfe7b7gkx9t3ss 192.168.205.10:2377
vagrant ssh swarm-work2
docker swarm join --token SWMTKN-1-0c8b3a47nnjzclttnhhgdnl5mhfh8qic89wvq65yuddmgw46d5-43luksaph5upfe7b7gkx9t3ss 192.168.205.10:2377

查看节点

#docker node ls 只能在 manager 节点上执行
[vagrant@swarm-manager ~]$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
xk4srb722hwekv4vhkzgaq1ti * swarm-manager Ready Active Leader 18.05.0-ce
ie6azlh3y4qgyemteziufon7j swarm-work1 Ready Active 18.05.0-ce
wwaea67e4lbk5vn1y5r8i0uw9 swarm-work2 Ready Active 18.05.0-ce

正文完
 0