The silent page awaits the waking dawn.
catyuki-gitops/
├── clusters/
│ ├── cluster1/ # cdg1 的入口:flux-system + 四层定义
│ └── standby/ # sjc1 的入口
├── infrastructure/
│ ├── controllers/ # cert-manager、CNPG、Envoy Gateway 的 HelmRelease
│ └── configs/ # Gateway、PKI、Barman 插件
├── db/
│ ├── base/ # 命名空间、PG 专用 CA、数据库账号
│ ├── cluster1/ # postgres(主库 + 备份)
│ └── standby/ # postgres-sj(副本)
└── apps/
├── base/ # 服务 A、服务 B
├── cluster1/ # HPA、Portainer
└── standby/ # 副本数、HPA、Portainer Agent
Oct 22, 2026 · @binaryYuki
catyuki.com now runs on two machines: a 4-core, 24 GB Oracle ARM box in Paris (codename cdg1) as the primary, and a 2-core, 4 GB x86 machine in San Jose (codename sjc1) as a warm standby. Both are driven by the same Git repo; the database replicates in real time across the Atlantic; stateless services run active-active at a 60:40 split, and failover only takes a one-line config change.
Behind the site sit two backend services, referred to below as Service A and Service B. Service A is a Go API I wrote myself with no database dependency; Service B is a Node.js application backed by PostgreSQL and Redis. There's also a separately deployed frontend and the Portainer management dashboard. They were all crammed onto a single Docker + nginx VPS. After I tore that machine down and rebuilt it, I realized everything was concentrated in one cloud account and one data center, which kicked off this overhaul: migrate to k3s first, then add a second machine for disaster recovery.
This post walks through the full tech stack layer by layer and wraps up with a list of gotchas I ran into. For security reasons, source IPs, management ports, and specific service names are omitted throughout.
The Big Picture
Each machine runs its own standalone single-node k3s cluster. The only direct connection between the two is PostgreSQL's TLS streaming replication. Everything else stays in sync through Git—each machine's Flux pulls from the same repo independently.
[embedded content: catyuki.com architecture · 2 origin servers, 1 direct connection]
Three CDNs connect to both origins simultaneously. The only direct link between the two machines is database replication; all other configuration is pulled independently from the same Git repo.
cdg1
sjc1
Location
Paris (Oracle Cloud)
San Jose
Specs
4 cores, 24 GB, ARM64
2 cores, 4 GB, x86\_64
OS
Ubuntu 26.04
Ubuntu 24.04
DB Role
Global primary, read-write
Read-only replica, real-time replication
Traffic Served
60% of Service A, all of Service B and the dashboard
40% of Service A, the rest as standby origin
Layer
Component
Edge
Fastly (Service A, overseas), Alibaba ESA (Service A, mainland China), Gcore (Service B, dashboard, static assets); DNS on Bunny DNS
Gateway
Envoy Gateway 1.9.2, bound to 443 via k3s ServiceLB
Orchestration
k3s 1.36.5
Delivery
Flux 2.9.6, secrets encrypted into the repo with SOPS + age
Certificates
cert-manager 1.21.2 + self-built private CA
Database
CloudNativePG 1.30.1, PostgreSQL 16, Barman Cloud plugin 0.15.1
Object Storage
OCI Object Storage (DB backups), Backblaze B2 (static assets)
Applications
Service A, Service B, Portainer BE 2.45.3
Identity
Microsoft Entra ID (Portainer login)
Edge Layer: Origins Trust Only the CDN
The origins don't face visitors directly: only 443 is open (no port 80), and every request has to prove it comes from one of my CDNs. Service A's domains are geo-routed at the DNS level—mainland China goes through Alibaba ESA, the rest of the world through Fastly. Service B and the dashboard go through Gcore.
The three CDNs have different capabilities, so origin authentication works differently for each:
CDN
Origin Auth
Why
Fastly
mTLS client certificate
Supports mutual TLS to origin—cleanest option
Gcore
`X-Origin-Auth` request header
No mTLS support to origin
Alibaba ESA
`X-Origin-Auth` request header
No custom client cert support
Service A's listener is set to verify-if-cert-present: requests carrying Fastly's certificate are matched to the Fastly route by the Subject in the x-forwarded-client-cert that Envoy generates. Requests without a certificate go through the ESA route, where Envoy's apiKeyAuth checks X-Origin-Authand strips it immediately after validation. Each route also removes the other CDN's real-IP header to prevent visitor spoofing.
Private PKI
All origin certificates are issued by cert-manager using our own CA. There are three CAs in total:
Server certs are valid for two years and auto-renew 30 days before expiry. The CDNs trust the CA, not the individual cert, so after renewal there's nothing to do on the CDN side. For the dual-machine setup, these three CAs were switched from self-signed in-cluster generation to SOPS-encrypted imports from the repo. Both machines use the same CA set, which is what lets the CDNs trust both sides.
One Header, Full-Chain Visibility
Every response carries two debug headers:
The origin codename segment is a Flux-injected variable (cdg1 or sjc1); a Lua script in the gateway reads it and splices it in. The naming follows Cloudflare's cf-ray and Vercel's x-vercel-id: only location and request ID are exposed, never the tech stack.
Gateway Layer: Envoy Gateway
The entry point is Envoy Gateway; k3s's built-in traefik is disabled. It replaces the old nginx + CrowdSec Lua bouncer setup. All configuration is expressed in standard Gateway API resources—compression, rate limiting, authentication, and CORS are all declarative.
One gotcha worth calling out: ClientTrafficPolicy does not merge. Once a listener has a policy with sectionName specific settings, the Gateway-level default policy is completely overridden. So Service A's per-listener policy (mTLS verification) has to explicitly restate the shared settings—Server-Timing, timeouts, XFF trust depth—word for word.
Application Layer
The three apps deploy the same way; the difference is how many replicas run on each machine:
App
What It Is
cdg1
sjc1
Service A
Go API with Valkey, no database dependency
HPA 2–6 replicas
HPA 2–3 replicas
Service B
Node.js app with Redis and PostgreSQL
HPA 2–4 replicas
0 replicas, scaled up after promotion to primary
Portainer BE
Cluster management dashboard
Server
Agent only
Service B uses a StatefulSet instead of a Deployment for one reason: it generates IDs with the Snowflake algorithm, using the Pod ordinal as the worker ID so multiple replicas never collide. Two small details:enableServiceLinks must be turned off, otherwise the *_PORT=tcp://… environment variable that k8s auto-injects would override the app's own port config; Pods start in order to avoid multiple replicas installing dependencies into the shared volume simultaneously. Database migrations run as a Job — and since a Job can't be modified once created, I don't let Flux manage it. Before an upgrade, I run a script that deletes the old Job and creates a new one by hand.
Service A runs in cluster mode. Shared state — data snapshots, caches, upstream rate limiting — all lives in Valkey, and since every piece can be rebuilt, there's no persistence. On the security side, it runs at the Pod Security restricted level: non-root, read-only root filesystem, all capabilities dropped. The image is multi-arch — arm64 + amd64 — so the same tag runs on both the ARM box in Paris and the x86 box in San Jose.
Portainer logs in with Microsoft Entra ID. The "AD" option in Portainer settings is for on-prem Active Directory over LDAP; to connect to cloud-hosted Entra ID, you pick OAuth and fill in Microsoft's authorization, token, and userinfo endpoints per OIDC. sjc1 joins as a regular Agent: Portainer on cdg1 reaches out to sjc1, with the port open only to cdg1. I didn't use the Edge Agent because its tunnel port can't traverse the CDN.
Data Layer: PostgreSQL Across the Atlantic
The database runs on CloudNativePG (CNPG). The postgres cluster has two instances; if one goes down, it automatically fails over to the other. WAL gets its own volume. The Barman Cloud plugin continuously archives WAL to OCI object storage, with a full backup every day at 03:30, retained for 15 days — point-in-time recovery to any moment in that window.
The postgres-sj is the replica cluster in what CNPG calls a distributed topology: the initialpg_basebackup fetches the full backup across the ocean, then stays in sync through TLS streaming replication. Both Cluster definitions declare the same global primary:
When CNPG sees primary match itself, it acts as the primary; otherwise it replicates from source as its source. For a planned failover, I first demote the old primary to get a demotion token, then pass it to the new primary as a promotion token — CNPG waits until the new primary has fully caught up before promoting, so no data is lost. If a whole data center goes down, I just flip it without the token; the trade-off is that the old primary has to be rebuilt when it comes back.
Certificates: The Make-or-Break of Replication
By default, CNPG generates a separate CA for each cluster, rotated every 90 days. The two sides don't trust each other, so a certificate copied over would last at most 90 days. Instead, I created a dedicated PG-only CA, stored it in SOPS, and each machine's cert-manager uses it to issue server certificates and streaming_replica client certificates, with automatic renewal at expiry. CNPG hot-reloads certificates on rotation — the live primary never restarts.
A few details:
GitOps: Keeping Both Machines in Sync
Each machine runs its own Flux instance, pulling config from the same private GitHub repo. I didn't go with a centralized "one Argo CD managing two clusters" setup: if the machine hosting the control plane goes down, the other cluster is left orphaned. Independent Flux instances, on the other hand, don't depend on each other. A day-to-day config change is one action: edit the repo, push, and both machines pick it up within a minute.
Adopting Existing Resources
Before the migration, everything on cdg1 was deployed with helm install and kubectl apply deployment. Flux can adopt them: if the HelmRelease name and namespace match the original release, Flux takes over with a single helm upgrade install. Before each push I do two things: run kubectl diff --server-side to confirm nothing changed beyond labels and annotations; hash-compare every Secret in the repo against the live ones, and only commit once they match. Throughout the entire migration, the live services never went down.
Traffic Routing: 60:40 and Active-Standby
Not every service can run active-active. Service A has no database dependency, so both machines work independently and can serve traffic simultaneously. Service B writes to the database, and since sjc1's is read-only, it's active-standby only. The admin panel exists on cdg1 alone — no failover.
Service
CDN
Mode
Status
Service A (intl.)
Fastly
Weighted 60:40; health checks auto-evict
Live
Service A (China)
Alibaba ESA
Origin pool: weighted or active-standby
Pending — depends on plan support for load balancing
Service B
Gcore
Active-standby: fail over when the primary origin errors
Pending
Admin panel
Gcore
No failover
—
On the Fastly side: two origins and a VCL snippet. Both origins have identical TLS, SNI, and origin-pull client certificate settings, share the same health check (Service A's readiness endpoint), and traffic is split by weight via a random director:
In vcl_recv, set req.backend = svc_a_origin_lb; it takes effect immediately. The random director automatically skips origins that fail health checks, so it doubles as failover: when one goes down, 100% of traffic lands on the other. After deployment I fired off a batch of requests and tallied the X-Trace-Id origin identifiers — both cdg1 and sjc1 were serving traffic, and the larger the sample, the closer the ratio gets to 3:2.
Two trade-offs in the config:
Security: Three Lines of Defense
Only three port types are exposed publicly: 443 for CDN origin pulls, a non-standard port for SSH, and database replication plus Portainer Agent between the two machines, open only to each other. The latter two each have three lines of defense, and no single one failing alone creates an exposure:
Layer
cdg1
sjc1
Cloud firewall
Oracle security lists
Provider security groups
Host firewall
iptables
nftables (dedicated table)
k8s Service
`loadBalancerSourceRanges`
`loadBalancerSourceRanges`
The pitfalls at this layer are all k3s-related:
Gotcha Roundup
The scariest one: during bootstrap, sjc1 wrote --path was set to cdg1's path, so I just duplicated cdg1's config and stood up an empty primary database, complete with archiving aimed at the same backup bucket and a one-shot backup scheduled to fire immediately. What saved me was a Barman safeguard: before the first archive ran, it noticed the target path already held WAL from a different database and threwExpected empty archive a write rejection; the scheduled backup also sat in pending because the database wasn't ready yet. Not a single byte of the production backup got touched.
Pitfall
Symptom
Lesson
Bootstrap path pointed the wrong way
Standby copied the primary's database config verbatim
Write a full command for each machine — no "same as above, just change one flag." To change a path, bootstrap refuses to overwrite; stage the new path in flux-system in the repo first, then update the sync path.
`flux suspend` got undone
Resumed on its own a few minutes later
The child Kustomization is itself Git-synced by the parent, so a parent sync reverts it. Fix it at the root.
Fastly `quorum` set to 50%
Primary origin down → whole director unavailable
Quorum must be lower than the smallest member's weight share
`req.backend.is_origin`
Compile error in `vcl_recv`
This variable is only available in the backend-fetching phase; not needed once Shielding is off
OCI chart got a digest appended
Pod restarted once during the cert-manager takeover
Flux appends a content digest to the version, so the chart version in the Pod label changed
Labels lost after takeover
Pod Security labels gone from Service B's namespace
After Flux takes over, any field missing from the manifest gets deleted; write the original labels back verbatim
Committed but didn't push
Blamed a firewall blocking port 5432
Check `git log` for `origin/main` first; then triage by "timeout / refused / no route" to find which layer is stuck
Pasted a token into the terminal
It lingered in plaintext in the shell history
Revoke and reissue immediately; use `read -rs` going forward so the token never hits the command line
Portainer OAuth misconfigured
Login page only showed the OAuth button
A local admin can still log in via `/#!/internal-auth`, or flip auth back to Internal through the API
Final thoughts
For a personal site, this is obviously overkill. But what makes it worth it isn't the "two servers" part — it's two principles: Git is the single source of truth, and between the two machines there's only one direct connection: database replication. The first lets the second machine follow the first at near-zero cost; the second keeps the whole system's failure surface small enough to explain in a single sentence.