Browse Source

swarm

master
test2 5 years ago
parent
commit
3e94834a8f
  1. 310
      DockerSwarm/Creaate-Swarm.adoc
  2. BIN
      DockerSwarm/replicated-vs-global.png
  3. BIN
      DockerSwarm/services-diagram.png

310
DockerSwarm/Creaate-Swarm.adoc

@ -168,6 +168,16 @@ docker node demote id
== Manage nodes == Manage nodes
[NOTE]
.INFO
====
This is a cluster management command, and must be executed on a swarm manager node.
====
- *docker node ls* List nodes in the swarm - *docker node ls* List nodes in the swarm
---- ----
@ -176,9 +186,9 @@ docker node ls
- *docker node demote* `_ Demote one or more nodes from manager in the swarm_` - *docker node demote* `_ Demote one or more nodes from manager in the swarm_`
- *docker node inspect* `_ Display detailed information on one or more nodes_` - *docker node inspect* `_ Display detailed information on one or more nodes_`
- *docker node promote* `_ Promote one or more nodes to manager in the swarm_~ - *docker node promote* `_ Promote one or more nodes to manager in the swarm_`
- *docker node ps* `_ List tasks running on one or more nodes, defaults to current node_` - *docker node ps* `_ List tasks running on one or more nodes, defaults to current node_`
- *docker node rm* `_ Remove one or more nodes from the swarm_~ - *docker node rm* `_ Remove one or more nodes from the swarm_`
- *docker node update* `_ Update a node_` - *docker node update* `_ Update a node_`
- *docker node inspect* `_ Display detailed information on one or more nodes_` - *docker node inspect* `_ Display detailed information on one or more nodes_`
@ -244,3 +254,299 @@ docker node inspect id | jq -r '.[]["Status"]["State"]'
==== ====
== Deploy services and Tasks
To deploy an application image when Docker Engine is in swarm mode, you *create a service.*
A service is the image for a microservice within the context of some larger application.
Examples of services might include an HTTP server, a database, or any other type of executable program that you wish to run in a distributed environment.
A *task* is the atomic unit of scheduling within a swarm.
When you declare a desired service state by creating or updating a service, the orchestrator realizes the desired state by scheduling tasks.
For instance, you define a service that instructs the orchestrator to keep three instances of an HTTP listener running at all times.
The orchestrator responds by creating three tasks.
Each task is a slot that the scheduler fills by spawning a container.
image:./services-diagram.png[alt="services"] +
=== service vs stack
- A *Service* defines one or more instances of a single image deployed on one or more machines (described by one entry in the services part of *yaml* files).
- A *Stack* defines a group of heterogeneous services (described by the whole yaml file).
The *docker service* command is used when managing individual service on a docker swarm cluster.
The *docker stack* command can be used to manage a multi-service application.
=== Build
[NOTE]
.INFO
====
This is a cluster management command, and must be executed on a swarm manager node.
====
==== Create yaml
.yml example MPI (save as run.yml)
[source,sh]
----
version: "3.8"
services:
master:
image: image
user: root
environment:
# Pass environment variables to containers CUSTOM
- PASSWORD=dgergergergerrfgwehrtsger
- PASSWORDVIEW=rtyrwtyrwftertgueteyserfy5e6ytrg
- SERVERROLE=master
- SERVERWEB=no
# Pass environment variables to containers FROM ENGINE see inspect
- NODENAME={{.Node.Hostname}}
- NODEID={{.Node.ID}}
- SERVICEID={{.Service.ID}}
- SERVICENAME={{.Service.Name}}
- TASKID={{.Task.ID}}
- TASKNAME={{.Task.Name}}
- TASKREPID={{.Task.Slot}}
deploy:
# mode: global # see image replica-vs-global
replicas: 1
placement:
max_replicas_per_node: 1
constraints:
- node.role == worker
#- node.labels.region == region1
resources:
limits:
cpus: '0.50'
memory: 500M
reservations:
cpus: '0.25'
memory: 200M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 5
window: 120s
update_config:
parallelism: 2
delay: 10s
order: stop-first
networks:
mpi2-net:
ports:
- "5580:80"
- "5588:8088"
slave:
image: image
user: root
environment:
- PASSWORD=rtyrthrthyrthyrtyrtyrty
- PASSWORDVIEW=rtyrtuyrtuyrt
- SERVERROLE=slave
- SERVERWEB=no
- NODENAME={{.Node.Hostname}}
- NODEID={{.Node.ID}}
- SERVICEID={{.Service.ID}}
- SERVICENAME={{.Service.Name}}
- TASKID={{.Task.ID}}
- TASKNAME={{.Task.Name}}
- TASKREPID={{.Task.Slot}}
deploy:
# mode: global # see image replica-vs-global
replicas: 9
placement:
max_replicas_per_node: 1
constraints:
- node.role == worker
- node.labels.region == region2
resources:
limits:
cpus: '0.50'
memory: 500M
reservations:
cpus: '0.25'
memory: 200M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 5
window: 120s
update_config:
parallelism: 2
delay: 10s
order: stop-first
networks:
mpi2-net:
ports:
- "5581:80"
- "5590:8088"
web:
image: image
user: root
environment:
- SERVERROLE=web
- SERVERWEB=yes
- NODENAME={{.Node.Hostname}}
- NODEID={{.Node.ID}}
- SERVICEID={{.Service.ID}}
- SERVICENAME={{.Service.Name}}
- TASKID={{.Task.ID}}
- TASKNAME={{.Task.Name}}
- TASKREPID={{.Task.Slot}}
deploy:
# mode: global # see image replica-vs-global
replicas: 1
placement:
constraints:
- node.role == worker
- node.labels.region == region3
resources:
limits:
cpus: '0.50'
memory: 500M
reservations:
cpus: '0.25'
memory: 200M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 5
window: 120s
update_config:
parallelism: 2
delay: 10s
order: stop-first
networks:
mpi2-net:
ports:
- "5598:80"
- "5599:8088"
networks:
mpi2-net:
----
image:./replicated-vs-global.png[alt="replica-vs-global"] +
[NOTE]
.INFO
====
YAML (a recursive acronym for "YAML Ain't Markup Language") is a human-readable data-serialization language.
It is commonly used for configuration files and in applications where data is being stored or transmitted.
YAML targets many of the same communications applications as Extensible Markup Language (XML) but has a minimal syntax which intentionally differs from SGML 
It uses Python-style indentation to indicate nesting
From Wikipedia, the free encyclopedia +
more: Learn YAML in five minutes!
https://www.codeproject.com/Articles/1214409/Learn-YAML-in-five-minutes[^]
====
==== Build
.build
[source,sh]
----
docker stack deploy -c run.yml my_service
----
==== Lists services
.List the services that are running as part of the specified stack.
[source,sh]
----
docker stack services
----
.List *ALL* services are running in the swarm.
[source,sh]
----
docker service ls
----
==== Remove one or more stacks
.Remove the stack from the swarm.
[source,sh]
----
docker stack rm
----
.Removes the specified services from the swarm.
[source,sh]
----
docker service rm
----
==== List tasks
.List the tasks that are running as part of the specified services.
[source,sh]
----
docker service ps
----
.List the tasks in the stack
[source,sh]
----
docker stack ps
----
[NOTE]
.INFO
====
Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands.
more info: https://en.wikipedia.org/wiki/Command-line_completion[^]
====

BIN
DockerSwarm/replicated-vs-global.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
DockerSwarm/services-diagram.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Loading…
Cancel
Save