Welcome to TGL and DS. In this article you will find consul cluster and registrator combination. I am also creating video tutorial. Please like and share my video and article. It will encourage me to create article and video more actively and Don't forget to subscribe my YouTube channel for get updates.
What is consul ?
- Consul is a way to do service discovery. It gives us key-value pair combination feature.
- It is written by Hashicrop and written in go lang.
- Consul includes multiple services - Services Discovery, Health check of services and nodes key-value pair combination and so on.
-
you can find more document in consul official website : www.consul.io
What is registrator ?
- Registrator will listen every docker event. like create container, stop container, delete container according to event it will register and diregister service.
- Ragistrator database can be consul, etcd and skydns2.
-
More document you can find in : registrator offcial github account
pre-requisite
- We should have 3 VM's with Docker stable version installed. Lets give name to 3 of our VM's : consul-bootstrap(192.168.1.6), consul-server(192.168.1.7), consul-agent(192.168.1.8)
- Open folowing port between these VM's : 8300/tcp, 8301/udp-tcp, 8400/tcp, 8500/tcp, 8600/udp
- Pull custom consul Docker image :
# docker pull rajugupta15/consul - Pull ragistrator following commands :
# docker pull gliderlabs/registrator:v7 - Pull mysql docker image :
# docker pull mysql:5.7 - Pull wordpress docker image :
# docker pull wordpress:4.5.3
Let us wirite down what we are trying to do :
- We will create consul container in three of our VM's - one will be bootstrap another one will server and last one will agent which will contact to server.
- On the 'consul-bootstrap' node we will run following commands to create consul bootstrap node.
- On the 'consul-server' node we will run following commands to create consul server node.
- On the 'consul-agent' node we will run following commands to create consul agent node.
- Every VM's will have registrator which will listen docker event and register and diregister service in consul.
- After making consul cluster we will create one wordpress service and one mysql service for testing. Both service will be in different nodes.
- To create mysql container use following command :
- To create wordpress container run following command :
# docker run --name="consul" -d -p "8300:8300" -p "8301:8301/udp" -p "8301:8301" -p "8400:8400" -p "8500:8500" -p "8600:53/udp" -e "ADVERTISE=192.168.1.6" -e "ARGS=-server -bootstrap-expect 1 -node=thegeeklinux-consul-bootstrap" -e "SERVICE_8300_IGNORE=always" -e "SERVICE_8400_IGNORE=always" -e "SERVICE_8500_IGNORE=always" -e "SERVICE_53_IGNORE=always" "thegeeklinux/consul:1.0" # docker run --name="consul" -d -p "8300:8300" -p "8301:8301/udp" -p "8301:8301" -p "8400:8400" -p "8500:8500" -p "8600:53/udp" -e "ADVERTISE=192.168.1.7" -e "ARGS=-server -node='thegeeklinux-consul-server' -join='192.168.1.6'" -e "SERVICE_8300_IGNORE=always" -e "SERVICE_8400_IGNORE=always" -e "SERVICE_8500_IGNORE=always" -e "SERVICE_53_IGNORE=always" thegeeklinux/consul:1.0 # docker run --name="consul" -d -p "8300:8300" -p "8301:8301/udp" -p "8301:8301" -p "8400:8400" -p "8500:8500" -p "8600:53/udp" -e "ADVERTISE=192.168.1.8" -e "ARGS=-node=thegeeklinux-consul-agent -join=192.168.1.6" -e "SERVICE_8300_IGNORE=always" -e "SERVICE_8400_IGNORE=always" -e "SERVICE_8500_IGNORE=always" -e "SERVICE_53_IGNORE=always" thegeeklinux/consul:1.0 # curl localhost:8500/v1/catalog/nodes It will give node list which is register with consul. # docker run --name="thegeeklinux-regstrator" -d -v "/var/run/docker.sock:/tmp/docker.sock" -h "tgl-registrator" gliderlabs/registrator:v7 -ip ${ip_address_of_local_system} consul://${ip_address_of_local_system}:8500 # docker run --name mysql -p 3306:3306 -v "/mysql/datadir:/var/lib/mysql" -e "MYSQL_ROOT_PASSWORD=thegeeklinux" -e "SERVICE_3306_NAME=mysql" -e "MYSQL_DATABASE=thegeeklinux" -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci # docker run -d --name thegeeklinux-wordpress -e "WORDPRESS_DB_HOST=$mysql_ip:3306" -e "WORDPRESS_DB_USER=root" -e "WORDPRESS_DB_PASSWORD=thegeeklinux" -p 80:80 wordpress:4.5.3
Nice.
ReplyDeleteGood post. This is very useful. Thanks for sharing.
ReplyDeleteWeb Development Training in Chennai
The modern era is an era of internet technology. If you need online education and training, devops complete tutorial now where you can learn our online programs and get instant devops foundation certification after the successful completion of your course, Addmission Now And Get 175$ devops complete course at only 10$ [limited time discount]
ReplyDeleteDiscount link:
https://www.udemy.com/devops-docker-complete-guide-hands-on-with-practical/?couponCode=MAXIMUS10
Coupon Code: MAXIMUS10