One Year Later: I Finally Open-Sourced My Homelab K3s Stack

How do you publish your homelab code without accidentally publishing your whole infrastructure, passwords included? For a year I did not dare.

Comic: the man unwraps a big gift box labelled “Open Source” on a desk in a data center, code and gears burst out with confetti

🌐 Also available in: Deutsch · Français · Español · Italiano · Português · Nederlands · Polski

In short: A year after the start, my homelab K3s stack is finally open source – without accidentally publishing my entire infrastructure with it. The trick is two separate Git remotes: a private Gitea instance with secrets and inventory, a public repository without them. The post shows the stack, what a single playbook run does, how secrets are handled and everything that was harder than expected.

In a few of my recent posts I mentioned that I was trying to figure out how to publish my homelab automation code *without accidentally open-sourcing my entire infrastructure along with it* 😅

Turns out that’s a surprisingly non-trivial problem when your Ansible inventory looks like a cyberpunk treasure chest full of vaults, secrets and host-specific variables. 🔐🐉

After a bit of trial, error, caffeine and questionable life choices… I finally found a setup that works beautifully:

👉 two separate git remotes.

A private self-hosted Gitea instance keeps the *real* repository — including encrypted secrets, vault files and all the spicy internal bits.

Meanwhile a public GitHub repo only receives the clean automation code, with sensitive files excluded via .gitignore and replaced by friendly .example templates. 🧼✨

Anything secret is encrypted using Ansible Vault (AES-256) anyway — so even if something somehow slips through, all an attacker gets is encrypted gobbledygook. 🧠💾

📦 Repo:

👉 github.com/aptupgrademe/www_k3s (opens in a new tab)

The project provisions either Nextcloud or WordPress on a fresh single-node K3s cluster running on AlmaLinux 9.

One command.

Zero click-ops.

Maximum nerd energy. ⚡🤓


Table of Contents

🧠 The Idea

Run:

ansible-playbook blog.yml --limit <host> --ask-vault-pass

…against a completely fresh VPS and watch it transform itself into a fully hardened, TLS-enabled, monitored WordPress or Nextcloud server like some kind of infrastructure Pokémon evolution. 🐛➡️🐉

No manual SSH fiddling.

No mystery setup steps.

No “TODO: document later” graveyard. 💀

Everything is idempotent — re-run it anytime without nuking your data or summoning configuration drift demons.


⚙️ Stack at a Glance

  • 🏗️ K3s — Kubernetes without the enterprise trauma
  • 🔀 F5 nginx-ingress — running as DaemonSet with hostNetwork: true
  • 🔒 cert-manager — automatic Let’s Encrypt certs because browsers yearn for green locks
  • 📝 WordPress 6.9-fpm + nginx sidecar + MariaDB 10.11
  • ☁️ Nextcloud 33-fpm + Redis + Collabora (opens in a new tab) CODE for nerd-grade self-hosted office vibes
  • 📊 Prometheus + Grafana — because if you can’t graph it, does it even exist?
  • 🛡️ iptables — default DROP, portscan detection, ICMP rate limiting, tiny digital moat 🏰
  • 🔐 Fail2Ban, auditd, rkhunter, dnf-automatic — paranoia as code™

🚀 What One Playbook Run Actually Does

  1. 🔑 Hardens SSH — custom port, key-only auth, tighter configs
  2. 🔥 Builds IPv4 + IPv6 firewall rules with portscan detection via xt_recent
  3. 🧱 Enables SELinux enforcing with correct container contexts
  4. ☸️ Installs K3s (opens in a new tab), Helm, cert-manager and nginx-ingress
  5. 📦 Deploys the full Kubernetes workload stack automatically
  6. 📝 Configures WordPress via WP-CLI like a civilized automation goblin
  7. ☁️ Configures Nextcloud (opens in a new tab) via occ including Redis, SMTP and trusted domains
  8. 📈 Sets up monitoring exporters + Prometheus scraping + Grafana dashboards
  9. 🛡️ Deploys Fail2Ban, auditd, rkhunter scans and unattended security updates
  10. ☕ Probably consumes less coffee than I did while debugging it

🔐 Secrets & Security

All credentials are encrypted using Ansible Vault (AES-256).

Sensitive files like:

  • vault.yml
  • vars.yml
  • hosts.yml

…never touch the public repository. 🚫🌍

The GitHub repo only contains reusable automation code and .example templates:

vars.yml.example
vault.yml.example
hosts.yml.example

Clone → fill in values → encrypt → deploy. ✨


🙃 Things That Were Way Harder Than Expected

  • Let’s Encrypt HTTP-01 challenge returning 301

    Turns out redirecting everything to HTTPS also redirects the ACME challenge. Who could have guessed? 🙃

    Fixed using F5 Mergeable Ingresses (master/minion pattern) so /.well-known/ bypasses redirects.

  • Infinite HTTPS redirect loop

    My first nginx logic basically DDoSed itself philosophically.

    Fixed with a cleaner three-variable redirect pattern.

  • mysqld_exporter dropped DATA_SOURCE_NAME back in v0.15.0

    Credentials now need a mounted .my.cnf file.

    Also discovered that 0600 permissions don’t help if the container runs as nobody. 🤡

  • iptables OUTPUT DROP broke K3s internals

    Because apparently Kubernetes enjoys talking to itself constantly.

    Fixed with explicit ACCEPT rules for pod/service CIDRs.

  • Grafana dashboard 1860 showed “No data”

    Modern Grafana dashboards no longer contain __inputs.

    Solution: tiny Python patcher script talking to the Grafana API like a little automation goblin.


🎯 Conclusion

Sharing code without sharing secrets works – with two remotes, Vault for the secrets and a public repository that only holds the blueprint. The way there was paved with redirect loops, changed exporter options and a firewall that disturbed Kubernetes talking to itself. Now anyone can rebuild the stack, and I have a good reason to keep it clean.

🧪 Try It Yourself

git clone https://github.com/aptupgrademe/www_k3s.git
cd www_k3s

cp inventory/hosts.yml.example inventory/hosts.yml
cp inventory/host_vars/test/vars.yml.example inventory/host_vars/myhost/vars.yml

# fill in your values, then:
ansible-vault encrypt inventory/host_vars/myhost/vault.yml

ansible-playbook blog.yml --limit myhost --ask-vault-pass

The full quickstart, role overview and variable documentation live in the GitHub README.

PRs, feedback and fellow infrastructure nerds welcome. 🚀🐧☸️

Addendum (28 November 2026): The www_k3s repository is now archived and has been split: the Nextcloud part lives on in nextcloud_k3s (opens in a new tab), the blog server in www_hugo (opens in a new tab). The links in this post point to the state at the time and still work.


📚 Related posts:

Some text, images, videos and audio on this site are AI-assisted or AI-generated. Details