1

I've setup consul, and can now internaly resolve service hostnames to the appropriate IP. For example:

dig @127.0.0.1 -p 8600 tickethub.service.consul

; <<>> DiG 9.12.3-P1 <<>> @127.0.0.1 -p 8600 tickethub.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42657
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;tickethub.service.consul.  IN  A

;; ANSWER SECTION:
tickethub.service.consul. 0 IN  A   172.23.0.5
tickethub.service.consul. 0 IN  A   172.23.0.6
tickethub.service.consul. 0 IN  A   172.23.0.7

;; ADDITIONAL SECTION:
tickethub.service.consul. 0 IN  TXT "consul-network-segment="
tickethub.service.consul. 0 IN  TXT "consul-network-segment="
tickethub.service.consul. 0 IN  TXT "consul-network-segment="

;; Query time: 0 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Sun May 12 14:38:44 GMT 2019
;; MSG SIZE  rcvd: 209

How can I now route external traffic to the Consul service? It seems Nginx can use a explicit DNS server, but it seems it would cache the DNS lookup. So probably there is some pragmatic way to connect to a consul service?

Chris Stryczynski
  • 1,566
  • 2
  • 20
  • 25
  • Fabiolb and traefik are the most common proxies used for this but if you want you can also write a bit of code in your application to resolve SRV dns records from consul dns interface and use the ip and port from dns response to connect with the service. – Gufran Feb 25 '20 at 18:00

0 Answers0