How can I know when a DNS change has propagated and that the record is resolving?

Viewed 22

A frequent problem I face is that the when deploying a new ingress to Kubernetes, the DNS creation takes time. The external-dns service in Kubernetes writes to route53 and creates the record as specified in the ingress, but it takes time for this DNS to propagate to our company DNS server.

1 Answers

In order not to have to wait longer than necessary, I wrote the following little python3 script that I am sharing below:

#!/usr/bin/python3
from socket import gethostbyname, gaierror
import time
import sys

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

def main(arg):
    print ("Waiting for dns to be ready for: %s%s%s" % (bcolors.OKGREEN, arg, bcolors.ENDC))
    while True:
        try:
            addr = gethostbyname(arg)
            print ("%s%s%s%s is up now\n" % ("\n", bcolors.OKGREEN, arg, bcolors.ENDC ))
            break
        except gaierror:
            try:
              print(".", end="")
              sys.stdout.flush()
              time.sleep(1)
              continue
            except KeyboardInterrupt:
              print ("\nInterrupt - aborting")
              exit()


if __name__ == '__main__':
    main(sys.argv[1])

Save the python code to wait4dns, and move the file to a place on your path. Execute chmod +x [path]/wait4dns.

Usage is wait4dns dns-name.com

Related