Docker swarm combat summary Docker management tools -Swarm docker-compose choreography arguments detailed

 

 


I. Introduction

Swarm is a cluster management tools provided by Docker official , whose main role is to host a number of Taiwan Docker abstract as a whole, and unified management of these resources on a variety of Docker Docker host through a portal.

Docker Swarm includes two aspects: a Docker enterprise-class security cluster, as well as a micro application service orchestration engine.

Cluster aspects, Swarm Docker one or more nodes organize themselves, enabling users to manage their way in a cluster, you can freely add or delete nodes .

Choreography aspects, Swarm provides a rich set of API makes deployment and management of complex micro-service applications a breeze. By applying defined in declarative configuration file, you can use native Docker order to complete the deployment.

In addition, even you can perform a rolling upgrade, rollback and scaling capacity operation , also based on a simple command to complete.

In the past, Docker Swarm is based on a stand-alone product Docker engine. Since Docker 1.12 version, it is fully integrated in Docker engine , execute a command to enable.

By 2018, in addition to native Swarm application, it can deploy and manage Kubernetes applications. Swarm and Kubernetes relatively similar, but much lighter, has fewer functions than kubernetes number.

Cluster management:   Docker have the Swarm sub-command init, join, leave, update (to see help)

Node Manager:   Docker sub-command has the Node accept, promote, demote, inspect,to see help)

Configuration Management:   Docker config subcommand has create, inspect, ls, rm (View help)

Service Management:   Docker Service sub-command has create, inspect, update, remove,View help)

Stack Management:   Docker Stack sub-command has deploy, services, ps, rm (View help)

 


Second, the department

  preliminary work

  Prepare several machines, installing Docker + v1.12 , add a private source mirror warehouse

/etc/docker/daemon.json

{ "insecure-registries":["xxx.xxx.xxx.xxx:5000"] }

    Guaranteed between the cluster nodes 4789 TCP 2377, TCP / UDP 7946 and UDP port communication (directly or turn off the firewall systemctl stop firewalld)

cmd = public---zone Firewall --add-Port = 2377 / tcp --permanent    # cluster management port

firewall-cmd --zone = public --add-    port = 7946 / tcp --permanent communication port between the node #
firewall-cmd --zone = public --add- port = 7946 / udp --permanent

cmd = public---zone Firewall --add-Port = 4789 / tcp --permanent   # overlay network communication port
firewall-cmd --zone = public --add- port = 4789 / udp --permanent

firewall-cmd --reload

  

  Initialization swarm

the Swarm the init Docker \        # default initialization node manager

--advertise-addr 192.168.89.14 \   # In case of multiple network adapters, specifies the need to use ip

192.168.89.14:2377-addr --listen   # specify the listener's ip and port

  

 

   Add Work node

    --token acquires the initialization or acquisition (command Docker Swarm the Join token-worker )

docker swarm join \

192.168.89.15-addr --advertise \
--listen-addr 192.168.89.15:2377 \  # may increase, according to the actual needs

--token SWMTKN-1-29ynh5uyfiiospy4fsm4pd4xucyji2rn0oj4b4ak4s7a37syf9-ajkrv2ctjr5cmxzuij75tbrmz \  # 节点token

192.168.89.14:2377  # 管理节点

  

  管理节点

docker node ls   # 查看节点

docker node rm   # 移除节点

docker swarm leave   # 退出节点(对应节点上运行)

   更详细部署推荐>>> Docker Swarm集群部署实践

 


三、Docker config

17.06引入了群体服务配置,使您可以在服务映像之外或运行中的容器之外存储非敏感信息,例如配置文件。这使您可以保持映像尽可能通用,而无需将安装文件绑定安装到容器中或使用环境变量。

可以随时在服务中添加或删除配置,并且服务可以共享配置。您甚至可以将配置与环境变量或标签结合使用,以实现最大的灵活性。配置值可以是通用字符串或二进制内容(最大500 kb)。

注意:Docker配置仅适用于群集服务,不适用于独立容器。

将配置添加到群集时,Docker会通过双向TLS连接将配置发送到群集管理器。该配置存储在Raft日志中,该日志已加密。整个Raft日志会在其他管理器之间复制,以确保对配置的高可用性保证与其他集群管理数据一样。

当您授予对配置的新创建或正在运行的服务访问权限时,该配置将作为文件安装在容器中。容器中安装点的位置默认为/<config-name>Linux容器中的位置。

 docker config create jmdiservice-application.properties ~/local/application.properties  # 为创建服务所引用

 


四、Docker service

服务是自 Docker 1.12 后新引入的概念,并且仅适用于 Swarm 模式。

使用服务仍能够配置大多数熟悉的容器属性,比如容器名、端口映射、接入网络和镜像。

此外还增加了额外的特性,比如可以声明应用服务的期望状态,将其告知 Docker 后,Docker 会负责进行服务的部署和管理。

更多概念推荐>>> Docker管理工具-Swarm

 

服务创建

docker service create \
--with-registry-auth \
--mode global \
--name jmdiservice \
--config source=jmdiservice-application.properties,target=/root/application.properties \
--mount type=bind,source=/opt/lib,destination=/root/lib \ --env JAVA_OPTS="-Xms1024m -Xmx1024m" \ --publish 20036:20036 \ -td xx.xx.xx.xx:5000/zwx/jmdiservice:1123    

命令详解:

--with-registry-auth:将registry身份验证详细信息发送给集群代理。

--mode global:全局模式,在这种模式下,每个节点上仅运行一个副本。
   另一种是复制模式(--replicas 3),这种模式会部署期望数量的服务副本,并尽可能均匀地将各个副本分布在整个集群中。

--name:服务名称。(避免使用符号,容易解析错误)

--config:指定要向服务公开的配置。(添加配置参考docker config create)

--mount:将文件系统挂载附加到服务。(需要保留/读取的容器外信息)

--env:设置环境变量。

--publish:将端口发布为节点端口。(默认把需要发布的端口映射到本地)

-td:分配伪TTY,并后台运行。

注意:镜像地址、名称、标签一定填写正确

 

  服务更新:

docker service update --args "ping www.baidu.com" redis    # 添加参数
docker service scale redis=4    # 为服务扩(缩)容scale
docker service update --image redis:3.0.7 redis  # 更新服务的镜像版本
docker service update --rollback redis  # 回滚服务

 


五、Docker stack

大规模场景下的多服务部署和管理是一件很难的事情,Docker Stack由此而生。

Stack 通过提供期望状态、滚动升级、简单易用、扩缩容、健康检查等特性简化了应用的管理,这些功能都封装在一个完美的声明式模型当中。

Stack 能够在单个声明文件中定义复杂的多服务应用,还提供了简单的方式来部署应用并管理其完整的生命周期:初始化部署 -> 健康检查 -> 扩容 -> 更新 -> 回滚

 

步骤很简单,在 Compose 文件中定义应用,然后通过 docker stack deploy 命令完成部署和管理。

export logpath=/home/jhmyPro/logs      
export tag=latest              # 使用环境变量,增强可用性
docker stack deploy --with-registry-auth -c docker-compose.yml QS    

 

# file: docker-compose.yml

version: "3.7" services: JmDiService: # 服务名 image: xx.xx.xx.xx:5000/zwx/jmdiservice:${tag} environment: # 环境变量 LOG_PATH: ${logpath}     PKG_NAME: "JmDiService" JAVA_OPTS: "-Xms512m -Xmx1024m" networks: # 网络设置 overlay: ports: # 端口映射 [宿主机:容器] - 20036:20036 configs: # 读取配置 [配置名:容器] - source: JmDiService-application.properties target: /root/application.properties volumes: # 挂载数据卷 [宿主机:容器] - ${logpath}:${logpath} - /opt/lib:/root/lib - /usr/local/nginx/html/clientexe:/usr/local/nginx/html/clientexe deploy: # 部署设置 mode: replicated replicas: 3 restart_policy: # 重启策略 [条件,延时,最大次数,检测时间] condition: on-failure delay: 5s max_attempts: 3 window: 30s update_config: # 升级配置 [并发数,延时,失败处理,监听时间,更新规则] parallelism: 1 delay: 5s failure_action: rollback monitor: 5s order: start-first resources: # 资源控制 [cpu,mem] limits: #cpus: '0.2' memory: 1024M configs:      # 定义配置 JmDiService-application.properties: external: true networks:     # 定义网络 overlay:

   更多参数定义推荐>>> docker-compose编排参数详解

 

 

作者:Leozhanggg

出处:https://www.cnblogs.com/leozhanggg/p/12061360.html

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Guess you like

Origin www.cnblogs.com/leozhanggg/p/12061360.html