domingo, 30 de junio de 2019

Docker Swarm mode recostruyendo ambiente de contenedores, Testing failover



-- Reconfigurar el ambiente del swarm como en el lab anterior.
-- Probar el failover, tirando un worker que este ejecutando el servicio.

Reconfiguración


   En la previa sesión guardamos las detuvimos las máquinas virtuales y apagamos la máquina física. Continuando con el laboratorio. arrancamos la vm master, la cual automáticamente ejecuta nuestro visualizador y el servicio web de prueba. Estos los ejecuta en un solo contenedor, posteriormente arrancamos los 2 workers, pero la configuración de tareas continua en la sw-master.
   Para tener la tarea web en otro contenedor detenemos esta tarea y la volvemos a ejecutar, de esta manera se ejecuta en otro contenedor.
   Aquí la pregunta es si ubieramos arrancado primero los workers y luego el master para que los servicios se distribuyeran a lo largo de todos los workers sería posible?. Por lo que vemos al final de este lab la redistribución automatica al tener más máquinas virtuales no es efectuada. Algo tan preciado tal vez solo sea por medio de configuración.?

bext@bext-VPCF13WFX:~$ docker-machine start sw-master
Starting "sw-master"...
(sw-master) Check network to re-create if needed...
(sw-master) Found a new host-only adapter: "vboxnet0"
(sw-master) Waiting for an IP...
Machine "sw-master" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
bext@bext-VPCF13WFX:~$ docker-machine ls
NAME          ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
sw-master     -        virtualbox   Running   tcp://192.168.99.111:2376           v18.09.7   
sw-worker-1   -        virtualbox   Stopped                                       Unknown    
sw-worker-2   -        virtualbox   Stopped                                       Unknown    
bext@bext-VPCF13WFX:~$ docker-machine start sw-worker-1
Starting "sw-worker-1"...
(sw-worker-1) Check network to re-create if needed...
(sw-worker-1) Waiting for an IP...
Machine "sw-worker-1" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
bext@bext-VPCF13WFX:~$ docker-machine start sw-worker-2
Starting "sw-worker-2"...
(sw-worker-2) Check network to re-create if needed...
(sw-worker-2) Waiting for an IP...
Machine "sw-worker-2" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@sw-master:~$ docker swarm init --advertise-addr 192.168.99.111
Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave this swarm and join another one.
docker@sw-master:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7
docker@sw-master:~$ docker images ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker@sw-master:~$ exit
logout
bext@bext-VPCF13WFX:~$ docker images ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
bext@bext-VPCF13WFX:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
bext@bext-VPCF13WFX:~$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@sw-master:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                             PORTS
1k6akx8sh6yr        viz                 replicated          1/1                 dockersamples/visualizer:latest   *:8080->8080/tcp
h5mriknsbuvo        web                 replicated          1/1                 nginx:latest                      *:80->80/tcp
docker@sw-master:~$ curl http://192.168.99.111:8080
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Visualizer</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link href='//fonts.googleapis.com/css?family=Ubuntu+Mono|Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
  <style type="text/css">
   .hidden{ display: none; }
  </style>
</head>
<body style='background:#254356'>
  <div class='tabs'>
    <button id='tab-physical'>
      <svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 80 80"><path fill="#FFF" d="M14.752 32.456l-7.72.002v7.553h7.72v-7.554zm9.65 0h-7.72v7.556h7.72v-7.556zm0-9.445h-7.72v7.556h7.72V23.01zm9.65 9.446h-7.72v7.556h7.72v-7.556zm0-9.445h-7.72v7.556h7.72V23.01zm9.648 9.446h-7.72v7.556h7.72v-7.556zm0-9.445h-7.72v7.556h7.72V23.01zm9.65 9.446l-7.72.002v7.553h7.72v-7.554zm-9.65-18.89h-7.72v7.556h7.72v-7.556zm31.938 23.106c-2.51-1.417-5.85-1.61-8.693-.792-.35-2.958-2.337-5.55-4.7-7.41l-.938-.738-.79.89c-1.58 1.79-2.052 4.768-1.838 7.053.16 1.68.697 3.388 1.756 4.737-.805.473-1.717.85-2.53 1.12-1.657.55-3.456.854-5.206.854H3.544l-.105 1.107c-.354 3.7.165 7.402 1.728 10.778l.673 1.343.078.124c4.622 7.68 12.74 10.914 21.584 10.914 17.125 0 31.248-7.48 37.734-23.284 4.335.222 8.77-1.033 10.89-5.082l.54-1.033-1.028-.578zm-57.77 19.982v.002c-2.18 0-3.955-1.735-3.955-3.866 0-2.132 1.774-3.866 3.954-3.866s3.954 1.732 3.954 3.865c0 2.13-1.77 3.864-3.95 3.864zm-.01-5.854c-1.137 0-2.06.9-2.06 2.013 0 1.11.924 2.01 2.06 2.01 1.134 0 2.057-.9 2.057-2.01 0-1.11-.922-2.013-2.057-2.013z"/></svg>
    </button>

  </div>
  <div id="app">
    <!-- content goes here -->
  </div>

  <script type="text/javascript">
    window.MS = '1000';
  </script>
  <script type="text/javascript" src="app.js"></script>
</body>
</html>
docker@sw-master:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7
docker@sw-master:~$ docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS                   PORTS               NAMES
5378758ca05d        nginx:latest                      "nginx -g 'daemon of…"   7 minutes ago       Up 7 minutes             80/tcp              web.1.7pr8m576poedkkwoi7m1jnlh2
9098949ebfb7        dockersamples/visualizer:latest   "npm start"              8 minutes ago       Up 8 minutes (healthy)   8080/tcp            viz.1.fnp74zgxepf4hj9d15jtokb1x
docker@sw-master:~$ docker container ls
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS                   PORTS               NAMES
5378758ca05d        nginx:latest                      "nginx -g 'daemon of…"   7 minutes ago       Up 7 minutes             80/tcp              web.1.7pr8m576poedkkwoi7m1jnlh2
9098949ebfb7        dockersamples/visualizer:latest   "npm start"              9 minutes ago       Up 8 minutes (healthy)   8080/tcp            viz.1.fnp74zgxepf4hj9d15jtokb1x
docker@sw-master:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                             PORTS
1k6akx8sh6yr        viz                 replicated          1/1                 dockersamples/visualizer:latest   *:8080->8080/tcp
h5mriknsbuvo        web                 replicated          1/1                 nginx:latest                      *:80->80/tcp
docker@sw-master:~$ docker service scale web=2
web scaled to 2
overall progress: 2 out of 2 tasks 
1/2: running   
2/2: running   
verify: Service converged 
docker@sw-master:~$ docker service   

Usage: docker service COMMAND

Manage services

Commands:
  create      Create a new service
  inspect     Display detailed information on one or more services
  logs        Fetch the logs of a service or task
  ls          List services
  ps          List the tasks of one or more services
  rm          Remove one or more services
  rollback    Revert changes to a service's configuration
  scale       Scale one or multiple replicated services
  update      Update a service

Run 'docker service COMMAND --help' for more information on a command.
docker@sw-master:~$ docker service rm web
web
docker@sw-master:~$ docker service create --name=web --publish=80:80 nginx
vtuogblw02akurqjkeyw9oxz0
overall progress: 1 out of 1 tasks 
1/1: running   
verify: Service converged 
docker@sw-master:~$ 
docker@sw-master:~$ eval $(docker-machine env -u)
-bash: docker-machine: command not found
docker@sw-master:~$ exit
logout
bext@bext-VPCF13WFX:~$ eval $(docker-machine env -u)
bext@bext-VPCF13WFX:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
kdaljefl1ech729w83jrdmqr9 *   bext-VPCF13WFX      Ready               Active              Leader              18.09.6
bext@bext-VPCF13WFX:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
bext@bext-VPCF13WFX:~$ docker image ls
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
miapp80               latest              0c4a3d184820        3 days ago          131MB
<none>                <none>              2ff52a5267f4        3 days ago          131MB
<none>                <none>              fb93b11a258a        3 days ago          131MB
jalbertomr/lab1       miapp80             58c057288e10        3 days ago          131MB
python_app            latest              68e8339a3346        8 days ago          131MB
jalbertomr/lab1       python_app_1        68e8339a3346        8 days ago          131MB
redis                 <none>              3c41ce05add9        2 weeks ago         95MB
python                2.7-slim            ca96bab3e2aa        2 weeks ago         120MB
portainer/portainer   latest              da2759008147        3 weeks ago         75.4MB
hello-world           latest              fce289e99eb9        6 months ago        1.84kB
bext@bext-VPCF13WFX:~$ 
bext@bext-VPCF13WFX:~$ eval $(docker-machine env sw-master)
bext@bext-VPCF13WFX:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7
 
 

Test Failover


bext@bext-VPCF13WFX:~$ docker-machine stop sw-worker-1
Stopping "sw-worker-1"...
Machine "sw-worker-1" was stopped.

Detenemos la sw-worker-1, y vemos que el servicio web se traspasa automaticamente a sw-worker-2.



bext@bext-VPCF13WFX:~$ docker service scale web=2
web scaled to 2
overall progress: 2 out of 2 tasks 
1/2: running   
2/2: running   
verify: Service converged 


bext@bext-VPCF13WFX:~$ docker service scale web=3
web scaled to 3
overall progress: 3 out of 3 tasks 
1/3: running   
2/3: running   
3/3: running   
verify: Service converged 


Arrancamos sw-worker-1, vemos que el servicio web no se reacomoda en la maquina sw-worker-1.
bext@bext-VPCF13WFX:~$ docker-machine start sw-worker-1
Starting "sw-worker-1"...
(sw-worker-1) Check network to re-create if needed...
(sw-worker-1) Waiting for an IP...
Machine "sw-worker-1" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.



Vamos a estresarlo con un escalamiento a 7, a ver si se ocupa la sw-worker-1.





Pues observamos que no se redistribuyen en la máquina recien disponible.

eot

No hay comentarios:

Publicar un comentario