A governed app platform on a 4 GB VPS
On this page 6 sections
Keepyard, the platform I've been building, is Kubernetes underneath: k3s, gVisor sandboxes for every app and build, Cilium for the network rules, plus sign-in, metrics, logs and backups. That usually sounds like something for a rack of servers. My own copy runs on one Hetzner VPS with 4 GB of memory, next to nginx, and hosts all my sites. Here is what that takes, and where 4 GB runs out.
Lite mode: off until needed#
Below 6 GB of memory the installer picks a profile I call Lite. The security core is the same as on a big server: every app sandboxed, workspaces walled off from each other, new apps private behind a login, an approval before anything goes public. What changes is what runs all the time.
- Installed but switched off until something needs them: the Postgres operator, certificates, and the built-in backup storage. The first database, turning on HTTPS, or the first thing to back up starts them. The first database takes a few seconds longer to create; that's the whole cost.
- Off by default, one switch to turn on: image scanning, the live traffic map and log history. The settings page shows how much memory each one needs and how much is free.
- Always on: per-app requests, errors, latency, CPU and memory, uptime checks and alerts. The whole monitoring stack, metrics and log history together, uses about 130 MB when all of it is on.
With that, the platform itself needs about 1.2 GB. The rest is for apps.
Where the memory goes#
On my server the numbers look like this, roughly:
- The operating system and everything outside Kubernetes. The installer measures it and reserves memory for it so apps can't starve nginx or SSH. After I removed Docker, the other programs used about 220 MB, and the reservation is 768 MB.
- What's left for pods: about 2 GB.
- Apps reserve a quarter of their limit. An app gets 512 MB unless I change it, and it reserves 128 MB of that up front, at least 32 MB for tiny ones. That's what lets a static site, a Node site, two demo apps, a scheduled job and Keepyard's own website and licence service share 2 GB.
One thing to know about gVisor: an app's memory limit covers the whole sandbox, including files the app writes to its own container disk. An app that writes a big temp file can run out of memory without allocating much.
Builds are the hard part#
Running apps is cheap. Building them is not. Installing dependencies and compiling can use a lot of memory for a few minutes, and on a small server that's exactly where things fail.
My first version asked for 1 GB for every build. On the real server, with apps already running, that 1 GB was never free, and builds sat waiting until they timed out. Now:
- On Lite a build asks for 256 MB up front and can use more while it runs. My server is set even lower, to 192 MB, and that setting survives upgrades.
- Builds run one at a time and are the first thing to give way when memory runs short. Apps are never pushed out to make room for a build.
- When a build can't start, the console says it's waiting for memory, instead of just waiting.
Most of my builds are small. My template shop, a 546 MB static site, builds with about 180 MB, because building it means copying files into an nginx image. Static sites without a build step skip the builder completely: Keepyard puts the files into an image itself, and the site is live in seconds.
The exception was Go with a pure-Go SQLite driver. Compiling it on the server used enough memory that the build was evicted. That one I now compile on my laptop and deploy the result.
The disk matters too#
Memory runs out first, but the disk is close behind. The server has 38 GB, and each deploy of the template shop adds about 2.5 GB of image layers until old ones are cleaned up. Kubernetes' default cleanup starts at 85% full, which is also where it starts evicting pods, so the first big deploy evicted a build before anything was cleaned. The installer now starts cleaning at 75% and goes down to 60%. After cleaning up by hand, the disk sat at 66%.
What doesn't fit#
- Several builds at once. They queue. Usually that's a minute; with a big build it's longer.
- Everything switched on. Image scanning and log history are useful, and together with the rest they don't leave much for apps on 4 GB. I keep them off on this server.
- Many databases. Each Postgres instance used 150–250 MB in my tests. One or two fit; a team with ten would not.
- Room to grow. After the last release, 77% of the memory on my server is reserved. Everything runs, but builds queue more often than I'd like. The next step is 8 GB, which is also what I recommend in the docs for a team.
Would I do it again on 4 GB?#
For my own sites, yes. Five sites, a scheduled job, Keepyard's own website and its licence service run fine, sandboxed and behind the same rules a bigger install has. For a team that builds a lot, 4 GB works as a start and 8 GB is where it stops being a puzzle.
I wrote about what broke while moving the sites over separately. The installer, the Lite mode and the docs are at keepyard.dev.