This repo demonstrates the uses of Hashicorp's Consul.
- Service Registry
- Health Checks
- Key-Value (K/V) store
- Intro
- Configuration Directory
- Services
- HealthChecks
- Consul Connect
- Cluster
- Key/Value (K/V) Store
- UI Web Console
consul agentStarting in "Dev" mode:
consul agent -devFrom CLI:
consul members --detailedvia HTTP API:
curl localhost:8500/v1/catalog/nodes
default port of 8500 applies
or via DNS interface:
e.g.
dig @127.0.0.1 -p 8600 ip-192-168-20-127.eu-west-1.compute.internal
"Note that you have to make sure to point your DNS lookups to the Consul agent's DNS server which runs on port 8600 by default."
A 'config' directory for Consul. The directory stores:
- Service definition files
- HealthChecks definitions
- Sidecar Proxy definitions
This config directory is commonly stored under /etc/conf.d
Create the folder before starting up Consul.
e.g.
sudo mkdir /etc/conf.dYou define 'services' in a "Service Definition" file which is of JSON format. See this repo for samples.
You store the definition files in the Configuration Directory.
If Consul is already started up after you placed the 'new' Definition files in the Configuration Directory then issue either a Consul reload or SIGNUP
e.g.
consul reloadQueries e.g.
curl http://localhost:8500/v1/catalog/service/web
curl 'http://localhost:8500/v1/health/service/web?passing'or via DNS:
dig @127.0.0.1 -p 8600 rails.web.service.consul SRVcurl http://localhost:8500/v1/health/state/criticalor via DNS:
dig @127.0.0.1 -p 8600 web.service.consul[TBC]
consul connect proxy -sidecar-for socat
consul connect proxy -service web -upstream socat:9191
consul connect proxy -sidecar-for webInteractions in Consul are a way to specify whether a service can or cannot communicate with another service.
Deny
consul intention create -deny web socatAllow it again
consul intention delete web socat
Assumming you're running more than one node and therefore have multiple nodes forming a cluster.
One agent acts as the 'Server' so you start up the agent as the Server.
consul agent -server -bootstrap-expect=1 \
-data-dir=/tmp/consul -node=agent-one -bind=172.20.20.10 \
-enable-script-checks=true -config-dir=/etc/consul.dAnother 'member' comes along to this cluster as the 'Client'
consul agent -data-dir=/tmp/consul -node=agent-two -bind=172.20.20.11 -enable-script-checks=true -config-dir=/etc/consul.dTo join a cluster, run as the agent of any node and connect to one of the nodes already on the cluster by specifying that nodes' IP address.
e.g.
consul join 172.20.20.11Agent from one node querying another Agent from a second node.
e.g.
dig @127.0.0.1 -p 8600 agent-two.node.consulconsul leaveThe Key/Value store.
Put
consul kv put redis/config/minconns 1
consul kv put redis/config/maxconns 25
consul kv put -flags=42 redis/config/users/admin abcd1234Get one
consul kv get redis/config/minconns
consul kv get -detailed redis/config/minconnsGet All
consul kv get -recurseDelete
consul kv delete redis/config/minconns
consul kv delete -recurse redisUpdate
consul kv put foo bar
consul kv put foo zipAtomic Update
consul kv put -cas -modify-index=123 foo barvia the -ui flag on the CLI
consul agent -ui -config-dir=/etc/consul.dand then you can visit the /ui path on the HTTP port of 8500
e.g.
http://localhost:8500/ui/
The official Demo Consul UI is located here: https://demo.consul.io/ui