chore: k8s manifests and Gitea CI for ins-landing.containerverse.dev

Modelled on dynamic-qr: Traefik Gateway with Let's Encrypt, Longhorn PVC,
1 replica with Recreate, Calico network policies, and a rate limit on
POST /api/leads. CI runs the tests in a Dockerfile stage before pushing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfmHGGiYUjNcvJoyzdf
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 11:24:33 +08:00
1 parent 0d50d3c09c
commit 91b6b31644
8 files changed
+590 -10

No files matched your search

+25 -8
View File
@@ -23,20 +23,37 @@ docker build -t ins-landing-page .
docker run -p 3000:3000 -v ins-leads:/data ins-landing-page
```
## Deploying to Kubernetes
## Kubernetes (microk8s)
- Mount a PersistentVolumeClaim at `/data`. Without it, leads are lost when the pod restarts.
- Run exactly **1 replica** (SQLite file, single writer). Use `strategy: Recreate` so two pods never hold the volume at once during a rollout.
- The container runs as user `node` (uid 1000); set `securityContext.fsGroup: 1000` so it can write to the volume.
- Health check: `GET /` returns 200.
- **Required: rate-limit `POST /api/leads` at the ingress.** The form is public and the honeypot only stops naive bots; without a limit a script can fill the volume. For ingress-nginx, e.g. `nginx.ingress.kubernetes.io/limit-rpm: "30"` (per client IP, applies to the whole Ingress) on this Ingress.
`k8s/` deploys everything into namespace `ins-landing-page`, the same way as dynamic-qr:
- `40-app.yaml`: Longhorn PVC (1 Gi, ReadWriteOnce) mounted at `/data`, Service, and Deployment. The Deployment runs **1 replica** with `strategy: Recreate`, because SQLite has a single writer. It runs as uid 1000 with a read-only root filesystem.
- `50-gateway.yaml`:
- A Let's Encrypt Certificate and a Traefik Gateway for `ins-landing.containerverse.dev`.
- HTTP redirects to HTTPS.
- `POST /api/leads` goes through the `lead-rate-limit` middleware: 5 per minute per visitor, burst 5, keyed on the Cloudflare visitor IP.
- `60-network-policy.yaml`: denies all ingress except Traefik to port 3000, and Traefik to cert-manager's HTTP-01 solver.
Prerequisite: DNS for `ins-landing.containerverse.dev` points at the cluster through Cloudflare, like the other `containerverse.dev` hosts.
First install, on the microk8s host (`k` = `microk8s kubectl`):
k apply -f k8s/00-namespace.yaml
k -n ins-landing-page create secret docker-registry regcred \
--docker-server=gitea.containerverse.dev --docker-username=<user> --docker-password=<token>
k apply -f k8s/
k -n ins-landing-page rollout status deployment/ins-landing-page
Updates: every push to `main` runs the tests and builds `gitea.containerverse.dev/solvway/ins-landing-page:ins-landing-page-prd-latest`. CI then runs `./krrd.sh ins-landing-page ins-landing-page` on the deploy host. Manifest changes are applied by hand (`k apply -f k8s/`).
CI needs the same repository secrets as dynamic-qr: `PACKAGE_USER`, `PACKAGE_RW_KEY`, `DRONECICD_SSH_*`, `TELEGRAM_*` and, optionally, `MICROSOFT_TEAMS_WEBHOOK_URL`. They come from the `solvway` org once the repo is transferred there.
## Exporting leads
To CSV, from the running pod:
```bash
kubectl exec deploy/ins-landing-page -- node --disable-warning=ExperimentalWarning -e "
microk8s kubectl -n ins-landing-page exec deploy/ins-landing-page -- node --disable-warning=ExperimentalWarning -e "
const {DatabaseSync}=require('node:sqlite');
const rows=new DatabaseSync(process.env.DB_PATH,{readOnly:true}).prepare('SELECT * FROM leads ORDER BY id').all();
const q=v=>v==null?'':'\"'+String(v).replace(/^[=+\-@]/,\"'\$&\").replace(/\"/g,'\"\"')+'\"';
@@ -45,7 +62,7 @@ for(const r of rows)console.log(Object.values(r).map(q).join(','));
" > leads.csv
```
Or copy the whole database file: `kubectl cp <pod>:/data/leads.db ./leads.db`.
Prefer the CSV export above. The database runs in WAL mode, so copying only `leads.db` can miss the newest leads; if you copy the file, copy `leads.db-wal` with it.
Columns: `id, created_at (UTC), name, email, phone, company, service, referrer, utm_source, utm_medium, utm_campaign`.