{"id":46234,"date":"2017-03-06T10:18:47","date_gmt":"2017-03-06T04:48:47","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=46234"},"modified":"2017-03-06T10:18:47","modified_gmt":"2017-03-06T04:48:47","slug":"how-to-setup-consul-multinode-cluster-with-docker","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-setup-consul-multinode-cluster-with-docker\/","title":{"rendered":"How to Setup Consul Multinode Cluster with Docker?"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46268\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul-logo.png\" alt=\"consul-logo\" width=\"947\" height=\"274\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul-logo.png 947w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul-logo-300x86.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul-logo-624x180.png 624w\" sizes=\"(max-width: 947px) 100vw, 947px\" \/><\/p>\n<p>Consul is a service discovery and a configuration system tool used to discover the services running on multiple nodes. It is both distributed and highly available. It provides a powerful interface to get a better picture of <a title=\"DevOps as a service\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">infrastructure and services<\/a> running on them. Consul gives us a variety of features that help to determine our infrastructure in a better way such as service and node discovery mechanism, health check, tagging system, system-wide key\/value storage, consensus-based election routines and so on.<\/p>\n<p style=\"text-align: justify\">In this blog, we showcase how to create a three-server cluster. We run the Consul master in <a title=\"Docker DevOps\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\">docker containers<\/a> and therefore we have it installed in all the three nodes.<\/p>\n<p style=\"text-align: justify\">Let us first set up a consul container on consul-node1 with a &#8211;bootstrap-expect flag. The number associated with this flag will be the number of nodes required to start bootstrapping. If you give this flag in all the nodes either of it will start the bootstrap process. Alternatively, node that is assigned the flag will start in particular.<\/p>\n<p>[js]<br \/>\ndocker run -d -h consul-node1 -v \/mnt:\/data \\<br \/>\n    -p 192.168.33.60:8300:8300 \\<br \/>\n    -p 192.168.33.60:8301:8301 \\<br \/>\n    -p 192.168.33.60:8301:8301\/udp \\<br \/>\n    -p 192.168.33.60:8302:8302 \\<br \/>\n    -p 192.168.33.60:8302:8302\/udp \\<br \/>\n    -p 192.168.33.60:8400:8400 \\<br \/>\n    -p 192.168.33.60:8500:8500 \\<br \/>\n    -p 172.17.0.1:53:53\/udp \\<br \/>\n    progrium\/consul -server -advertise 192.168.33.60 -bootstrap-expect 3<br \/>\n[\/js]<\/p>\n<p style=\"text-align: justify\">In this command, 192.168.33.60 is the machine IP while\u00a0172.17.0.1 is the docker0 interface IP. When we see the logs of the container it shows:<\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46240\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul1.png\" alt=\"consul1\" width=\"1366\" height=\"244\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul1.png 1366w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul1-300x53.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul1-1024x182.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul1-624x111.png 624w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p style=\"text-align: justify\">Similarly, when we see the UI of the consul we see no nodes appearing.<\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46241\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul2.png\" alt=\"consul2\" width=\"1299\" height=\"206\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul2.png 1299w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul2-300x47.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul2-1024x162.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul2-624x98.png 624w\" sizes=\"(max-width: 1299px) 100vw, 1299px\" \/><\/p>\n<p style=\"text-align: justify\">Now run the consul containers on the two other machines with &#8211;advertise flag and &#8211;join flag. With &#8211;join flag we give the IP of the bootstrapping node, i.e, 192.168.33.60.<\/p>\n<p>[js]<br \/>\ndocker run -d -h consul-node2 -v \/mnt:\/data  \\<br \/>\n    -p 192.168.33.61:8300:8300 \\<br \/>\n    -p 192.168.33.61:8301:8301 \\<br \/>\n    -p 192.168.33.61:8301:8301\/udp \\<br \/>\n    -p 192.168.33.61:8302:8302 \\<br \/>\n    -p 192.168.33.61:8302:8302\/udp \\<br \/>\n    -p 192.168.33.61:8400:8400 \\<br \/>\n    -p 192.168.33.61:8500:8500 \\<br \/>\n    -p 172.17.0.1:53:53\/udp \\<br \/>\n    progrium\/consul -server -advertise 192.168.33.61 -join 192.168.33.60<br \/>\n[\/js]<\/p>\n<p style=\"text-align: justify\">When the other container is up and running, we see the logs of the first container. You can see that it tries to join the cluster. However, since there are only two nodes, \u00a0bootstrap process has not yet begun.<\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46242\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul3.png\" alt=\"consul3\" width=\"1360\" height=\"90\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul3.png 1360w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul3-300x19.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul3-1024x67.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul3-624x41.png 624w\" sizes=\"(max-width: 1360px) 100vw, 1360px\" \/><\/p>\n<p style=\"text-align: justify\">Next, run the third consul container on consul-node3 and observe the logs of the\u00a0first container. As you can see, the cluster leadership is complete and we have 3 node consul cluster functioning.<\/p>\n<p>[js]<br \/>\ndocker run -d -h consul-node3 -v \/mnt:\/data  \\<br \/>\n    -p 192.168.33.62:8300:8300 \\<br \/>\n    -p 192.168.33.62:8301:8301 \\<br \/>\n    -p 192.168.33.62:8301:8301\/udp \\<br \/>\n    -p 192.168.33.62:8302:8302 \\<br \/>\n    -p 192.168.33.62:8302:8302\/udp \\<br \/>\n    -p 192.168.33.62:8400:8400 \\<br \/>\n    -p 192.168.33.62:8500:8500 \\<br \/>\n    -p 172.17.0.1:53:53\/udp \\<br \/>\n    progrium\/consul -server -advertise 192.168.33.62 -join 192.168.33.60<br \/>\n[\/js]<\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46243\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul4.png\" alt=\"consul4\" width=\"1297\" height=\"336\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul4.png 1297w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul4-300x77.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul4-1024x265.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul4-624x161.png 624w\" sizes=\"(max-width: 1297px) 100vw, 1297px\" \/><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46244\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul5.png\" alt=\"consul5\" width=\"1366\" height=\"359\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul5.png 1366w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul5-300x78.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul5-1024x269.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul5-624x163.png 624w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p style=\"text-align: justify\">Consequently, when we run a docker container on consul-node3, it is not discovered by consul because we are not running any registrators. Thus we need to run 3 registrators for and on each node so that the data is in sync. These registrators give necessary information of the cluster to the consul master.<\/p>\n<p>[js]<br \/>\ndocker run -d &#8211;name=registrator1 &#8211;net=host &#8211;volume=\/var\/run\/docker.sock:\/tmp\/docker.sock gliderlabs\/registrator:latest consul:\/\/192.168.33.60:8500<br \/>\ndocker run -d &#8211;name=registrator2 &#8211;net=host &#8211;volume=\/var\/run\/docker.sock:\/tmp\/docker.sock gliderlabs\/registrator:latest consul:\/\/192.168.33.61:8500<br \/>\ndocker run -d &#8211;name=registrator3 &#8211;net=host &#8211;volume=\/var\/run\/docker.sock:\/tmp\/docker.sock gliderlabs\/registrator:latest consul:\/\/192.168.33.62:8500<br \/>\n[\/js]<\/p>\n<p>This will be done on all the nodes. As you can see, after running registrators on all nodes, the services are running perfectly.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46248\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul6.png\" alt=\"consul6\" width=\"1305\" height=\"502\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul6.png 1305w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul6-300x115.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul6-1024x393.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/consul6-624x240.png 624w\" sizes=\"(max-width: 1305px) 100vw, 1305px\" \/><\/p>\n<p>We are through with setting up Consul Multinode Cluster With Docker. I hope the blog was useful. Watch out this space for more such knowledge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Consul is a service discovery and a configuration system tool used to discover the services running on multiple nodes. It is both distributed and highly available. It provides a powerful interface to get a better picture of infrastructure and services running on them. Consul gives us a variety of features that help to determine our [&hellip;]<\/p>\n","protected":false},"author":969,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":67},"categories":[2348,1],"tags":[178,4435,4494,1891,1892,1883],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/46234"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/969"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=46234"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/46234\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=46234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=46234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=46234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}