video-iac/docker/coturn-dns/pod-node-register.py

41 lines
1.3 KiB
Python
Raw Normal View History

2021-11-12 17:31:53 +00:00
from kubernetes import client, config
2021-08-09 19:37:53 +00:00
import boto3
import time
2021-08-12 17:40:06 +00:00
import os
2021-08-09 19:37:53 +00:00
2021-08-30 18:21:19 +00:00
HOSTED_ZONE=os.environ['HOSTED_ZONE']
2021-11-12 17:31:53 +00:00
COTURN_DOMAIN_NAME=os.environ['COTURN_DOMAIN_NAME']
COTURN_DOMAIN_NAME="coturn.staging.video.jamkazam.com"
2021-08-10 18:55:36 +00:00
2021-11-12 17:31:53 +00:00
config.load_kube_config()
v1 = client.CoreV1Api()
2021-08-09 19:37:53 +00:00
2021-11-12 17:31:53 +00:00
while(True):
2021-08-09 19:37:53 +00:00
ips=[]
2021-11-12 17:31:53 +00:00
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)
2021-08-09 19:37:53 +00:00
print("Node IPs: "+str(ips))
2021-11-12 17:31:53 +00:00
2021-08-09 19:37:53 +00:00
client = boto3.client('route53')
response = client.change_resource_record_sets(
HostedZoneId=HOSTED_ZONE,
ChangeBatch= {
'Comment': 'COTURN NODES',
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
2021-08-30 18:21:19 +00:00
'Name': COTURN_DOMAIN_NAME,
2021-08-09 19:37:53 +00:00
'Type': 'A',
'TTL': 300,
'ResourceRecords': ips
}
}]
})
2021-11-12 17:31:53 +00:00
time.sleep(60)