Here we register two custom DNS services sgw-s1u
and dp-cpdp
for our Dataplane, with Consul
Set necessary variables
IID=$(hostname | awk -F '-' '{print $NF}')
ETH0_IP=$(netstat -ie | grep -A1 eth0 | tail -1 | awk '{print $2}' | tr -d addr:)
SGW_S1U_IP=$(netstat -ie | grep -A1 s1u-net | tail -1 | awk '{print $2}' | tr -d addr:)
controller='ngic-fi'
Function that generates the service definition data
gen_svc_def()
{
name=$1-${IID}
cat << EOF
{"node":"$(hostname)", "address":"${ETH0_IP}", "service": {"service":"$name-$controller", "tags": ["udp"], "address":"$2", "port": $3}}
EOF
}
Check before PUT
echo $(gen_svc_def sgw-s1u ${SGW_S1U_IP} 2152)
echo $(gen_svc_def dp-cpdp ${ETH0_IP} 20)
Output
{"node":"ngic-fi-dp-0", "address":"192.168.51.32", "service": {"service":"sgw-s1u-0-ngic-fi", "tags": ["udp"], "address":"2.2.2.87", "port": 2152}}
{"node":"ngic-fi-dp-0", "address":"192.168.51.32", "service": {"service":"dp-cpdp-0-ngic-fi", "tags": ["udp"], "address":"192.168.51.32", "port": 20}}
Now register the service in the Consul catalog
curl -XPUT -H "Content-Type: application/json" http://consul-helm-consul:8500/v1/catalog/register -d "$(gen_svc_def sgw-s1u ${SGW_S1U_IP} 2152)"
curl -XPUT -H "Content-Type: application/json" http://consul-helm-consul:8500/v1/catalog/register -d "$(gen_svc_def dp-cpdp ${ETH0_IP} 20)"
Test DNS
# Basics
dig @192.168.50.169 -p 8600 sgw-s1u-0-ngic-fi.service.consul +short
dig @192.168.50.169 -p 8600 dp-cpdp-0-ngic-fi.service.consul +short
# SRV records
dig @192.168.50.169 -p 8600 sgw-s1u-0-ngic-fi.service.consul SRV
dig @192.168.50.169 -p 8600 dp-cpdp-0-ngic-fi.service.consul SRV
# RFC 2782
dig @192.168.50.169 -p 8600 _sgw-s1u-0-ngic-fi._udp.service.consul SRV
dig @192.168.50.169 -p 8600 _dp-cpdp-0-ngic-fi._udp.service.consul SRV