One Evening, Three Problems: Mail Down, Memory Full, Wrong Docker Arch

Published: 2026-08-13

I run everything on one small VM: 4GB RAM, k0s, one node. This evening mail.antonnovikov.com started to return 503. I fixed it, and then I found that mail was not the real problem. The whole node was low on memory. After that, I broke a small site during a redeploy because I built it for the wrong CPU architecture. This post tells the story in order, with the commands I really ran.

The title says three problems, and there are four sections below. The count is still honest: problems 2 and 3 turn out to be the same problem.


Problem 1: mail.antonnovikov.com returns 503

The first check is always the same:

bashkubectl get pods -A | grep -v Running

Output:

webmail   snappymail-7fd545b5bf-tvhxx   0/1   CrashLoopBackOff   221 (13s ago)   251d

221 restarts. This is not new: the pod has been crashing for a long time. Today it just stayed down long enough for APISIX to return 503 (no healthy backend).

bashkubectl describe pod -n webmail snappymail-7fd545b5bf-tvhxx
Last State:  Terminated
  Reason:    OOMKilled
  Exit Code: 137

OOMKilled. The memory limit was 256Mi. The container grows slowly (a normal PHP-FPM worker leak), and it was killed about once a day for 251 days. Nobody noticed, because the pod comes back fast. Today the timing was bad, and it stayed down a bit too long.

Fix: raise the limit.

yamlresources:
  limits:
    memory: "384Mi"  # was 256Mi
    cpu: "500m"
bashkubectl patch deployment snappymail -n webmail --type='json' \
  -p='[{"op":"replace","path":"/spec/template/spec/containers/0/resources/limits/memory","value":"384Mi"}]'

Mail came back. But this made me look at the whole node, not only at the pod.


Problem 2: the node has almost no free memory

bashssh root@$SERVER_IP free -h
              total   used   free   shared  buff/cache  available
Mem:          3.8Gi   3.4Gi  120Mi  27Mi     553Mi       404Mi
Swap:         2.0Gi   801Mi  1.2Gi

120Mi free and 800Mi already in swap. This is not good for a 4GB box that runs the full k0s control plane plus ~30 pods (VPN proxies, monitoring stack, mail, a few small sites).

bashkubectl describe node antonnovikov.com | grep -A5 "Allocated resources"
Resource   Requests          Limits
--------   --------          ------
cpu        1105m (18%)       7250m (120%)
memory     1909048192 (47%)  6240Mi (163%)

Memory limits are overcommitted at 163%. On a single node this is not a problem by itself (there is no other node to move pods to anyway). But it tells me one thing: if two or three pods grow at the same time, one of them gets OOM-killed.

What I actually reduced

I did not just raise limits everywhere. On one node that changes nothing real: used RAM is used RAM, whatever the limit says. I looked for real and safe savings:

VictoriaMetrics (vmsingle) used 396Mi.

bashhelm get values vmsingle -n monitoring -a > /tmp/vmsingle-live.yaml
# memory.allowedPercent: 30 -> 20  (cache ceiling, no data loss)
helm upgrade vmsingle vm/victoria-metrics-single -n monitoring -f /tmp/vmsingle-live.yaml

Later I also doubled the global scrape interval, 30s -> 60s. This cut the ingestion rate in half: less CPU, fewer disk writes and less memory pressure. It also matters for problem 3 below.

Grafana dashboard sidecar. This is a k8s-sidecar container that watches ConfigMaps and reloads dashboards live. It cost ~90-130Mi just to sit there and watch. I don't edit dashboards often, so:

yamlsidecar:
  dashboards:
    enabled: false  # was true
bashhelm upgrade grafana grafana/grafana -n monitoring -f platform/monitoring/values/grafana.yaml

Dashboards still work. If I change one now, I need to run kubectl rollout restart deployment/grafana -n monitoring to load the change. A small price for -100Mi.

tor-proxy is a rotating Tor HTTP proxy. It ran with TOR_INSTANCES=2 (two tor daemons) and used 223Mi.

bashkubectl set env deployment/tor-proxy -n tor TOR_INSTANCES=1

This saved ~85Mi. It still works, just with fewer parallel exit circuits.

What I did not touch

APISIX, even though it is the biggest single consumer (~400Mi). My own install script has a comment from a past incident:

"Under real load (blackbox probes + real traffic), CPU hit the 500m limit and got stuck - both http and https stopped responding."

After that incident, the limits went up from 256Mi/500m to 512Mi/1000m. I'm not going back there. If I ever want APISIX to use less, I need a second node, not a smaller limit on this one.

Alerting stack (alertmanager, vmalert, kube-state-metrics, blackbox-exporter). I almost suggested removing it, because the Slack and PagerDuty connectors were not set up. That was a wrong assumption: alerts go straight to Telegram, so this stack does its job. Lesson: "connector X is not configured" does not mean "the feature is not used". Check the real receiver config, not only the integrations you connected yourself.


Problem 3: high disk read, ~40-70 MB/s, all evening

Grafana showed a flat, steady disk read graph. My first guess was "something is scanning a lot of data". Wrong guess. First I checked I/O per process and found nothing that explained 40-70 MB/s:

bash# snapshot /proc/<pid>/io read_bytes twice, 5s apart, compute delta

Nothing stood out. Then I checked swap activity directly:

bashvmstat 2 6
procs -----------memory---------- ---swap-- -----io----
 r  b   swpd   free  buff  cache    si   so    bi    bo
 5  0  758556 119432 9736 672540  7836   74  44346  252

si (swap in) and bi (blocks read) are both high, and they move together. That's the answer. This is not one noisy process, it is swap thrashing. With ~120Mi of free RAM, the kernel keeps moving process memory in and out of swap, and every page-in is a real disk read. The graph is flat because the memory pressure is constant. It is not a one-time spike.

So problem 3 is problem 2 again. Freeing real RAM (vmsingle, Grafana sidecar, tor-proxy) also fixes the disk graph. No separate disk tuning needed.


Problem 4: I redeployed a site and broke it with the wrong CPU architecture

While doing all this, I also redeployed a small static site (mne-pohui.rf) with a design update. A simple docker build && push && kubectl apply, I have done it a hundred times. This time it went wrong:

bashkubectl get pods -n default -l app=mne-pohui-site
mne-pohui-site-587fc87586-gmp62   0/1   CrashLoopBackOff
bashkubectl logs -n default -l app=mne-pohui-site
exec /docker-entrypoint.sh: exec format error

exec format error almost always means the wrong CPU architecture. My laptop is Apple Silicon (arm64), and the k0s node is amd64. The deploy script normally uses docker buildx build --platform linux/amd64. But docker buildx was not installed on this machine at all. The script silently fell back to plain docker build, which built for arm64 (the laptop's native architecture). That image got pushed, and the amd64 node could not run it.

I found one more thing on the way. The local Docker engine (I use colima, not Docker Desktop) had no insecure-registries setting. So the push to the internal 91.184.248.13:30500 registry failed with an HTTPS error before I even got to the architecture problem.

I fixed both:

bash# 1. install the missing buildx plugin
brew install docker-buildx
ln -sf /opt/homebrew/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx
yaml# 2. ~/.colima/default/colima.yaml
docker:
  insecure-registries:
    - 91.184.248.13:30500
bashcolima stop && colima start

Then I rebuilt it properly with --platform linux/amd64, pushed it and ran kubectl rollout restart. The old pod served traffic the whole time (Kubernetes does not remove the old replica until the new one is Ready). So visitors saw no real downtime. It was just a stuck rollout that I had to notice and fix.


What can go wrong (if you copy this)

  • A higher memory limit does not fix a leak. It only delays the crash. If snappymail hits OOM again at 384Mi, the leak is still there. Either restart PHP-FPM workers on a schedule or find the actual leak.
  • Don't cut resources on a component that already has a documented incident about cuts. Read your own old comments in scripts before you "optimize". I almost touched APISIX before I re-read my own install script.
  • A memory graph and a disk graph can have the same root cause. Check swap (vmstat, si/so) before you chase a specific process for disk I/O. On a box with too little memory, it is almost always swap.
  • exec format error means an architecture mismatch, not a broken image. Check that docker buildx build --platform really runs and is not silently skipped because buildx is not installed.
  • A rolling update protects you more than you think. A broken new pod in a Deployment does not take the site down by itself: the old replica stays until the new one is Ready. You still need to fix it, but it is not an emergency.

Summary

  • Mail returned 503 because snappymail was OOMKilled. I raised its limit from 256Mi to 384Mi.
  • The real cause was memory pressure on the whole node: 163% memory limits overcommit, 120Mi free, 800Mi in swap.
  • I freed real RAM: vmsingle cache ceiling from 30% to 20% plus scrape interval from 30s to 60s, Grafana dashboard sidecar off (~100Mi), tor-proxy from 2 instances to 1 (~85Mi).
  • I left APISIX alone. A past incident already showed that smaller limits break the site under load.
  • The alerting stack stays. It sends alerts to Telegram, so "no Slack/PagerDuty connector" was a false sign that nobody uses it.
  • The high disk I/O was swap thrashing caused by memory pressure, not one specific process. Same root cause as everything else.
  • Separately, I broke and fixed a redeploy because of an arm64/amd64 mismatch. buildx was not installed, so docker build silently built for the wrong architecture.