Keeping My Blog Online: Dynamic DNS with Cloudflare

Share
Keeping My Blog Online: Dynamic DNS with Cloudflare

You know I run my own Kubernetes cluster at home. This blog is hosted on it — and yay! it’s been working well. Well, until my external IP address changes.

I use Cloudflare to manage my DNS records, with an A record pointing my domain to my current external IP. If I wanted a static IP, my ISP would gladly sell me one — for a fee, of course (and you know I’m frugal).

In the beginning, I updated the A record manually every time my IP changed. This was fine while I was at home: a quick “what’s my IP” search on Google, and done. But the real issue showed up when I wasn’t home.

There was a time when I was telling someone about my Kubernetes cluster and they wanted to check out my blog (it’s still very new!). I was excited and gave them the link — but when I tried to open blog.katam.cc, it didn’t respond.

This usually meant one of two things:

  1. My nodes were down (which happened twice because the circuit breaker tripped 🙃)
  2. My external IP had changed

I can’t do much about the MCB tripping for now, but I could definitely solve the DNS problem.


Cloudflare DDNS to the Rescue

My first solution (probably not original, but new to me!) was to set up Cloudflare DDNS — a small tool to automatically check my external IP and update the DNS record if it changes.

Cloudflare’s API is well-documented. The idea is simple:

  • Get the current external IP.
  • Compare it with the IP in my A record.
  • If they don’t match, update the record with the current IP.

Easy.

Here’s how you can do it in a single Docker run (replace the values with your own):

docker run --rm \
  -e CLOUDFLARE_ZONE_ID="your_cloudflare_zone_id" \
  -e CLOUDFLARE_API_TOKEN="your_cloudflare_api_token" \
  -e CLOUDFLARE_RECORD_NAME="your.domain.com" \
  -e CLOUDFLARE_TTL="300" \
  -e CLOUDFLARE_PROXIED="true" \
  ghcr.io/prateekatam/cloudflare-ddns

But Wait... Kubernetes!

Since I’m already running a Kubernetes cluster, I deploy this as a Kubernetes CronJob via ArgoCD. It checks every few minutes and keeps my blog accessible, even if my ISP decides to shuffle my IP.

It’s a small thing, but seeing it work feels so satisfying. No more surprises when someone asks, “Hey, can I see your blog?” — it’ll always be up. Well, unless the circuit breaker trips again... but that’s another blog post.