from kubernetes import client, config import boto3 import time import os HOSTED_ZONE=os.environ['HOSTED_ZONE'] COTURN_DOMAIN_NAME=os.environ['COTURN_DOMAIN_NAME'] COTURN_DOMAIN_NAME="coturn.staging.video.jamkazam.com" config.load_kube_config() v1 = client.CoreV1Api() while(True): ips=[] pods = v1.list_namespaced_pod(namespace="coturn") for i in pods.items: node_status = v1.read_node(name=i.spec.node_name) for adr in node_status.status.addresses: if adr.type=="ExternalIP": ips.append(adr.address) print("Node IPs: "+str(ips)) client = boto3.client('route53') response = client.change_resource_record_sets( HostedZoneId=HOSTED_ZONE, ChangeBatch= { 'Comment': 'COTURN NODES', 'Changes': [ { 'Action': 'UPSERT', 'ResourceRecordSet': { 'Name': COTURN_DOMAIN_NAME, 'Type': 'A', 'TTL': 300, 'ResourceRecords': ips } }] }) time.sleep(60)