Skip to content

Latest commit

 

History

History
118 lines (68 loc) · 5.5 KB

1.Orchestration.md

File metadata and controls

118 lines (68 loc) · 5.5 KB

Orchestration

1. Complete the setup of a swarm mode cluster, with managers and worker nodes

  1. create a new swarm $ docker swarm init --advertise-addr <MANAGER-IP>
  2. To retrieve the join command including the join token for worker/manager nodes, run the following command on a manager node: $ docker swarm join-token worker/manager
  3. Run the command from the output on the worker/manager to join the swarm: docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 192.168.99.100:2377

2. State the differences between running a container vs running a service

The docker run command creates and starts a container on the local docker host. A docker "service" is one or more containers with the same configuration running under docker's swarm mode. It's similar to docker run in that you spin up a container. The difference is that you now have orchestration. That orchestration restarts your container if it stops, finds the appropriate node to run the container on based on your constraints, scale your service up or down, allows you to use the mesh networking and a VIP to discover your service, and perform rolling updates to minimize the risk of an outage during a change to your running application.

3. Demonstrate steps to lock a swarm cluster

  • Initialize a swarm with autolocking enabled $ docker swarm init --autolock
  • Enable or disable autolock on an existing swarm docker swarm update --autolock=true

4. Extend the instructions to run individual containers into running services under swarm

  1. Create a service$ docker service create --name="myservice" --replicas 3 ubuntu:latest
  2. Change a service: docker service update --replicas 5 myservice

5. Interpret the output of "docker inspect" commands

Return low-level information on Docker objects. Docker inspect provides detailed information on constructs controlled by Docker. By default, docker inspect will render results in a JSON array.

6. Convert an application deployment into a stack file using a YAML compose file with "docker stack deploy"

The docker stack deploy command supports any Compose file of version “3.0” or above. Create and update a stack from a compose or file on the swarm. This command has to be run targeting a manager node. docker stack deploy --compose-file docker-compose.yml stackdemo

7. Increase # of replicas

  • docker service update --replicas 2 SERVICE
  • docker service scale SERVICE=REPLICAS

8. Add networks, publish ports

docker service update \ --publish-add published=8080,target=80 \ myservice

docker service update \ --network-rm my-network \ --network-add name=my-network,alias=web1 \ myservice

9. Mount volumes

docker service update \ --mount-add \ type=volume,source=other-volume,target=/somewhere-else \ myservice

10. Illustrate running a replicated vs global service

There are two types of service deployments, replicated and global.

For a replicated service, you specify the number of identical tasks you want to run. For example, you decide to deploy an HTTP service with three replicas, each serving the same content.

A global service is a service that runs one task on every node. There is no pre-specified number of tasks. Each time you add a node to the swarm, the orchestrator creates a task and the scheduler assigns the task to the new node. Good candidates for global services are monitoring agents, an anti-virus scanners or other types of containers that you want to run on every node in the swarm.

The diagram below shows a three-service replica in yellow and a global service in gray.

11. Identify the steps needed to troubleshoot a service not deploying

???

12. Apply node labels to demonstrate placement of tasks

We can use node constraints to control which nodes a service’s tasks will run on based upon node labels. Here is an example: docker service create --constraint node.labels.availability_zone==east nginx To use various expressions for constraints, such as inequality, we can run, for instance: docker service create --constraint node.labels.availability_zone!=east

Use --placement-pref to spread tasks evenly based on the value of a specific label: docker service create --placement-pref spread=node.labels.availability_zone --replicas 3 nginx

13. Sketch how a Dockerized application communicates with legacy systems

14. Paraphrase the importance of quorum in a swarm cluster

To make our swarm cluster highly available, we must use multiple manager nodes. Swarm managers use a consensus algorithm to maintain consistent data about the swarm state across all nodes. This algorithm requires that a quorum be maintained for changes to be made to the cluster.

Quorum: The majority (more than half) of the manager nodes in our swarm. To achieve quorum, more than half of the total amount of nodes in our swarm must be available and communicate with the other available nodes. Remember if exactly half of our nodes are available, this does not count as a quorum. We must have more than half.

15. Demonstrate the usage of templates with "docker service create"

You can use templates for some flags of service create, using the syntax provided by the Go’s text/template package.

The supported flags are the following :

--hostname
--mount
--env

docker service create --name hosttempl \ --hostname="{{.Node.Hostname}}-{{.Node.ID}}-{{.Service.Name}}"\ busybox top

16. Manipulate a running stack of services