Hello self-hosting friends!
I'm back with another great installment of Awesome Self Hosted! Today we're going to take a step back and look at Dynamic DNS (DDNS) and specifically how I've configured DDNS for my self hosted cluster.
For those who don't know, DDNS is the idea where we integrate with an external service (DuckDNS) where we ping them on a schedule. The dynamic DNS provider captures our public IP address, and attaches our public IP address to the sub-domains we've registered with them. DuckDNS allows anyone to have up to 5 sub-domains free of charge, and so it's an excellent way to achieve a free domain name for your self hosted cluster. As an added plus, DuckDNS allows all sub domains off your primary sub domains.
All DuckDNS subdomains are in the format of *.duckdns.org
- if you run a tool that can route by subdomains, DuckDNS treats any sub-sub domain as an instance of the primary sub-domain, and will route that call to the configured IP address. This means publish0x.duckdns.org
, sub1.publish0x.duckdns.org
and even awesome.sub1.publish0x.duckdns.org
are all routed to the same IP address. You can have endless combinations!
Here is an example of some DuckDNS configuration - I got to this page by going to https://www.duckdns.org/, logging in, and creating a sub-domain:
A quick note about the screenshot, the ip address is fake, and this domain & account have already been deleted, this is only for illustrative purposes.
Okay, great you say, I have a sub-domain attached to my public IP address, but, what do I do with it?
I have opened port 443
on my router, and I port forward any incoming traffic from that port to my self-hosted Kubernetes cluster. In another blog post, I will detail how I handle this incoming traffic, but today's blog post is all about getting traffic from the world wide webs to your cluster.
Beyond creating this DDNS configuration, the next piece is to run something to keep it updated. The beauty of DDNS is to allow you to have a static domain name, without paying for a static IP address from your ISP. The next step is to run a DuckDNS daemon either on your cluster or in docker that will continually ping DuckDNS from your home network. DuckDNS will update your IP address with the public IP address of the daemon making this call. For this reason, I recommend only running this daemon on a computer that never leaves your house. Let's get started!
We'll be using the linuxserver/duckdns
container, and it's usage is dead simple! You can view the image here.
You will need your token, and any domains you'd like to update from the screenshot above. To run in docker, simply execute:
docker run \
-e TZ=UTC \
-e SUBDOMAINS=publish0x,anothersubdomain \
-e TOKEN={token} \
-e LOG_FILE=false \
-d --restart unless-stopped \
linuxserver/duckdns
And that is it! This would continually ping DuckDNS to ensure your public IP address is always accurate for your sub domains.
You can run the same thing on Kubernetes, but we will first save the token as a secret.
kubectl create secret generic duckdns \
--from-literal=token={token} \
-n duckdns
With the token saved, all that is left is to start the DuckDNS pod.
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: duckdns
namespace: duckdns
spec:
replicas: 1
#number of replicas generated
selector:
#assigns labels to the pods for future selection
matchLabels:
app: duckdns
template:
metadata:
labels:
app: duckdns
spec:
containers:
- name: duckdns
image: linuxserver/duckdns
env:
- name: TZ
value: "UTC"
- name: SUBDOMAINS
value: "publish0x,anothersubdomain"
- name: TOKEN
valueFrom:
secretKeyRef:
name: duckdns
key: token
- name: LOG_FILE
value: "false"
And that is it!
Go ahead and apply that yaml, and you'll have DuckDNS up and running.
kubectl get pods -n duckdns
NAME READY STATUS RESTARTS AGE
duckdns-a75d625759-bxnmf 1/1 Running 0 4m32s
If you check the logs, you should see records if it updating your IP address on a 5 minute cadence.
Your IP was updated at Sat Mar 13 15:15:01 UTC 2021
Your IP was updated at Sat Mar 13 15:20:04 UTC 2021
Your IP was updated at Sat Mar 13 15:25:03 UTC 2021
This tool has been an integral and trusty part of my home cluster since it's inception. In the next post, I'll dive into what I do with this traffic once it's reached my cluster - subscribe for updates to see my Ingress and SSL configurations! Thanks for reading! Do you use a different DDNS tool? Let me know in the comments. DuckDNS seemed to be the most private and simple to configure of all the ones I investigated. I love this product!