Production Infrastructure: GitOps on a Single k3s Node
How I run four production websites on one server: every release is a Git commit, new versions are health-checked before they get traffic, and a rollback is just reverting a commit.
This site runs on the same server as three client sites I built: phoenixsts.ie, safetyequipment.ie and iiesms.ie. This post is about the platform underneath them: how code gets to production, how a bad release gets stopped, and how the server is kept safe.
The short version
- Git is the only way to deploy. Nothing reaches production by SSH. A release is a commit; a rollback is reverting it.
- New versions have to prove themselves. Each release starts next to the live one and only gets traffic after automated checks pass. If they fail, users never see it.
- Everything is written down as code. The cloud server, DNS, cluster and even the server's config files live in Git.
The architecture
Cloudflare
│
nginx (TLS, security headers, rate limits)
│
┌─────────┴──────────┐
│ k3s (Kubernetes) │ Argo CD keeps it in sync with Git
│ 4 apps × staging + │ Argo Rollouts handles blue-green releases
│ prod │
└─────────┬──────────┘
│
PostgreSQL Prometheus · Grafana · Loki
Everything runs on one DigitalOcean server behind Cloudflare. Running Kubernetes on a single machine doesn't buy any failover, and I knew that going in. What it does buy is a declared, version-controlled description of what should be running, and proper tooling for safe releases. It was also something I wanted to learn to do well.
How a release works
- I push to
main. GitHub Actions builds a Docker image tagged with the commit hash and scans it for vulnerabilities. If the scan finds a serious fixable issue, the release stops there. - CI doesn't touch the server at all. It makes a commit to a separate infrastructure repo saying "staging should run this image".
- Argo CD sees the commit and deploys it to staging.
- A pull request is opened to put the same image in production. For the client sites it merges automatically once staging is healthy, or I can hold it and review it.
- Production gets exactly the image that was tested in staging.
Blue-green releases with automatic checks
This is the part I like most. Argo Rollouts starts the new version alongside the old one and tests it before switching any traffic:
- Health check: the app reports whether it can reach its database.
- Smoke test: a small job requests the site's key pages. Any server error or slow response fails the release.
If both pass, traffic switches over. It keeps watching after the switch too, using real traffic from the nginx logs. If the error rate or response times jump, it switches back on its own.
Before moving any real site over, I tested it with a deliberately broken release. The release was stopped within seconds, and the live site answered every request the whole time.
Rolling back is just setting the image back in Git. That takes about a minute. Within ten minutes of a release the old version is still running, so switching back is instant.
Infrastructure as code
- OpenTofu manages the server, firewalls, Cloudflare zones and DNS records, the secrets CI uses, and the Argo install itself.
- The cluster's desired state (which image each app runs, in staging and prod) lives in the infrastructure repo.
- The server's own config (nginx, Postgres, firewall, backup scripts, scheduled jobs) is mirrored in Git. An hourly check compares the live server against it and alerts me if something has changed without being committed.
Security
- Cloudflare is the only way in. The firewall only accepts web traffic from Cloudflare's IP ranges, so nobody can reach the server directly.
- Admin tools are private. SSH (key-only), the Argo CD dashboard and Grafana are only reachable over my private Tailscale network.
- fail2ban blocks the bots that probe for WordPress logins and leaked
.envfiles. - Apps are isolated. Containers run as non-root with minimal permissions. Each app has its own database user that can only see its own database.
Backups that actually restore
Each database is backed up nightly with restic: encrypted, and stored off the server in object storage.
A backup you've never restored is just a hope, so once a month a job restores the latest backup into a scratch database, checks every table is there with sensible row counts, and then deletes it. The result shows up in Grafana.
Monitoring
Prometheus, Grafana and Loki collect server metrics, uptime checks and logs, plus dashboards for every release and the checks it ran. Alerts go to Discord: a site going down, a release that failed its checks, or the server drifting from Git.
What's next
- Rebuild from scratch with one command. The server is fully described in Git, but rebuilding it is still a manual process.
- Fully separate staging. Staging has its own databases and secrets, but still shares a few third-party services with production.