Created
September 25, 2014 16:07
-
-
Save hkumarmk/ae4d73ff460bd0e7e089 to your computer and use it in GitHub Desktop.
consul role/profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is what I did to test consul puppet module | |
### In consul, any node whether it is agent or server, (other than initial node) need an agent address which is in the cluster in order to join the cluster. This is different from etcd where it allow for autodiscovery. | |
I Faced couple of issues with consul module. | |
1. Consul service configuration json is not correct when port parameter specified in consul::service. consul expect that parameter to be integer, but module write it as string. This need to be fixed. | |
2. If initial server is not up while starting other servers or agent, the cluster join will be failed, and unless there is any (new) service definition, that node will not be joining to the consul cluster, as cluster join code in the module is only called when service restart. I submitted a patch in jiocloud/puppet-consul to fix this. | |
Added initial server IP in hiera in my env as testing for now. | |
Added below entry in hiera/data/env/harish.yaml | |
## Etcd server IP address is 10.1.0.243 for me | |
rjil::jiocloud::consul::join_cluster: 10.1.0.243 | |
Added rjil::jiocloud::consul | |
# | |
# Class rjil::jiocloud::consul | |
# | |
class rjil::jiocloud::consul ( | |
$join_cluster = false, | |
$server = false, | |
) { | |
class { '::consul': | |
join_cluster => $join_cluster, | |
config_hash => { | |
'data_dir' => '/opt/consul', | |
'server' => true, | |
'bootstrap_expect' => 3, | |
} | |
} | |
} | |
Called them in appropriate node blocks in site.pp | |
### 3 servers and rest agent only configuration | |
## This is initial server (no join_cluster param) | |
node "etcd" { | |
include rjil::base | |
class {'rjil::jiocloud::consul': | |
server => true, | |
join_cluster => undef, | |
} | |
} | |
## Second server | |
node /^db\d*/ { | |
include rjil::base | |
include rjil::db | |
class {'rjil::jiocloud::consul': | |
server => true, | |
} | |
} | |
## Third server | |
node /^lb\d+/ { | |
include rjil::base | |
# include rjil::haproxy | |
# include rjil::haproxy::contrail | |
class {'rjil::jiocloud::consul': | |
server => true, | |
} | |
} | |
## Agent only | |
node /mc\d*/ { | |
include rjil::base | |
include rjil::memcached | |
include rjil::jiocloud::consul | |
} | |
Then registered services for db and mc | |
## Added below entries in rjil::db | |
consul::service {'db': | |
tags => ['mysql','db'], | |
check_script => '/usr/lib/jiocloud/tests/mysql.sh' | |
} | |
## Added below entries to rjil::memcache | |
## register to consul | |
consul::service {'memcache': | |
tags => ['memcache'], | |
check_script => '/usr/lib/jiocloud/tests/memcached.sh' | |
} | |
########### Now After running puppet apply, I am able to get the services details by using | |
## Web querries | |
root@db1:/var/log/upstart# curl http://localhost:8500/v1/catalog/service/db | |
[{"Node":"db1","Address":"10.1.0.10","ServiceID":"db","ServiceName":"db","ServiceTags":["mysql","db"],"ServicePort":0}] | |
root@db1:/var/log/upstart# curl http://localhost:8500/v1/catalog/service/memcache | |
[{"Node":"mc1","Address":"10.1.0.248","ServiceID":"memcache","ServiceName":"memcache","ServiceTags":["memcache"],"ServicePort":0}] | |
## DNS Queries | |
root@db1:/var/log/upstart# dig @localhost -p 8600 db.service.consul | grep -A1 ANSWER.SECTION | |
;; ANSWER SECTION: | |
db.service.consul. 0 IN A 10.1.0.10 | |
root@db1:/var/log/upstart# dig @localhost -p 8600 memcache.service.consul | grep -A1 ANSWER.SECTION | |
;; ANSWER SECTION: | |
memcache.service.consul. 0 IN A 10.1.0.248 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment