docker-compose 单节点的问题,多个实体机就无法适应的。
多机器如何管理?如果跨机器做scale横向扩展?容器失败退出时如何新建容器确保服务正常运行?如何确保零宕机时间?如何管理密码,Key等敏感数据?其它 容器编排 swarm
Swarm的基本架构
docker swarm vs kubernetesk8s在容器编排领域处于绝对领先的地位
2021年redhat调查:https://www.redhat.com/en/resources/kubernetes-adoption-security-market-trends-2021-overview
为什么还要学些了解docker swarm呢?
swarm作为分布式集群架构,相对k8s简单很多,也是一个典型分布式架构,通过学习能了解很多分布式知识的,很多内容和k8s想通的,去理解k8s就会很快,所以可以从swarm开始学起。
Swarm 单节点快速上手PS F:docker> docker swarm Usage: docker swarm COMMAND Manage Swarm Commands: ca Display and rotate the root CA init Initialize a swarm join Join a swarm as a node and/or manager join-token Manage join tokens leave Leave the swarm unlock Unlock swarm unlock-key Manage the unlock key update Update the swarm Run 'docker swarm COMMAND --help' for more information on a command.初始化
docker info 这个命令可以查看我们的docker engine有没有激活swarm模式, 默认是没有的,我们会看到
Swarm: inactive
激活swarm,有两个方法:
初始化一个swarm集群,自己成为manager加入一个已经存在的swarm集群
PS F:docker> docker swarm init
Swarm initialized: current node (c1wjw7zp6gnk85rlwww5z5ot5) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4wm4icfpg9g4a429is7tjvsqfn28u7xnmkyjilzs4hpzfv031t-0kzmaqemqig5066ybdlwqletw 192.168.65.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
PS F:docker> docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
c1wjw7zp6gnk85rlwww5z5ot5 * docker-desktop Ready Active Leader 20.10.11
PS F:docker>
docker swarm init 背后发生了什么
主要是PKI和安全相关的自动化
创建swarm集群的根证书manager节点的证书其它节点加入集群需要的tokens
创建Raft数据库用于存储证书,配置,密码等数据
退出swarm的环境,非激活的状态--force牵制离开
PS F:docker> docker swarm leave --force Node left the swarm.创建一个service
PS F:docker> docker service create nginx:latest zc60j740nf7drrogxem5zm4to overall progress: 1 out of 1 tasks 1/1: running [==================================================>] verify: Service converged PS F:docker> docker service ls ID NAME MODE REPLICAS IMAGE PORTS zc60j740nf7d beautiful_jones replicated 1/1 nginx:latest
zc60j740nf7drrogxem5zm4to 是 serviceID
查看具体的一个service:docker service ps
PS F:docker> docker service ls ID NAME MODE REPLICAS IMAGE PORTS zc60j740nf7d beautiful_jones replicated 1/1 nginx:latest PS F:docker> docker service ps zc60j740nf7d ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS y2os1b2wgyjx beautiful_jones.1 nginx:latest docker-desktop Running Running about a minute ago PS F:docker>



