Skip to content

Instantly share code, notes, and snippets.

@nikitawootten
Last active September 2, 2023 22:26
Show Gist options
  • Save nikitawootten/16125951b35224cd4f1a7934bbbface9 to your computer and use it in GitHub Desktop.
Save nikitawootten/16125951b35224cd4f1a7934bbbface9 to your computer and use it in GitHub Desktop.
Simple Cloudflare DDNS K8s `CronJob`
apiVersion: v1
kind: Secret
metadata:
name: cloudflare-ddns-secret
stringData:
ZONE_ID: ""
RECORD_ID: ""
NAME: test.example
TYPE: A
PROXIED: "true"
TTL: "1" # set to 1 for automatic
API_KEY: "" # your cloudflare api token
CHECK_IP: https://domains.google.com/checkip
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cloudflare-ddns-script-configmap
data:
run.sh: |
IP=$(curl $CHECK_IP)
curl --request PUT --url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $API_KEY" \
--data "{
\"content\": \"$IP\",
\"name\": \"$NAME\",
\"proxied\": $PROXIED,
\"ttl\": $TTL,
\"type\": \"$TYPE\"
}"
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: cloudflare-ddns-job
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 5
successfulJobsHistoryLimit: 5
startingDeadlineSeconds: 60
schedule: "*/5 * * * *"
jobTemplate:
metadata:
name: cloudflare-ddns-job
spec:
activeDeadlineSeconds: 240
backoffLimit: 3
template:
metadata:
name: cloudflare-ddns-job-pod
spec:
containers:
- name: cloudflare-ddns-job-container
image: fedora:36
command: ["bash", "/scripts/run.sh"]
envFrom:
- secretRef:
name: cloudflare-ddns-secret
volumeMounts:
- name: script-volume
mountPath: /scripts
volumes:
- name: script-volume
configMap:
name: cloudflare-ddns-script-configmap
restartPolicy: OnFailure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment