Orchestration is the automatic process of managing or scheduling the work of individual containers for applications based on micro services within multiple clusters. The widely deployed container orchestration platforms are based on open-source versions like Kubernetes, Docker Swarm.
Why We Need Container Orchestration?
Container orchestration is used to automate the following tasks at scale:
• Configuring and scheduling of containers
• Provisioning and deployments of containers
• Availability of containers
• The configuration of applications in terms of the containers that they run in
• Scaling of containers to equally balance application workloads across infrastructure
• Allocation of resources between containers
• Load balancing, traffic routing and service discovery of containers
• Health monitoring of containers
• Securing the interactions between containers.
Container orchestration works with tools like Kubernetes and Docker Swarm. Configurations files tell the container orchestration tool how to network between containers and where to store logs. The orchestration tool also schedules deployment of containers into clusters and determines the best host for the container. After a host is decided, the orchestration tool manages the lifecycle of the container based on predetermined specifications. Container orchestration tools work in any environment that runs containers.
Orchestration tools for Docker include the following:
• Docker Machine — Provisions hosts and installs Docker Engine.
• Docker Swarm — Clusters multiple Docker hosts under a single host. It can also integrate with any tool that works with a single Docker host.
• Docker Compose — Deploys multi-container applications by creating the required containers.
A swarm consists of multiple Docker hosts which run in swarm mode and act as managers (to manage membership and delegation) and workers (which run swarm services). A node is an instance of the Docker engine participating in the swarm. To deploy your application to a swarm, you submit a service definition to a manager node. The manager node dispatches units of work called tasks to worker nodes.
A service is the definition of the tasks to execute on the manager or worker nodes. It is the central structure of the swarm system and the primary root of user interaction with the swarm.
When you create a service, you specify which container image to use and which commands to execute inside running containers.
Join as a worker node
The Docker Engine joins the swarm depending on the join-token you provide to the docker swarm join command. The node only uses the token at join time.
# docker swarm join-token worker
To add a worker to this swarm, run the followingcommand:
# docker swarm join--token********** (use same token generated while initialize master)192.168.200.9:2044
# docker swarm join-token manager
List nodes
# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
46aqrk4bt745z53cr3t node-3 Ready Active Reachable
a5b2m3391pefq5u node-2 Ready Active Reachable
ehkv3bcie79dn78otj5*node-1 Ready Active Leader
Create a service
To create a single-replica service with no extra configuration, you only need to supply the image name. This command starts an Nginx service with a randomly-generated name and no published ports. This is a naive example, since you can’t interact with the Nginx service.
$ docker service create nginx
The service is scheduled on an available node. To confirm that the service was created and started successfully, use the docker service ls command:
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
a3mjhts1lxuem quizzical_lamarr replicated 1/1 docker.io/library/nginx
To provide a name for your service, use the --name flag:
$docker service create--namemy_web nginx
Update a service
You can change almost everything about an existing service using the docker service update command. When you update a service, Docker stops its containers and restarts them with the new configuration.
Since Nginx is a web service, it works much better if you publish port 80 to clients outside the swarm. You can specify this when you create the service, using the -p or --publish flag. When updating an existing service, the flag is --publish-add. There is also a --publish-rm flag to remove a port that was previously published.
$docker service update--publish-add80 my_web
To verify that it worked, use docker service ls:
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
4nhxl7oxw5vz my_web replicated 1/1 docker.io/library/nginx@sha256:
Remove a service
To remove a service, use the docker service remove command. You can remove a service by its ID or name, as shown in the output of the docker service ls command. The following command removes the my_web service.
$ docker service remove my_web
Docker Service Child commands
| Command | Description |
| docker service create | Create a new service |
| docker service inspect | Display detailed information on one or more services |
| docker service logs | Fetch the logs of a service or task |
| docker service ls | List services |
| docker service ps | List the tasks of one or more services |
| docker service rm | Remove one or more services |
| docker service rollback | Revert changes to a service’s configuration |
| docker service scale | Scale one or multiple replicated services |
| docker service update | Update a service |
Docker service create (options)
| –detach , -d | Exit immediately instead of waiting for the service to converge | |
| –env , -e | Set environment variables | |
| –hostname | Container hostname | |
| –limit-cpu | Limit CPUs | |
| –limit-memory | Limit Memory | |
| –log-driver | Logging driver for service | |
| -mode | replicated | Service mode (replicated or global) |
| –mount | Attach a filesystem mount to the service | |
| –name | Service name | |
| –network | Network attachments | |
| –publish , -p | Publish a port as a node port | |
| –tty , -t | Allocate a pseudo-TTY |
#docker service create--nameredis--replicas=5 redis:3.0.6
Above Command Create a service with name redis with 5 replicas using redis:3.0.6 docker image.
References:
- https://docs.docker.com
- from Miscellaneous technical websites.
