diff --git a/k8s/Dockerfile-coturn-dns b/k8s/Dockerfile-coturn-dns new file mode 100644 index 0000000..a79cd56 --- /dev/null +++ b/k8s/Dockerfile-coturn-dns @@ -0,0 +1,10 @@ +FROM python:3 + +WORKDIR /app + +COPY k8s/coturn-dns/requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +COPY k8s/coturn-dns/ . + +CMD [ "python3", "register-nodes.py"] \ No newline at end of file diff --git a/k8s/coturn-dns/register-nodes.py b/k8s/coturn-dns/register-nodes.py new file mode 100644 index 0000000..2f8d116 --- /dev/null +++ b/k8s/coturn-dns/register-nodes.py @@ -0,0 +1,38 @@ +import requests +import json +import boto3 +import time + +HOSTED_ZONE="Z00156242SK162FEXDPVF" +CLUSTER_ID="29062" +POOL_ID="49934" +TOKEN={"Authorization": "Bearer a821bb97039cbd8b259e19ef9f7ea7a4e295a7399e00709fc27cad2b1f3742f4"} + +while(True): + r = requests.get("https://api.linode.com/v4/lke/clusters/"+CLUSTER_ID+"/pools/"+POOL_ID, headers=TOKEN) + + ips=[] + + for node in r.json()['nodes']: + ip = requests.get("https://api.linode.com/v4/linode/instances/"+str(node['instance_id'])+"/ips", headers=TOKEN) + #print(ip.json()) + ips.append({'Value': ip.json()['ipv4']['public'][0]['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.staging.video.jamkazam.com', + 'Type': 'A', + 'TTL': 300, + 'ResourceRecords': ips + } + }] + }) + time.sleep(60) \ No newline at end of file diff --git a/k8s/coturn-dns/requirements.txt b/k8s/coturn-dns/requirements.txt new file mode 100644 index 0000000..5ece686 --- /dev/null +++ b/k8s/coturn-dns/requirements.txt @@ -0,0 +1,2 @@ +boto3 +requests \ No newline at end of file