Last active
August 27, 2019 20:35
-
-
Save haproxytechblog/3b8a6efc48bbd28bfbd8e92efcf8d9d1 to your computer and use it in GitHub Desktop.
DNS for Service Discovery in HAProxy
This file contains 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
_service._proto.name. TTL class SRV priority weight port target |
This file contains 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
resolvers mydns | |
nameserver dns1 192.168.50.30:53 | |
accepted_payload_size 8192 # allow larger DNS payloads |
This file contains 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
backend webservers | |
balance roundrobin | |
server-template web 5 myservice.example.local:80 check resolvers mydns init-addr none |
This file contains 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
$ dig @192.168.50.30 -p 53 A myservice.example.local | |
;; QUESTION SECTION: | |
;myservice.example.local. IN A | |
;; ANSWER SECTION: | |
myservice.example.local. 90 IN A 192.168.50.31 | |
myservice.example.local. 90 IN A 192.168.50.32 | |
myservice.example.local. 90 IN A 192.168.50.33 |
This file contains 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
backend webservers | |
balance roundrobin | |
server web1 192.168.50.31:80 check | |
server web2 192.168.50.32:80 check | |
server web3 192.168.50.33:80 check | |
server web4 check disabled | |
server web5 check disabled |
This file contains 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
global | |
log stdout local0 | |
stats socket :9000 mode 660 level admin |
This file contains 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
$ echo "show servers state servers" | nc localhost 9000 | |
# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord | |
3 servers 1 web1 192.168.50.33 0 32 1 1 400 7 2 0 14 0 0 0 myservice.example.local 80 - | |
3 servers 2 web2 192.168.50.31 0 32 1 1 290 6 3 0 14 0 0 0 myservice.example.local 80 - | |
3 servers 3 web3 192.168.50.32 0 32 1 1 401 7 2 0 14 0 0 0 myservice.example.local 80 - | |
3 servers 4 web4 - 0 32 1 1 404 1 0 0 14 0 0 0 myservice.example.local 80 - | |
3 servers 5 web5 - 0 32 1 1 404 1 0 0 14 0 0 0 myservice.example.local 80 - |
This file contains 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
frontend stats | |
bind :8404 | |
stats enable | |
stats uri / | |
stats refresh 5s |
This file contains 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
$ dig @192.168.50.30 -p 53 SRV _myservice._tcp.example.local | |
;; QUESTION SECTION: | |
;_myservice._tcp.example.local. IN SRV | |
;; ANSWER SECTION: | |
_myservice._tcp.example.local. 0 IN SRV 0 0 8081 host2. | |
_myservice._tcp.example.local. 0 IN SRV 0 0 8080 host1. | |
_myservice._tcp.example.local. 0 IN SRV 0 0 8082 host3. | |
;; ADDITIONAL SECTION: | |
host1. 0 IN A 192.168.50.31 | |
host3. 0 IN A 192.168.50.33 | |
host2. 0 IN A 192.168.50.32 |
This file contains 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
backend webservers | |
balance roundrobin | |
server-template web 5 _myservice._tcp.example.local resolvers mydns check init-addr none |
This file contains 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
echo "show servers state servers" | nc localhost 9000 | |
# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord | |
3 servers 1 web1 192.168.50.33 0 0 1 1 3 5 0 0 7 0 0 0 host3 8082 _myservice._tcp.example.local | |
3 servers 2 web2 192.168.50.32 0 0 1 1 1 7 2 0 6 0 0 0 host2 8081 _myservice._tcp.example.local | |
3 servers 3 web3 192.168.50.31 2 0 1 1 3 6 3 4 6 0 0 0 host1 8080 _myservice._tcp.example.local | |
3 servers 4 web4 - 0 0 1 1 2 5 2 0 6 0 0 0 - 0 _myservice._tcp.example.local | |
3 servers 5 web5 - 0 0 1 1 2 5 2 0 6 0 0 0 - 0 _myservice._tcp.example.local |
This file contains 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
backend webservers | |
balance roundrobin | |
server web1 192.168.50.33:8082 check | |
server web2 192.168.50.32:8081 check | |
server web3 192.168.50.31:8080 check | |
server web4 check disabled | |
server web5 check disabled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment