apiVersion: v1 kind: ConfigMap metadata: name: ddns-script namespace: monitoring data: ddns.sh: | #!/bin/sh # Keeps the carr.pub apex A record pointing at this network's public IP. RECORD_ID=84723206 ZONE="carr.pub" ACCOUNT=6300 API="https://api.dnsimple.com/v2" AUTH="Authorization: Bearer ${DNSIMPLE_TOKEN}" IP=$(curl -s -m 15 https://ifconfig.me) case "$IP" in *.*.*.*) : ;; *) echo "no valid public ip: '$IP'"; exit 0 ;; esac CUR=$(curl -s -m 15 -H "$AUTH" "$API/$ACCOUNT/zones/$ZONE/records/$RECORD_ID" \ | sed -n 's/.*"content":"\([^"]*\)".*/\1/p') if [ "$IP" = "$CUR" ]; then echo "$(date -Is) up to date ($IP)" exit 0 fi RES=$(curl -s -m 15 -X PATCH -H "$AUTH" -H "Content-Type: application/json" \ "$API/$ACCOUNT/zones/$ZONE/records/$RECORD_ID" \ -d "{\"content\":\"$IP\"}") echo "$(date -Is) updated carr.pub -> $IP" case "$RES" in *'"id"'*) exit 0 ;; *) echo "API error: $RES"; exit 1 ;; esac --- apiVersion: batch/v1 kind: CronJob metadata: name: ddns-carr-pub namespace: monitoring spec: schedule: "*/5 * * * *" concurrencyPolicy: Forbid successfulJobsHistoryLimit: 1 failedJobsHistoryLimit: 3 jobTemplate: spec: backoffLimit: 1 template: spec: restartPolicy: Never containers: - name: ddns image: curlimages/curl:8.11.1 command: ["/bin/sh", "/scripts/ddns.sh"] env: - name: DNSIMPLE_TOKEN valueFrom: secretKeyRef: {name: dnsimple-token, key: token} resources: requests: {cpu: 10m, memory: 16Mi} limits: {memory: 32Mi} volumeMounts: - {name: scripts, mountPath: /scripts} volumes: - name: scripts configMap: {name: ddns-script, defaultMode: 0744}