7.2 创建一个三节点的swarm集群

思过崖

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
阅读 332

从转行到入门,记录我的自学成长之路

59 声望
15 粉丝
0 条评论
你知道吗?

从转行到入门,记录我的自学成长之路

59 声望
15 粉丝
文章目录
宣传栏