05 Docker Cluster/Infrastructure - The Road to DevOps
Article Github address, welcome
start
: https://github.com/li-keli/DevOps-WiKi
The current mainstream solutions for Docker clusters:
Docker Swarm cluster
It is to deploy a stateless service with a Swarm cluster:
There are currently three physical machines node01, node02, and node03, and Swarm is initialized on node01:
docker swarm init --advertise-addr 192.168.0.10 # 你的IP地址
At this time, a swarm manage node will be created and a sample join command will be output. Run the command output above on other docker machines to docker swarm join
join the cluster.
docker swarm join \
--token SWMTKN-1-2apg79ozshm0x9hgqgm7v3qo4ks6qcgqzqir5z03g6y90qolf8-***************** \
192.168.0.10:2377
If you forget the password and token output by init, you can docker swarm join-token worker
check it through the command.
Create service
Execute the command on the manager node:
docker service create --name web_server --publish 8080:80 --replicas=2 192.168.0.10:60000/test/api:1.0
The command is to create a service called web_server in the cluster and expose port 8080
Through docker service ls
can view all the services in the current cluster
Through the ocker service ps [服务名]
ability to view the operation of all containers [replicas] of the specified service
network of services
By default, services are created as follows:
docker service create --name web_server --replicas=2 192.168.0.10:60000/test/api:1.0
The services created in this way can only be accessed within the container and cannot be accessed externally
If the service is newly created, --publish 8080:80
it will map and expose 8080 to the outside.
If the service has already been created, execute:
docker service update --publish-add 8080:80 web_server
Elastic scaling service
If we want to do load balancing, we need a lot of nodes, then execute in swarm-manager:
docker service scale web_server=5
In this way, the number of replicas in the service can be increased and kept constant to 5
By default, the manager node is also a worker node, so swarm-manager also runs a replica. If you don't want to run the service on the manager, you can execute the following command:
docker node update --availability drain swarm-manager
Don't want to run service on manager
By default, the manager node is also a worker node, so swarm-manager also runs a replica. If you don't want to run the service on the manager, you can execute the following command:
docker node update --availability drain swarm-manager
In addition, due to the limited knowledge of the author himself, he is all groping, so not all practices are correct, or some practices will have better solutions. I hope readers will correct me. If you have any questions, please leave issues .