创建群集

初始化群集

master 主机执行以下命令

$ docker swarm init --advertise-addr 10.0.20.120
Swarm initialized: current node (w64t4fblkpuyj0jjk3g47df6v) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2z52uy5clu57n7tax3wmf97qx3ohiskmu0an6bz3w96kmx782z-b9m2k35lwd5tmu6s3h795omwp 10.0.20.120:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

[info] --advertise-addr 配置master发布地址,其他节点必须能够访问该ip,才能加入群集

输出包括其他节点加入该群集的完整命令和token。后续查看使用docker swarm join-token manager

查看当前swarm状态

$ docker info
Swarm: active
 NodeID: w64t4fblkpuyj0jjk3g47df6v
 Is Manager: true
 ClusterID: hlgjh2b5cbuzzt756m6d9au8e
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 10.0.20.120
 Manager Addresses:
  10.0.20.120:2377

查看当前节点

$  docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
w64t4fblkpuyj0jjk3g47df6v *   master              Ready               Active              Leader              18.03.0-ce

[info] '*' 表示当前连接的节点

添加节点


docker swarm join --token SWMTKN-1-2z52uy5clu57n7tax3wmf97qx3ohiskmu0an6bz3w96kmx782z-b9m2k35lwd5tmu6s3h795omwp 10.0.20.120:2377

查看当前节点,发现其他三台节点已加入当前群集

$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
w64t4fblkpuyj0jjk3g47df6v *   master              Ready               Active              Leader              18.03.0-ce
y3lswmm2qsuqvi0k55digfvjn     ndoe2               Ready               Active                                  18.03.0-ce
kreazv2yearuk14ovl06lri3z     ndoe3               Ready               Active                                  18.03.0-ce
v5xx8zo3hf19g6olxpzpjvxj1     node1               Ready               Active                                  18.03.0-ce

修改master只具备管理功能

[info] node的AVAILABILITY有三种状态:ActivePauseDrain

常见的变更操作:

  • 设置Manager Node只具有管理功能
  • 对服务进行停机维护,可以修改AVAILABILITYDrain状态
  • 暂停一个Node,然后该Node就不再接收新的Task
  • 恢复一个不可用或者暂停的Node

例如,使Manager Node只具备管理功能,不能部署实际的Docker容器来运行服务,执行如下命令:

docker node update --availability drain master

添加标签元数据

docker node update --label-add 键名称=值 node

修改群集证书过期时间

docker swarm update --cert-expiry 87600h

results matching ""

    No results matching ""