3 Steps to Set up Service Discovery / Consul

Create a host for running key/value store, Consul

          1. $ docker-machine create -d digitalocean consul

-d = --driver = provider (do, AWS, virtualbox)

consul - name we give this docker-machine

This machine is NOT part of the Swarm

Rather, consul service is used by Swarm to bootstrap and communicate shared state of cluster across nodes

Before a Consul cluster can begin to service requests, a server node must be elected leader (in image below, this is the consul node in the load balancer). Thus, the first nodes that are started are generally the server nodes. Bootstrapping is the process of joining these initial server nodes into a cluster.

          1. Look at the network configuration of consul server

$ docker-machine ssh consul ifconfig

$ docker-machine ssh → run command on a docker-machine that uses ssh

Docker0 - bridge network for container

eth0 - public network interface. Allows inbound/outbound to entire internet

eth1 - private network interface. Keeps our information private. NOT accessible over internet. Only hosts in the same data center (digital ocean in this case) can communicate.

We use eth1 since private interface. If use eth0, expose key/value store to entire internet

          1. Pinging eth0 (public) & eth1(private) from w/in consul docker-machine

$(docker-machine ssh consul 'ifconfig eth0 | grep "inet addr:" | cut -d: -f2 | cut -d" " -f1')

Ping results in 2 way packet traffic

$(docker-machine ssh consul 'ifconfig eth1 | grep "inet addr:" | cut -d: -f2 | cut -d" " -f1')

Ping results in NO return packet

Use -c flag to limit # of pings

$ ping 0 -c 2 //0=localhost

Returns stats

TTL = # of routers packet passed through. Higher # = fewer routers

          1. Use ehth1 from step above for consul’s private network

Set eth1’s ip to an env variable so don’t have to retype it

Code below, simply returns an ip address. Example 10.132.70.113

$ export KV_IP=$(docker-machine ssh consul 'ifconfig eth1 | grep "inet addr:" | cut -d: -f2 | cut -d" " -f1')

Connect docker client to docker server consul

          1. $ eval $(docker-machine env consul)

From the docker-machine named “consul”, Create consul container from image on DockerHub.

          1. Creates consul’s key/value store/service

$ docker run -d -p ${KV_IP}:8500:8500 -h consul --restart always gliderlabs/consul-server -bootstrap

-p ${KV_IP}:8500:8500 → eth1 private network

-p takes an optional parameter that specifies network interface that container’s external port should be mapped to. KV_IP is env var for priv network (in our case, it is 0.132.70.113)

--restart always → restart if container crashes

gliderlabs/consul-server → Docker Hub image

-bootstrap

Before a Consul cluster can begin to service requests, a server node must be elected leader (in image below, this is the consul node in the load balancer). Thus, the first nodes that are started are generally the server nodes. Bootstrapping is the process of joining these initial server nodes into a cluster.

results matching ""

    No results matching ""