Automating Dynamic IP Update to Cloudflare Using Kubernetes
Problem Statement
For a long time, my home IP was relitivly static. However a few months ago, my ISP moved onto a different setup which in-turn rotated my IP address and ever since, seems to be rotating weekly.
Since I am using residential internet and my ISP does not offer a static IP service, I was having to manually update my DNS records in Cloudflare every time my IP changed. This was a painful process, thus I did what I do best, automate it.
This document will walk you through how I automated the process of updating my Cloudflare DNS records using Kubernetes.
Project Setup
Kubernetes Cluster
Cloudflare Account
Cloudflare API Token
Solution
The solution is to create a Kubernetes CronJob that will run every 15 minutes to update the DNS record. Using python and click to create a CLI tool that will update the DNS record (source code can be found here. Coupled with a Kubernetes CronJob, this will automate the process of updating the DNS record.
This will run the cfcli update command every 15 minutes to update the DNS record.