1. Introduction to Swarm
Swarm is a self-developed container cluster management system developed by Docker. Swarm existed as an independent service in the early days, in the Docker Engine Swarm’s cluster management and orchestration functions are integrated in v1.12. The Swarm mode of the Docker engine can be enabled by initializing the Swarm or adding an existing Swarm.
Docker Engine CLI and API include management Swarm node commands, such as adding and deleting nodes, and deploying and orchestrating services in Swarm. The concepts of Stack, Service, and Task are also added.
2. Features of Swarm:
Reference link (https://docs.docker.com/engine/swarm/)
1. Docker Engine integrated cluster management
Use Docker Engine CLI to create a Docker Engine Swarm mode, in the cluster Deploy application services in the.
2. Decentralized design
Swarm roles are divided into Manager and Worker nodes. The failure of Manager node does not affect the application.
3. Expansion and shrinkage
You can declare the number of containers that each service runs, and automatically adjust the desired state by adding or deleting the number of containers.
4. Expected status coordination
The Swarm Manager node constantly monitors the cluster status and adjusts the difference between the current status and the desired status.
5. Multi-host network
The overlay network can be specified for the service. When the application is initialized or updated, the Swarm manager will automatically assign an IP address to the container on the overlay network.
6. Service Discovery
Swarm manager node assigns unique DNS records and load balancing VIP for each service in the cluster. You can query each running container in the cluster through the built-in DNS server of Swarm.
7. Load Balancing
Realize the load balancing of service copies and provide entrance access.
8. Secure Transmission
Each node in Swarm uses TLS to authenticate and encrypt each other to ensure secure communication with other nodes.
9. Rolling update
When upgrading, gradually update the application service to the node. If there is a problem, you can roll back the task to the previous version.
Three, swarm key concepts
1. What is swarm?
The cluster management and task scheduling functions have been integrated into the Docker engine through the use of swarmkit. Swarmkit is an independent project dedicated to Docker container orchestration and can be used directly on Docker.
Swarm cluster is composed of multiple Docker hosts running swarm mode. The key is that Docker defaults Integrated swarm mode. In the swarm cluster, there are managers (management of membership and elections) and workers (running swarm service).
A Docker host can be a manager or a worker role. Of course, it can also be a manager. Also a worker.
When you create a service, you define its ideal state (number of copies, network, Storage resources, exposed ports, etc.). Docker will maintain its state. For example, if a worker node becomes unavailable, Docker will schedule tasks from unavailable nodes to other nodes.
A task running in the container is part of the swarm service and is managed by the swarm manager And scheduling, and independent containers are very different.
2, nodes
3, services and tasks
4, Load balancing
4. Swarm architecture Figure
Swarm manager:
1. API: accept the command and create a service (API input)
2. Orchestrator: The task created by the service object is arranged (arrangement)
3. Allocater: For Each task assigns an IP address (assign IP)
4, dispatcher: distribute tasks to nodes (distribute Task)
5, scheduler: schedule a worker to run task (run task)< /p>
worker node
1, connect to the distributor to accept the specified task
2, assign the task to the corresponding worker node
Example:
The swarm manager creates a service with 3 nginx replica sets, and he will assign tasks to the corresponding nodes.