jueves, 11 de julio de 2019

Docker default Overlay Network


Docker default Overlay Network


Esta se inicializa automaincamente cuando se une al swarm. no es la mejor recomendación para ambientes productivos.

 Necesitamos tres máquinas virtuales corriendo para nuestro lab. En este caso solo las iniciamos.

bext@bext-VPCF13WFX:~$ docker-machine start sw-master
Starting "sw-master"...
(sw-master) Check network to re-create if needed...
(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 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.

Podemos ver que ya están en un swarm, ya que previamente se había hecho en la sw-master.

bext@bext-VPCF13WFX:~$ docker-machine ssh 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

Podemos tambien utilizar filtros para la consulta

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker node ls --filter role=manager"
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pdlp62hc1wqzo5wuubp5ailmx *   sw-master           Ready               Active              Leader              18.09.7
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker node ls --filter role=worker"
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
qfc9sx1tfe3wms1oera75f80b     sw-worker-1         Ready               Active                                  18.09.7
v28filrne0x5fua7r7rxh6zew     sw-worker-2         Ready               Active                                  18.09.7

Observamos que en cada máquina virtual tenemos una red ingress y docker_gwbridge.

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network ls"
NETWORK ID          NAME                DRIVER              SCOPE
d0969728609c        bridge              bridge              local
e10bcfbc49e7        docker_gwbridge     bridge              local
ba76f35aaae8        host                host                local
bgrfj46a3bnj        ingress             overlay             swarm
5ccedc5bdaaa        none                null                local
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-1 "docker network ls"
NETWORK ID          NAME                DRIVER              SCOPE
4e903eb0a568        bridge              bridge              local
61b8ad976bcd        docker_gwbridge     bridge              local
799aeb373e24        host                host                local
bgrfj46a3bnj        ingress             overlay             swarm
10abe5257131        none                null                local
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "docker network ls"
NETWORK ID          NAME                DRIVER              SCOPE
af4f3b6501b1        bridge              bridge              local
a1769ec2c4fe        docker_gwbridge     bridge              local
cdd3640844df        host                host                local
bgrfj46a3bnj        ingress             overlay             swarm
53798965249b        none                null                local

Inspeccionamos en cada VM la docker_gwbridge

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "docker network inspect docker_gwbridge" | more
[
    {
        "Name": "docker_gwbridge",
        "Id": "a1769ec2c4fefebfe58b837e0273aaecbce29ecf014d36b3ac72ca08bb605c06"
,
        "Created": "2019-06-30T01:51:17.348572773Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ingress-sbox": {
                "Name": "gateway_ingress-sbox",
                "EndpointID": "df198221f225307ce18fc0867b1b4a6c80855dcd62541c1dc
c059caa45cc2830",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.enable_icc": "false",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.name": "docker_gwbridge"
        },
        "Labels": {}
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-1 "docker network inspect docker_gwbridge" | more
[
    {
        "Name": "docker_gwbridge",
        "Id": "61b8ad976bcd635f2a05f6d52f2ad82180986fd6702bf34a9e48894b42bf3123"
,
        "Created": "2019-06-30T01:50:57.332950018Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ingress-sbox": {
                "Name": "gateway_ingress-sbox",
                "EndpointID": "87df0aa9d75316e034871d8cb69dc1939a4846b46768c0532
34e50c548c91025",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.enable_icc": "false",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.name": "docker_gwbridge"
        },
        "Labels": {}
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network inspect docker_gwbridge" | more
[
    {
        "Name": "docker_gwbridge",
        "Id": "e10bcfbc49e7b6188dee88ad78b4110eb1a54d2ff026678b8136b190fa313439"
,
        "Created": "2019-06-30T01:38:56.481913662Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ingress-sbox": {
                "Name": "gateway_ingress-sbox",
                "EndpointID": "1fcf5f318eb8a8bf717fcb7ee59c7aa151e3da6195dc7d651
da0dce3c6efb477",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.enable_icc": "false",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.name": "docker_gwbridge"
        },
        "Labels": {}
    }
]

Inspectionamos en cada vm la red bridge

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network inspect bridge" | more
[
    {
        "Name": "bridge",
        "Id": "d0969728609c7c69f495f0118a9badd15826fc9f41485d703d150e13e895d577"
,
        "Created": "2019-07-11T22:13:09.653991377Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-1 "docker network inspect bridge" | more
[
    {
        "Name": "bridge",
        "Id": "4e903eb0a56896e8f83dc304ff2ddffb72dd5777e99b34f8f9a03c9a1cdfbb90"
,
        "Created": "2019-07-11T22:14:04.417429514Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "docker network inspect bridge" | more
[
    {
        "Name": "bridge",
        "Id": "af4f3b6501b1a5e07cd5ab63cc3589a0f6e2310f7bad9d5bdf1aed43b0d9a565"
,
        "Created": "2019-07-11T22:14:55.532328299Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

Inspectionamos la red ingress de las vm.

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network inspect ingress" | more
[
    {
        "Name": "ingress",
        "Id": "bgrfj46a3bnjds7sjdtol377m",
        "Created": "2019-07-11T22:13:16.781313189Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.255.0.0/16",
                    "Gateway": "10.255.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": true,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ingress-sbox": {
                "Name": "ingress-endpoint",
                "EndpointID": "7e165f39593c235f84be16f8526c9ff4f15b84f714248cc10
ba3fa4b63de3243",
                "MacAddress": "02:42:0a:ff:00:02",
                "IPv4Address": "10.255.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4096"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "1c465485879a",
                "IP": "192.168.99.111"
            },
            {
                "Name": "b35470693cbd",
                "IP": "192.168.99.112"
            },
            {
                "Name": "63b46cb9e553",
                "IP": "192.168.99.113"
            }
        ]
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-1 "docker network inspect ingress" | more
[
    {
        "Name": "ingress",
        "Id": "bgrfj46a3bnjds7sjdtol377m",
        "Created": "2019-07-11T22:14:05.452543462Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.255.0.0/16",
                    "Gateway": "10.255.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": true,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ingress-sbox": {
                "Name": "ingress-endpoint",
                "EndpointID": "62cc78320dd7950133c78e962a8cd7803cbbf547b2dc57507
8f765219a2610dc",
                "MacAddress": "02:42:0a:ff:00:03",
                "IPv4Address": "10.255.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4096"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "1c465485879a",
                "IP": "192.168.99.111"
            },
            {
                "Name": "b35470693cbd",
                "IP": "192.168.99.112"
            },
            {
                "Name": "63b46cb9e553",
                "IP": "192.168.99.113"
            }
        ]
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "docker network inspect ingress" | more
[
    {
        "Name": "ingress",
        "Id": "bgrfj46a3bnjds7sjdtol377m",
        "Created": "2019-07-11T22:14:56.136794067Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.255.0.0/16",
                    "Gateway": "10.255.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": true,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ingress-sbox": {
                "Name": "ingress-endpoint",
                "EndpointID": "1df78f9918848c2de04e2579f8cb3d2b9cbc43c31a830b22e
c3f98092a9d1a1c",
                "MacAddress": "02:42:0a:ff:00:04",
                "IPv4Address": "10.255.0.4/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4096"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "1c465485879a",
                "IP": "192.168.99.111"
            },
            {
                "Name": "b35470693cbd",
                "IP": "192.168.99.112"
            },
            {
                "Name": "63b46cb9e553",
                "IP": "192.168.99.113"
            }
        ]
    }
]

En el Manager creamos una red overlay nginx-net

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network create -d overlay nginx-net"

No es necesario crea esta en las otras VM, se hace automáticamente.

Preparamos
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
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:~$ eval $(docker-machine env sw-master)

Creamos un servicion en el Master, con 5 replicas conectados a la red que creamos nginx-net, los contenedores se pueden comunicar entre ellos.

bext@bext-VPCF13WFX:~$ docker service create --name my-nginx \
> --publish target=80,published=80 \
> --replicas=5 \
> --network nginx-net nginx
nloib6ybck3k2ra0qradan3vc
overall progress: 5 out of 5 tasks 
1/5: running   
2/5: running   
3/5: running   
4/5: running   
5/5: running   
verify: Service converged 



bext@bext-VPCF13WFX:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
nloib6ybck3k        my-nginx            replicated          5/5                 nginx:latest        *:80->80/tcp

Indagamos sobre la red

bext@bext-VPCF13WFX:~$ eval $(docker-machine env -u)
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network inspect nginx-net" | more
[
    {
        "Name": "nginx-net",
        "Id": "boynjdp1eb95entflnjdzpg6q",
        "Created": "2019-07-11T22:51:56.433303833Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "6e215809cc79c99303384ad2a95199d4389165040e823ec62d1e8acb4c71ac62": 
{
                "Name": "my-nginx.5.ku8667pxsvfuwgmols8t3teo1",
                "EndpointID": "99b8330c988ef22f869dc8fd207674400fc33d73394ac328b
ddc84762c3c02f3",
                "MacAddress": "02:42:0a:00:00:04",
                "IPv4Address": "10.0.0.4/24",
                "IPv6Address": ""
            },
            "700b82f3979c2b16e41f6ac60494b71bec51b0d872b5681832e69d45f9d6d3cc": 
{
                "Name": "my-nginx.3.hxuyizku9zl9jnxm5p3xrbbjr",
                "EndpointID": "f0a498864b7999ce0f98d4f2964d8ecc270d75de2195fe5f9
bdb44b925c57ae4",
                "MacAddress": "02:42:0a:00:00:07",
                "IPv4Address": "10.0.0.7/24",
                "IPv6Address": ""
            },
            "lb-nginx-net": {
                "Name": "nginx-net-endpoint",
                "EndpointID": "35c8a4bdc15284e42f4d8ab5423c7f544615d4ef4b34b0f26
7cb5a4ec98b6a78",
                "MacAddress": "02:42:0a:00:00:08",
                "IPv4Address": "10.0.0.8/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "b35470693cbd",
                "IP": "192.168.99.112"
            },
            {
                "Name": "1c465485879a",
                "IP": "192.168.99.111"
            },
            {
                "Name": "63b46cb9e553",
                "IP": "192.168.99.113"
            }
        ]
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-1 "docker network inspect nginx-net" | more
[
    {
        "Name": "nginx-net",
        "Id": "boynjdp1eb95entflnjdzpg6q",
        "Created": "2019-07-11T22:51:56.439267319Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "d7c9626cc55b6dd14e4476d92de674fa72d9a5c040810937e0ab90b3e7cf325b": 
{
                "Name": "my-nginx.1.szmh2cyygasjzlzhq973z1116",
                "EndpointID": "e44c6056368a784c3b35988a51073edc7b852d4e8fa3b0204
b9dccb33952d10d",
                "MacAddress": "02:42:0a:00:00:05",
                "IPv4Address": "10.0.0.5/24",
                "IPv6Address": ""
            },
            "lb-nginx-net": {
                "Name": "nginx-net-endpoint",
                "EndpointID": "d1890993c02d954751e1c55d14f49e6f967a6facc0cce1a87
d0e236b723e6098",
                "MacAddress": "02:42:0a:00:00:0a",
                "IPv4Address": "10.0.0.10/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "b35470693cbd",
                "IP": "192.168.99.112"
            },
            {
                "Name": "63b46cb9e553",
                "IP": "192.168.99.113"
            },
            {
                "Name": "1c465485879a",
                "IP": "192.168.99.111"
            }
        ]
    }
]
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "docker network inspect nginx-net" | more
[
    {
        "Name": "nginx-net",
        "Id": "boynjdp1eb95entflnjdzpg6q",
        "Created": "2019-07-11T22:51:56.444244814Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "6518e9092a1f8c804020ea9e778e46cbd7519a8181a872f824a2526347f206e5": 
{
                "Name": "my-nginx.4.8l5i49h6q091cp76mck3134ez",
                "EndpointID": "eb5c4d2f6fcd3310135a47bda16ca53b0c09af6b60e215f64
1b6aafa8a6cfbcb",
                "MacAddress": "02:42:0a:00:00:03",
                "IPv4Address": "10.0.0.3/24",
                "IPv6Address": ""
            },
            "6ada69a4f00985fa6bd37d0793d4b3cead6324ab3dde8a7eb99e73bf4d077fec": 
{
                "Name": "my-nginx.2.wwhuu2b20n6cjb53nmtx4srft",
                "EndpointID": "b35f219350dc8f526be10f69e0db40b29ce15488a368824ec
d538abedf0ab9e4",
                "MacAddress": "02:42:0a:00:00:06",
                "IPv4Address": "10.0.0.6/24",
                "IPv6Address": ""
            },
            "lb-nginx-net": {
                "Name": "nginx-net-endpoint",
                "EndpointID": "266ab7c3f40e7d7d260892c03b6410ac0d246f5f59a6a30b1
3ccc44cb005a48e",
                "MacAddress": "02:42:0a:00:00:09",
                "IPv4Address": "10.0.0.9/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "63b46cb9e553",
                "IP": "192.168.99.113"
            },
            {
                "Name": "b35470693cbd",
                "IP": "192.168.99.112"
            },
            {
                "Name": "1c465485879a",
                "IP": "192.168.99.111"
            }
        ]
    }
]

Observamos que los contenedores workers estan en la red que creamos para master, aún cuando no lo atachamos a los workers.

Creamos una nueva red llamada nginx-net-2 y actualizamos nuestro servicio my-nginx hacia esta red. Esperamos que los contenedores se desconecten de la red donde estaban nginx-net.

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network create -d overlay nginx-net-2"
4fsin50c2xxfydo1mfaa638rr
bext@bext-VPCF13WFX:~$ eval $(docker-machine env sw-master)
bext@bext-VPCF13WFX:~$ docker service update \
> --network-add nginx-net-2 \
> --network-rm nginx-net \
> my-nginx
my-nginx
overall progress: 5 out of 5 tasks 
1/5: running   
2/5: running   
3/5: running   
4/5: running   
5/5: running   
verify: Service converged 

Inspeccionamos la red nginx-net la cual desatachamos del servicio.

bext@bext-VPCF13WFX:~$ docker network inspect nginx-net
[
    {
        "Name": "nginx-net",
        "Id": "boynjdp1eb95entflnjdzpg6q",
        "Created": "2019-07-11T22:40:26.206767548Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": null,
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": null
    }
]

Vemos que ya no tiene contenedores.

Indagamos las VM
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "ip addr"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:51:11:41 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe51:1141/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:a0:4e:a5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.111/24 brd 192.168.99.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fea0:4ea5/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:4f:fd:24:0e brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
6: docker_gwbridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:a3:b4:32:2f brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker_gwbridge
       valid_lft forever preferred_lft forever
    inet6 fe80::42:a3ff:feb4:322f/64 scope link 
       valid_lft forever preferred_lft forever
12: vethdb0b746@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether ae:13:26:13:97:06 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::ac13:26ff:fe13:9706/64 scope link 
       valid_lft forever preferred_lft forever
34: veth64ad9e4@if33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether c2:8f:5e:1d:93:e4 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::c08f:5eff:fe1d:93e4/64 scope link 
       valid_lft forever preferred_lft forever  

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-1 "ip addr"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:1e:84:4f brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe1e:844f/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:12:2d:c9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.112/24 brd 192.168.99.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe12:2dc9/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: docker_gwbridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:83:50:49:0f brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker_gwbridge
       valid_lft forever preferred_lft forever
    inet6 fe80::42:83ff:fe50:490f/64 scope link 
       valid_lft forever preferred_lft forever
6: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:6d:6c:1f:ed brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
12: vethe232b63@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether 56:53:f2:73:d9:53 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::5453:f2ff:fe73:d953/64 scope link 
       valid_lft forever preferred_lft forever
28: vethee76071@if27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether 22:b6:4e:a1:15:e2 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20b6:4eff:fea1:15e2/64 scope link 
       valid_lft forever preferred_lft forever
34: veth589c525@if33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether aa:fa:04:be:8f:f7 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a8fa:4ff:febe:8ff7/64 scope link 
       valid_lft forever preferred_lft forever

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "ip addr"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:8f:ca:12 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe8f:ca12/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:90:a8:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.113/24 brd 192.168.99.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe90:a854/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:b5:35:cb:95 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
6: docker_gwbridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:a5:0c:84:51 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker_gwbridge
       valid_lft forever preferred_lft forever
    inet6 fe80::42:a5ff:fe0c:8451/64 scope link 
       valid_lft forever preferred_lft forever
12: veth7860279@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether ba:a7:db:0f:f0:6f brd ff:ff:ff:ff:ff:ff
    inet6 fe80::b8a7:dbff:fe0f:f06f/64 scope link 
       valid_lft forever preferred_lft forever
34: veth2da7f7c@if33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether ce:91:10:b8:cc:fe brd ff:ff:ff:ff:ff:ff
    inet6 fe80::cc91:10ff:feb8:ccfe/64 scope link 
       valid_lft forever preferred_lft forever
40: veth7cad079@if39: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker_gwbridge state UP group default 
    link/ether b2:c9:e0:6f:62:d4 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::b0c9:e0ff:fe6f:62d4/64 scope link 
       valid_lft forever preferred_lft forever

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-worker-2 "docker network ls"
NETWORK ID          NAME                DRIVER              SCOPE
af4f3b6501b1        bridge              bridge              local
a1769ec2c4fe        docker_gwbridge     bridge              local
cdd3640844df        host                host                local
bgrfj46a3bnj        ingress             overlay             swarm
4fsin50c2xxf        nginx-net-2         overlay             swarm
53798965249b        none                null                local

Ahora solo queda quitar el servicio y las redes.

bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker service rm my-nginx" 
my-nginx
bext@bext-VPCF13WFX:~$ docker-machine ssh sw-master "docker network rm nginx-net nginx-net-2"
nginx-net
nginx-net-2


eot

No hay comentarios:

Publicar un comentario