Deploying the Microservice in a Container

We will first run our dummy microservice container on one of the hosts:

$docker run -d --name service1 -P yadavsms/python-micro-service

Lets see what happened in our Registrator container on the same host:

$docker logs 5ad2c811770b
2016/05/13 14:35:15 Starting registrator v7 ...
2016/05/13 14:35:15 Using consul adapter: consul://172.16.20.132:8500
2016/05/13 14:35:15 Connecting to backend (0/0)
2016/05/13 14:35:15 consul: current leader  172.16.20.132:8300
2016/05/13 14:35:15 Listening for Docker events ...
2016/05/13 14:35:15 Syncing services on 2 containers
2016/05/13 14:35:15 ignored: 5ad2c811770b no published ports
2016/05/13 15:32:46 added: c09f762d3283 registrator:service1:5000
2016/05/13 15:43:48 added: d628843108c9 registrator:service2:5000

Registrator saw that a new container (service1) was started, exposing port 5000 and it automatically registered it with our Consul cluster. We’ll query our cluster now to see if the service was added there:

$curl $HOST_IP:8500/v1/catalog/services | python -mjson.tool
{
    "consul": [],
    "consul-53": [
        "udp"
    ],
    "consul-8300": [],
    "consul-8301": [
        "udp"
    ],
    "consul-8302": [
        "udp"
    ],
    "consul-8400": [],
    "consul-8500": [],
    "python-micro-service": []
}

Let's do the same for Node2 also.

Whenever we have a Consul cluster running we can query any node (client or server) and the response should always be the same. Since we are running our microservice containers in Node1 and Node2, let's query Consul on Node3:

$curl $HOST_IP:8500/v1/catalog/service/python-micro-service | python -mjson.tool
    {
        "Address": "172.16.20.94",
        "Node": "node3",
        "ServiceAddress": "",
        "ServiceID": "registrator:service2:5000",
        "ServiceName": "python-micro-service",
        "ServicePort": 32768,
        "ServiceTags": null
    },
    {
        "Address": "172.16.20.132",
        "Node": "node1",
        "ServiceAddress": "",
        "ServiceID": "registrator:service2:5000",
        "ServiceName": "python-micro-service",
        "ServicePort": 32770,
        "ServiceTags": null
    },
    {
        "Address": "172.16.20.184",
        "Node": "node2",
        "ServiceAddress": "",
        "ServiceID": "registrator:service2:5000",
        "ServiceName": "python-micro-service",
        "ServicePort": 32769,
        "ServiceTags": null
    }

results matching ""

    No results matching ""