You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
14 Hrs
55 Min
22 Seg
Curso de Swarm

Curso de Swarm

Guido Vilariño

Guido Vilariño

Docker Swarm multinodo

11/24
Resources

How can we create a multi-node Swarm with Docker?

Deploying a multi-node Swarm in Docker is an eye-opening experience that allows us to manage nodes efficiently. Initializing a Swarm requires configuring our Swarm Manager, which acts as a central coordinator of operations.

What steps should we follow to initialize a Swarm Manager?

  1. Initialize the Swarm: First, we use the docker swarm init command. This command configures the current machine as the primary manager node. However, in an environment with multiple interfaces, it is important to specify which IP address to listen on, because the system might have multiple networks connected.

  2. Configure the listening address: To resolve this, we run the command docker swarm init --advertise-addr [IP_ADDRESS], replacing [IP_ADDRESS] with the IP of the interface to be used. For example:

    docker swarm init --advertise-addr 192.168.0.33

How to join other nodes to the Swarm?

Once the Swarm Manager is configured, we can add other nodes to the Swarm. To do this, each node must execute the Join Token on their systems:

  1. Obtain the Join Token: After creating the Swarm, the initial command provides a token that other nodes need to join the Swarm as workers.

  2. Join the Swarm: For each new node, run the provided command, similar to:

    docker swarm join --token SWMTKN-1-61ykxgntbp2j4c0epce2fywz3z7z7g567ctdqkhdbnh4ayngoballc8s9mr2zisd192c7wv 192.168.0.33:2377

How can we check the Swarm status?

The status of the Swarm and who is in it is crucial. As we saw:

  • View the status of the nodes: only from the Manager you can check the organization of the nodes with:
    docker node ls
    .

The command shows important information such as which node is acting as leader and identifies which one we are currently working on, pointing them as Manager or Worker.

How to run a service in a multi-node Swarm?

A Swarm is not only for managing machines, but for running distributed applications. Let's see how:

  1. Create a service: subsidiary to the concept of containers, Docker services allow to replicate and move along the available nodes. For example, to create a simple service that pings Google, we use:

    docker service create --name pinger alpine ping www.google.com
  2. Check where the services are running: We want to know on which node the service is running, and for that we run:

    docker service ps pinger

What else can we learn about Swarm management?

Swarm management gives us a powerful tool to scale and manage applications. It is important that we eventually learn to:

  • Configure constraints, specifying on which nodes we want certain applications to run.
  • Evaluate replication and load distribution policies for efficiency and redundancy.

As you continue to immerse yourself in the world of Docker management, exciting and more complex capabilities await, promising continued technical learning. Keep exploring!

Contributions 17

Questions 7

Sort by:

Want to see more contributions, questions and answers from the community?

Para copiar y pegar en play with docker pueden utilizar

control + insert //Copiar
shift  + insert //Pegar

Genial, también fue sencillo desde virtualbox…

Hola! estoy intentado unir una maquina a docker swarm pero me da un error. Con maquinas de DO.

docker swarm join --token SWMTKN-1-2l43xegaq2gchqr2e…. ip:2377
Error response from daemon: Timeout was reached before node joined. The attempt to join the swarm will continue in the background. Use the "docker info" command to see the current swarm status of your node.

He estado mirando y es porque entre maquinas deben tener unos puertos abiertos. https://docs.docker.com/engine/swarm/swarm-tutorial/#open-protocols-and-ports-between-the-hosts
Como puedo habilitar estos puertos?

– Creamos el nodo manager

docker swarm init --advertise-addr <MANAGER-IP>
docker swarm init --advertise-addr 192.168.0.18

– Creamos una nueva instancia en play-with-docker (+ ADD NEW INSTANCE)

docker swarm join --token <TOKEN> <MANAGER-IP>:<PORT>
docker swarm join --token SWMTKN-1-32cege8duoof9cr405bi1fsmcga831l6fcecmznp5cxcfdc3vg-ci6f98tjfy9fzhr2swmmo3ter 192.168.0.18:2377

– Creamos otra nueva instancia en play-with-docker (+ ADD NEW INSTANCE)

docker swarm join --token <TOKEN> <MANAGER-IP>:<PORT>
docker swarm join --token SWMTKN-1-32cege8duoof9cr405bi1fsmcga831l6fcecmznp5cxcfdc3vg-ci6f98tjfy9fzhr2swmmo3ter 192.168.0.18:2377

– Nos dirigimos a la terminal del nodo MANAGER, observamos los 3 nodos

docker node ls

– Crear un servicio en este caso multinodo

docker service create --name pinger alpine ping www.google.com

– Ver listado de servicios

docker service ls

– Donde estan asignado las tareas de este servicio, nos indica que esta en el nodo 1

docker service ps pinger

– Podemos ver el container

docker ps

// iniciar docker swarm
docker swarm init
// iniciar docker swarm en caso de tener mas de una interfaz de red
docker swarm init --advertise-addr [“ip de la interfaz donde va a escuchar peticiones para unirse al swarm”]
// ver nodos del swarm *solo se puede visualizar desde un docker swarm manager
// Todo lo relativo al estado del swarm, a la administracion del swarm y todo lo que tiene que ver con el swarm en si lo van a manejar exclusivamente los managers
docker node ls

  • docker swarm init --advertise-addr IP, para iniciar docker swarm con ip en específico
  • docker swarm join --token TOKEN server:puerto, para unir un nodo como worker al server con puerto 2377
  • docker node ls, para ver los nodos swarm de docker.

Las instancias que agregas desde playwithdocker, en un esquema de productividad son maquina físicas?

Pueden mandar la salida del comando a un archivo txt para copiarlo desde ahi, y luego pegarlo en las otras terminales:
$ comando > archivo.txt
luego entran a “editor” y ahi encuentran el archivo.

Play to docker , a jugar para comprender la arquitectura multinodo.

Por defecto las tareas son asignadas a cualquier nodo del swarm, para que no pase esto, hay que especificar en que nodos debe de correr el servicio.

Los nodos manager son los únicos que pueden hacer tareas relacionadas con el estado y la administración de swarm. Ésto por seguridad.

Muy interesante

docker service create --name pinger alpine ping www.google.com
docker service ps pinger

un comando simple y tienes tu servicio corriendo, muy buena herramienta.

Para los que tuvieron un error al ejecutar docker service ps pinger y no hacía ping a google traten de hacerlo a 8.8.8.8 que es la ip de google. `docker service create --name pinger alpine ping 8.8.8.8`

Hola a todos.
Si luego de hacer:

$ docker swarm init --advertise-addr [IP]

se les pierde el token para unir el manager con los workers, pueden ver nuevamente el comando con esta linea:

$ docker swarm join-token worker

Saludos.

Para los que tengan problemas con los comandos de copiar/pegar investige un poco y serian los siguientes:

Copiar: Ctrl + Insert o Ctrl + FN + Insert
Pegar: Ctrl + Shift + v

Que bien el play-with-docker ya yo tenia 4 vm con fedora en VMware para kubernetes local, pero con esto los puedo dejar dormidos, lo siento, no tengo soporte para acentos muy vago para buscarlo en fedora.