38e55757ca28dbf1caf48fef10c0f6d51fe90b47
docker/swarm.rst
... | ... | @@ -1,120 +0,0 @@ |
1 | -===== |
|
2 | -Swarm |
|
3 | -===== |
|
4 | ---------------------------- |
|
5 | -Instalación y configuración |
|
6 | ---------------------------- |
|
7 | - |
|
8 | -Describimos como instalar swarm y jugar con él un poco. |
|
9 | - |
|
10 | -Pre-requisitos |
|
11 | -============== |
|
12 | - |
|
13 | -Sistema Operativo |
|
14 | ------------------ |
|
15 | - |
|
16 | -* Instalación mínima de Fedora 25 |
|
17 | -* Red pública para el controlador (ens3) |
|
18 | -* Red privada para los nodos (ens4) |
|
19 | - |
|
20 | -Firewall |
|
21 | --------- |
|
22 | -El firewall debe modificarse para permitir acceso de/a swarm por la interfaz de red privada. Solo abriremos los puertos necesarios. |
|
23 | - |
|
24 | -.. code:: bash |
|
25 | - |
|
26 | - # configurar zona |
|
27 | - firewall-cmd --permanent --zone=work --add-port=2377/tcp --add-port=7946/tcp --add-port=7946/udp --add-port=4789/udp |
|
28 | - |
|
29 | - # modificar la zona de ens4 |
|
30 | - nmcli connection modify ens4 connection.zone work |
|
31 | - |
|
32 | - # activar |
|
33 | - firewall-cmd --full-reload |
|
34 | - nmcli connection reload ens4 |
|
35 | - |
|
36 | - # verificar |
|
37 | - nmcli connection show ens4 |
|
38 | - |
|
39 | - firewall-cmd --list-all |
|
40 | - firewall-cmd --list-all --zone=work |
|
41 | - |
|
42 | - |
|
43 | -Instalación |
|
44 | -=========== |
|
45 | -Instalaremos la versión más reciente en los repositorios de Fedora. |
|
46 | - |
|
47 | -.. code:: bash |
|
48 | - |
|
49 | - # instalar |
|
50 | - dnf -y install docker-latest |
|
51 | - |
|
52 | - # activar |
|
53 | - systemctl enable docker-latest |
|
54 | - systemctl start docker-latest |
|
55 | - |
|
56 | - |
|
57 | -Configuración |
|
58 | -============= |
|
59 | -Debemos iniciar un swarm y unir los nodos a él. |
|
60 | - |
|
61 | -.. code:: bash |
|
62 | - |
|
63 | - # crear un swarm (manager) |
|
64 | - docker swarm init --advertise-addr 192.168.77.1 |
|
65 | - |
|
66 | - # agregar nodos (nodos) |
|
67 | - # ejecutar ésto en nodos swarm2 y swarm3 |
|
68 | - docker swarm join --token <token-generado> 192.168.77.1:2377 |
|
69 | - |
|
70 | - # verificar (manager) |
|
71 | - docker info |
|
72 | - docker node ls |
|
73 | - |
|
74 | - |
|
75 | -Despliegue |
|
76 | -========== |
|
77 | -Veremos como desplegar algunas aplicaciones, usando ejemplos simplificados. |
|
78 | - |
|
79 | -.. code:: bash |
|
80 | - |
|
81 | - # crear un servicio con 1 réplica |
|
82 | - docker service create --replicas 1 --name helloworld alpine ping docker.com |
|
83 | - docker service ls |
|
84 | - docker service rm helloworld |
|
85 | - |
|
86 | - |
|
87 | - # crear un servicio con 3 réplicas |
|
88 | - docker service create --replicas 3 --name helloworld alpine ping docker.com |
|
89 | - docker service ls |
|
90 | - |
|
91 | - |
|
92 | - # inspeccionar el servicio |
|
93 | - docker service inspect --pretty helloworld |
|
94 | - |
|
95 | - |
|
96 | - # escalar |
|
97 | - ## abajo |
|
98 | - docker service scale helloworld=1 |
|
99 | - docker service inspect --pretty helloworld |
|
100 | - |
|
101 | - ## arriba |
|
102 | - docker service scale helloworld=5 |
|
103 | - docker service inspect --pretty helloworld |
|
104 | - docker service rm helloworld |
|
105 | - |
|
106 | - |
|
107 | - # exponer servicios |
|
108 | - docker service create --name my-web --publish 8080:80 --replicas 3 nginx |
|
109 | - docker service ls |
|
110 | - docker ps |
|
111 | - |
|
112 | - ## probar |
|
113 | - curl localhost:8080 |
|
114 | - curl 192.168.77.1:8080 |
|
115 | - curl 104.36.16.224:8080 |
|
116 | - |
|
117 | - |
|
118 | -Referencias |
|
119 | -=========== |
|
120 | -* https://docs.docker.com/engine/swarm/swarm-tutorial/ |