Skip to content

Instantly share code, notes, and snippets.

@jefferai
Created September 3, 2015 18:31
Show Gist options
  • Save jefferai/7461cce52179b22dae5e to your computer and use it in GitHub Desktop.
Save jefferai/7461cce52179b22dae5e to your computer and use it in GitHub Desktop.
Consul without agents
> http http://127.0.0.1:8500/v1/catalog/register Datacenter="dc1" Node="node1" Address="10.0.0.1" Service:='{"ID": "redis1", "Service": "redis", "Tags": ["tag1"], "Address": "1.2.3.4", "Port": 1234}'
HTTP/1.1 200 OK
Content-Length: 4
Content-Type: application/json
Date: Thu, 03 Sep 2015 11:07:22 GMT
true
> http http://127.0.0.1:8500/v1/catalog/register Datacenter="dc1" Node="node2" Address="10.0.0.2" Service:='{"ID": "redis2", "Service": "redis", "Tags": ["tag2"], "Address": "5.6.7.8", "Port": 5678}'
HTTP/1.1 200 OK
Content-Length: 4
Content-Type: application/json
Date: Thu, 03 Sep 2015 11:10:21 GMT
true
> http http://127.0.0.1:8500/v1/catalog/service/redis
HTTP/1.1 200 OK
Content-Length: 301
Content-Type: application/json
Date: Thu, 03 Sep 2015 18:17:58 GMT
X-Consul-Index: 454
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
[
{
"Address": "10.0.0.1",
"Node": "node1",
"ServiceAddress": "1.2.3.4",
"ServiceID": "redis1",
"ServiceName": "redis",
"ServicePort": 1234,
"ServiceTags": [
"tag1"
]
},
{
"Address": "10.0.0.2",
"Node": "node2",
"ServiceAddress": "1.2.3.4",
"ServiceID": "redis2",
"ServiceName": "redis",
"ServicePort": 1234,
"ServiceTags": [
"tag2"
]
}
]
> dig @127.0.0.1 -p 8600 SRV redis.service.consul
; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @127.0.0.1 -p 8600 SRV redis.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1406
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;redis.service.consul. IN SRV
;; ANSWER SECTION:
redis.service.consul. 0 IN SRV 1 1 1234 node2.node.dc1.consul.
redis.service.consul. 0 IN SRV 1 1 1234 node1.node.dc1.consul.
;; ADDITIONAL SECTION:
node2.node.dc1.consul. 0 IN A 1.2.3.4
node1.node.dc1.consul. 0 IN A 1.2.3.4
;; Query time: 0 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Thu Sep 03 14:19:15 EDT 2015
;; MSG SIZE rcvd: 234
> dig @127.0.0.1 -p 8600 A tag1.redis.service.consul
; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> @127.0.0.1 -p 8600 A tag1.redis.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26882
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;tag1.redis.service.consul. IN A
;; ANSWER SECTION:
tag1.redis.service.consul. 0 IN A 1.2.3.4
;; Query time: 0 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Thu Sep 03 14:19:31 EDT 2015
;; MSG SIZE rcvd: 84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment