Skip to content

Instantly share code, notes, and snippets.

@LeeMartin77
Created November 10, 2022 19:03
Show Gist options
  • Save LeeMartin77/b5ed0e068ecfb07345ae710a4b3da978 to your computer and use it in GitHub Desktop.
Save LeeMartin77/b5ed0e068ecfb07345ae710a4b3da978 to your computer and use it in GitHub Desktop.
k8s Helm CronJob for updating Dynamic DNS Records in Google
# Wrote this for updating domains for my homelab cluster
# Uses a simple bash script to get the current IP, then send it to Google Domains
# You could update the env variables to read from a secret, but I use this with a values file
# in this format:
# domains:
# domainone:
# domainName: "sub.domain.com"
# domainUsername: USERNAME
# domainPassword: PASSWORD
# domaintwo:
# domainName: "domaintwo.com"
# domainUsername: USERNAME
# domainPassword: PASSWORD
apiVersion: batch/v1
kind: CronJob
metadata:
name: googledomain-updater
spec:
schedule: "0 * * * *"
jobTemplate:
metadata:
creationTimestamp: null
spec:
ttlSecondsAfterFinished: 100
template:
spec:
volumes:
- name: googledomain-updater-script
configMap:
name: googledomain-updater-script
defaultMode: 0755
containers:
{{- range $key, $val := .Values.domains }}
- name: updater-{{ $key }}
image: curlimages/curl:latest
imagePullPolicy: IfNotPresent
command: ["sh", "/script.sh"]
env:
- name: USERNAME
value: {{ required "Missing Username" $val.domainUsername }}
- name: PASSWORD
value: {{ required "Missing Password" $val.domainPassword }}
- name: HOSTNAME
value: {{ required "Missing Domain" $val.domainName }}
volumeMounts:
- name: "googledomain-updater-script"
mountPath: "/script.sh"
subPath: "script.sh"
readOnly: true
{{- end }}
restartPolicy: Never
---
kind: ConfigMap
apiVersion: v1
metadata:
name: googledomain-updater-script
data:
script.sh: |
IP=$(curl -s "https://domains.google.com/checkip")
# Update Google DNS Record
URL="https://${USERNAME}:${PASSWORD}@domains.google.com/nic/update?hostname=${HOSTNAME}&myip=${IP}"
curl -s $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment