feat: k8s manifests, Plausible self-host, Dockerfile, CI, and deploy runbook for using.cash
- k8s/using-cash/: namespace, deployment (2 replicas, rolling), service, ingress - apex (using.cash) with Let's Encrypt TLS via cert-manager HTTP-01 - www.using.cash permanent-redirect → using.cash - app.using.cash placeholder ingress (DNS slot reserved for product app) - k8s/analytics/: Plausible CE + Postgres 16 + ClickHouse 24.3 with PVCs - stats.using.cash ingress with TLS - init containers wait for Postgres and ClickHouse before Plausible starts - Secrets created out-of-band; placeholder files document the kubectl commands - Dockerfile: multi-stage Next.js static export → nginx:alpine (port 8080, non-root) - nginx.conf: trailing-slash static export support, immutable asset caching, security headers - .gitea/workflows/deploy.yml: CI build→push→rollout on push to main - docs/deploy.md: first-apply checklist, DNS cutover procedure, rollback commands Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
name: Build & Deploy — using.cash website
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
REGISTRY: git.falkvinge.net
|
||||
IMAGE_NAME: using-cash/website
|
||||
NAMESPACE: using-cash
|
||||
DEPLOYMENT: website
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set image tag
|
||||
id: tag
|
||||
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Log in to Gitea container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.sha }}
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
|
||||
- name: Configure kubectl
|
||||
uses: azure/k8s-set-context@v3
|
||||
with:
|
||||
method: kubeconfig
|
||||
kubeconfig: ${{ secrets.KUBECONFIG }}
|
||||
|
||||
- name: Deploy to cluster
|
||||
run: |
|
||||
kubectl set image deployment/${{ env.DEPLOYMENT }} \
|
||||
${{ env.DEPLOYMENT }}=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.sha }} \
|
||||
-n ${{ env.NAMESPACE }}
|
||||
|
||||
- name: Wait for rollout
|
||||
run: |
|
||||
kubectl rollout status deployment/${{ env.DEPLOYMENT }} \
|
||||
-n ${{ env.NAMESPACE }} --timeout=120s
|
||||
|
||||
- name: Verify deployment
|
||||
run: |
|
||||
kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ env.DEPLOYMENT }}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Stage 1: build Next.js static export
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci --prefer-offline
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: serve with nginx (non-root, port 8080)
|
||||
FROM nginx:1.27-alpine
|
||||
COPY --from=builder /app/out /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 8080
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
|
||||
CMD wget -qO- http://localhost:8080/ || exit 1
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
# Deploy & Rollback Runbook — using.cash
|
||||
|
||||
## Overview
|
||||
|
||||
| Component | Namespace | Image / Service |
|
||||
|---|---|---|
|
||||
| Marketing website | `using-cash` | `git.falkvinge.net/using-cash/website:<sha>` |
|
||||
| Plausible analytics | `analytics` | `ghcr.io/plausible/community-edition:v2.1.4` |
|
||||
| Postgres (Plausible) | `analytics` | `postgres:16-alpine` |
|
||||
| ClickHouse (Plausible) | `analytics` | `clickhouse/clickhouse-server:24.3-alpine` |
|
||||
|
||||
---
|
||||
|
||||
## First-Time Apply (cluster bootstrap)
|
||||
|
||||
Run once when setting up the cluster for the first time. After this, CI handles deploys.
|
||||
|
||||
### 1. Prerequisites — verify cluster dependencies
|
||||
|
||||
```bash
|
||||
# Confirm nginx-ingress is running
|
||||
kubectl get pods -n ingress-nginx
|
||||
|
||||
# Confirm cert-manager is running
|
||||
kubectl get pods -n cert-manager
|
||||
|
||||
# Confirm letsencrypt-prod ClusterIssuer exists
|
||||
kubectl get clusterissuer letsencrypt-prod
|
||||
```
|
||||
|
||||
If any are missing, install them before proceeding:
|
||||
- nginx-ingress: `helm install ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx --create-namespace`
|
||||
- cert-manager: `helm install cert-manager jetstack/cert-manager -n cert-manager --create-namespace --set installCRDs=true`
|
||||
- letsencrypt-prod ClusterIssuer: see `k8s/cluster/letsencrypt-prod-issuer.yaml` (create if absent)
|
||||
|
||||
### 2. Confirm ingress LB external IP
|
||||
|
||||
```bash
|
||||
kubectl get svc -n ingress-nginx ingress-nginx-controller
|
||||
# Note the EXTERNAL-IP — this is what using.cash A record must point to
|
||||
```
|
||||
|
||||
### 3. Create secrets (out-of-band — never committed to git)
|
||||
|
||||
```bash
|
||||
# Postgres password
|
||||
kubectl create secret generic postgres-secret \
|
||||
--from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 32)" \
|
||||
-n analytics --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Plausible app secrets
|
||||
kubectl create secret generic plausible-env \
|
||||
--from-literal=SECRET_KEY_BASE="$(openssl rand -hex 64)" \
|
||||
--from-literal=TOTP_VAULT_KEY="$(openssl rand -base64 32)" \
|
||||
-n analytics --dry-run=client -o yaml | kubectl apply -f -
|
||||
```
|
||||
|
||||
### 4. Apply namespaces first
|
||||
|
||||
```bash
|
||||
kubectl apply -f k8s/using-cash/namespace.yaml
|
||||
kubectl apply -f k8s/analytics/namespace.yaml
|
||||
```
|
||||
|
||||
### 5. Apply website manifests
|
||||
|
||||
```bash
|
||||
kubectl apply -f k8s/using-cash/deployment.yaml
|
||||
kubectl apply -f k8s/using-cash/service.yaml
|
||||
kubectl apply -f k8s/using-cash/ingress.yaml
|
||||
```
|
||||
|
||||
### 6. Apply Plausible analytics manifests
|
||||
|
||||
```bash
|
||||
kubectl apply -f k8s/analytics/pvcs.yaml
|
||||
kubectl apply -f k8s/analytics/postgres.yaml
|
||||
kubectl apply -f k8s/analytics/clickhouse.yaml
|
||||
kubectl apply -f k8s/analytics/plausible.yaml
|
||||
|
||||
# Wait for all pods to be ready
|
||||
kubectl rollout status deployment/postgres -n analytics
|
||||
kubectl rollout status deployment/clickhouse -n analytics
|
||||
kubectl rollout status deployment/plausible -n analytics
|
||||
```
|
||||
|
||||
### 7. Create Plausible site + admin account
|
||||
|
||||
```bash
|
||||
# Exec into the plausible pod
|
||||
kubectl exec -it deploy/plausible -n analytics -- sh
|
||||
|
||||
# Create the admin user (first user becomes admin)
|
||||
# Then log in at https://stats.using.cash and create site "using.cash"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## DNS Cutover
|
||||
|
||||
### Pre-cutover checklist
|
||||
|
||||
- [ ] Ingress LB external IP confirmed (Step 2 above)
|
||||
- [ ] All manifests applied and pods healthy
|
||||
- [ ] Current `using.cash` A record documented (for rollback)
|
||||
- [ ] cert-manager + letsencrypt-prod ClusterIssuer confirmed
|
||||
- [ ] nginx-ingress confirmed running
|
||||
- [ ] Send-and-receive test from `klaus.ubervold@using.cash` to confirm mail works before cutover
|
||||
|
||||
### Current DNS state (document before touching)
|
||||
|
||||
```
|
||||
# Run before cutover:
|
||||
dig using.cash A
|
||||
dig www.using.cash A
|
||||
dig using.cash MX
|
||||
dig using.cash TXT # SPF, DKIM, DMARC
|
||||
```
|
||||
|
||||
### Records to add/update
|
||||
|
||||
| Record | Type | Value | Notes |
|
||||
|---|---|---|---|
|
||||
| `using.cash` | A | `<ingress LB external IP>` | Replace existing A if any |
|
||||
| `www.using.cash` | CNAME | `using.cash` | Adds / replaces |
|
||||
| `stats.using.cash` | CNAME | `using.cash` | New — Plausible |
|
||||
| `app.using.cash` | CNAME | `using.cash` | New — reserved slot, placeholder only |
|
||||
|
||||
### Records to NOT touch
|
||||
|
||||
- `using.cash` MX — mail delivery
|
||||
- `using.cash` TXT (SPF) — mail auth
|
||||
- `_domainkey.using.cash` TXT (DKIM) — mail signing
|
||||
- `_dmarc.using.cash` TXT (DMARC) — mail policy
|
||||
|
||||
### Post-cutover verification
|
||||
|
||||
```bash
|
||||
# DNS propagation (may take 0–60 min depending on TTL)
|
||||
dig using.cash A @8.8.8.8
|
||||
dig www.using.cash CNAME @8.8.8.8
|
||||
|
||||
# TLS cert issuance (cert-manager HTTP-01 — happens automatically)
|
||||
kubectl describe certificate using-cash-tls -n using-cash
|
||||
kubectl describe certificaterequest -n using-cash
|
||||
|
||||
# Site up
|
||||
curl -I https://using.cash
|
||||
curl -I https://www.using.cash # should redirect 301 → https://using.cash
|
||||
|
||||
# Plausible up
|
||||
curl -I https://stats.using.cash/api/health
|
||||
|
||||
# Mail — send + receive test
|
||||
# Send from/to: klaus.ubervold@using.cash, henrik.larsson@using.cash
|
||||
```
|
||||
|
||||
### DNS rollback
|
||||
|
||||
If the cutover causes issues, revert the A record to its previous value:
|
||||
|
||||
```bash
|
||||
# Previous A record: <document before cutover>
|
||||
# DNS TTL: set low (300s) before cutover to allow fast rollback
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Ongoing Deploys (CI)
|
||||
|
||||
CI runs automatically on push to `main` via `.gitea/workflows/deploy.yml`.
|
||||
|
||||
Manual deploy (if CI is unavailable):
|
||||
|
||||
```bash
|
||||
SHA=$(git rev-parse --short HEAD)
|
||||
docker build -t git.falkvinge.net/using-cash/website:$SHA .
|
||||
docker push git.falkvinge.net/using-cash/website:$SHA
|
||||
|
||||
kubectl set image deployment/website \
|
||||
website=git.falkvinge.net/using-cash/website:$SHA \
|
||||
-n using-cash
|
||||
|
||||
kubectl rollout status deployment/website -n using-cash
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Rollback
|
||||
|
||||
### Website rollback
|
||||
|
||||
```bash
|
||||
# Immediate rollback to previous image
|
||||
kubectl rollout undo deployment/website -n using-cash
|
||||
|
||||
# Verify
|
||||
kubectl rollout status deployment/website -n using-cash
|
||||
kubectl get pods -n using-cash
|
||||
```
|
||||
|
||||
### Rollback to specific SHA
|
||||
|
||||
```bash
|
||||
# List rollout history
|
||||
kubectl rollout history deployment/website -n using-cash
|
||||
|
||||
# Roll back to specific revision
|
||||
kubectl rollout undo deployment/website -n using-cash --to-revision=<N>
|
||||
```
|
||||
|
||||
### Plausible rollback
|
||||
|
||||
Plausible uses Recreate strategy. Rolling back the deployment image is sufficient:
|
||||
|
||||
```bash
|
||||
kubectl rollout undo deployment/plausible -n analytics
|
||||
```
|
||||
|
||||
Postgres and ClickHouse data is persisted on PVCs and is unaffected by pod restarts.
|
||||
|
||||
---
|
||||
|
||||
## Monitoring
|
||||
|
||||
```bash
|
||||
# Website pods
|
||||
kubectl get pods -n using-cash
|
||||
kubectl logs deploy/website -n using-cash --tail=50
|
||||
|
||||
# Analytics pods
|
||||
kubectl get pods -n analytics
|
||||
kubectl logs deploy/plausible -n analytics --tail=50
|
||||
|
||||
# Cert status
|
||||
kubectl get certificates -A
|
||||
kubectl get certificaterequests -A
|
||||
|
||||
# Ingress
|
||||
kubectl get ingress -A
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## CI Secrets (Gitea repository settings)
|
||||
|
||||
| Secret name | Value |
|
||||
|---|---|
|
||||
| `REGISTRY_USERNAME` | Gitea username with write access to `using-cash` packages |
|
||||
| `REGISTRY_PASSWORD` | Gitea password or access token |
|
||||
| `KUBECONFIG` | Full kubeconfig YAML for the cluster (base64 or raw) |
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: clickhouse-config
|
||||
namespace: analytics
|
||||
data:
|
||||
# Plausible CE requires this ClickHouse config for event storage
|
||||
clickhouse-config.xml: |
|
||||
<clickhouse>
|
||||
<logger>
|
||||
<level>warning</level>
|
||||
<console>true</console>
|
||||
</logger>
|
||||
<query_log remove="remove"/>
|
||||
<query_thread_log remove="remove"/>
|
||||
<part_log remove="remove"/>
|
||||
<trace_log remove="remove"/>
|
||||
<text_log remove="remove"/>
|
||||
<metric_log remove="remove"/>
|
||||
<asynchronous_metric_log remove="remove"/>
|
||||
<session_log remove="remove"/>
|
||||
<zookeeper_log remove="remove"/>
|
||||
</clickhouse>
|
||||
clickhouse-user-config.xml: |
|
||||
<clickhouse>
|
||||
<profiles>
|
||||
<default>
|
||||
<log_queries>0</log_queries>
|
||||
<log_query_threads>0</log_query_threads>
|
||||
</default>
|
||||
</profiles>
|
||||
</clickhouse>
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: clickhouse
|
||||
namespace: analytics
|
||||
labels:
|
||||
app: clickhouse
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: clickhouse
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: clickhouse
|
||||
spec:
|
||||
containers:
|
||||
- name: clickhouse
|
||||
image: clickhouse/clickhouse-server:24.3-alpine
|
||||
ports:
|
||||
- containerPort: 8123
|
||||
name: http
|
||||
- containerPort: 9000
|
||||
name: native
|
||||
resources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 2Gi
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /var/lib/clickhouse
|
||||
- name: config
|
||||
mountPath: /etc/clickhouse-server/config.d/logging.xml
|
||||
subPath: clickhouse-config.xml
|
||||
- name: config
|
||||
mountPath: /etc/clickhouse-server/users.d/logging.xml
|
||||
subPath: clickhouse-user-config.xml
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /ping
|
||||
port: 8123
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /ping
|
||||
port: 8123
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: clickhouse-data
|
||||
- name: config
|
||||
configMap:
|
||||
name: clickhouse-config
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: clickhouse
|
||||
namespace: analytics
|
||||
labels:
|
||||
app: clickhouse
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: clickhouse
|
||||
ports:
|
||||
- name: http
|
||||
port: 8123
|
||||
targetPort: 8123
|
||||
- name: native
|
||||
port: 9000
|
||||
targetPort: 9000
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: analytics
|
||||
labels:
|
||||
app.kubernetes.io/managed-by: kubectl
|
||||
@@ -0,0 +1,143 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: plausible-config
|
||||
namespace: analytics
|
||||
data:
|
||||
BASE_URL: "https://stats.using.cash"
|
||||
DATABASE_URL: "postgres://plausible:$(POSTGRES_PASSWORD)@postgres.analytics.svc.cluster.local:5432/plausible_db"
|
||||
CLICKHOUSE_DATABASE_URL: "http://clickhouse.analytics.svc.cluster.local:8123/plausible_events_db"
|
||||
# No cookies, no banner — Plausible default
|
||||
DISABLE_REGISTRATION: "invite_only"
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: plausible
|
||||
namespace: analytics
|
||||
labels:
|
||||
app: plausible
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 0
|
||||
maxSurge: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: plausible
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: plausible
|
||||
spec:
|
||||
initContainers:
|
||||
# Wait for Postgres to be ready before starting Plausible
|
||||
- name: wait-for-postgres
|
||||
image: busybox:1.36
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
until nc -z postgres.analytics.svc.cluster.local 5432; do
|
||||
echo "waiting for postgres..."; sleep 2;
|
||||
done
|
||||
# Wait for ClickHouse to be ready before starting Plausible
|
||||
- name: wait-for-clickhouse
|
||||
image: busybox:1.36
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
until nc -z clickhouse.analytics.svc.cluster.local 8123; do
|
||||
echo "waiting for clickhouse..."; sleep 2;
|
||||
done
|
||||
containers:
|
||||
- name: plausible
|
||||
image: ghcr.io/plausible/community-edition:v2.1.4
|
||||
command: ["/bin/sh", "-c", "/entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"]
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: DATABASE_URL
|
||||
value: "postgres://plausible:$(POSTGRES_PASSWORD)@postgres.analytics.svc.cluster.local:5432/plausible_db"
|
||||
- name: CLICKHOUSE_DATABASE_URL
|
||||
value: "http://clickhouse.analytics.svc.cluster.local:8123/plausible_events_db"
|
||||
- name: BASE_URL
|
||||
value: "https://stats.using.cash"
|
||||
- name: DISABLE_REGISTRATION
|
||||
value: "invite_only"
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: plausible-env
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
name: http
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 512Mi
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/health
|
||||
port: 8000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 15
|
||||
failureThreshold: 5
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/health
|
||||
port: 8000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: plausible
|
||||
namespace: analytics
|
||||
labels:
|
||||
app: plausible
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: plausible
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 8000
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: plausible
|
||||
namespace: analytics
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- stats.using.cash
|
||||
secretName: plausible-tls
|
||||
rules:
|
||||
- host: stats.using.cash
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: plausible
|
||||
port:
|
||||
number: 80
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: postgres-config
|
||||
namespace: analytics
|
||||
data:
|
||||
POSTGRES_DB: plausible_db
|
||||
POSTGRES_USER: plausible
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: postgres-secret
|
||||
namespace: analytics
|
||||
type: Opaque
|
||||
stringData:
|
||||
# Apply out-of-band: kubectl create secret generic postgres-secret \
|
||||
# --from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 32)" \
|
||||
# -n analytics --dry-run=client -o yaml | kubectl apply -f -
|
||||
POSTGRES_PASSWORD: REPLACE_WITH_STRONG_RANDOM_PASSWORD
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: postgres
|
||||
namespace: analytics
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres
|
||||
image: postgres:16-alpine
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: postgres-config
|
||||
- secretRef:
|
||||
name: postgres-secret
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 512Mi
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
livenessProbe:
|
||||
exec:
|
||||
command: ["pg_isready", "-U", "plausible", "-d", "plausible_db"]
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: ["pg_isready", "-U", "plausible", "-d", "plausible_db"]
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-data
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgres
|
||||
namespace: analytics
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: postgres
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
targetPort: 5432
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: postgres-data
|
||||
namespace: analytics
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: clickhouse-data
|
||||
namespace: analytics
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 20Gi
|
||||
@@ -0,0 +1,22 @@
|
||||
# Plausible secrets — values must be filled before apply.
|
||||
# Generate SECRET_KEY_BASE: openssl rand -hex 64
|
||||
# Generate TOTP_VAULT_KEY: openssl rand -base64 32
|
||||
#
|
||||
# Store the actual values in the adapter env vars (never commit real secrets).
|
||||
# Apply with:
|
||||
# kubectl create secret generic plausible-env \
|
||||
# --from-literal=SECRET_KEY_BASE="$(openssl rand -hex 64)" \
|
||||
# --from-literal=TOTP_VAULT_KEY="$(openssl rand -base64 32)" \
|
||||
# -n analytics --dry-run=client -o yaml | kubectl apply -f -
|
||||
#
|
||||
# This placeholder file is for documentation; the real secret is created
|
||||
# out-of-band and is not stored in git.
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: plausible-env
|
||||
namespace: analytics
|
||||
type: Opaque
|
||||
stringData:
|
||||
SECRET_KEY_BASE: REPLACE_WITH_OUTPUT_OF_openssl_rand_hex_64
|
||||
TOTP_VAULT_KEY: REPLACE_WITH_OUTPUT_OF_openssl_rand_base64_32
|
||||
@@ -0,0 +1,58 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: website
|
||||
namespace: using-cash
|
||||
labels:
|
||||
app: website
|
||||
spec:
|
||||
replicas: 2
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 0
|
||||
maxSurge: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: website
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: website
|
||||
spec:
|
||||
containers:
|
||||
- name: website
|
||||
# Image updated by CI: kubectl set image deployment/website website=<registry>/<sha>
|
||||
image: git.falkvinge.net/using-cash/website:latest
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 32Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 64Mi
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 8080
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 8080
|
||||
initialDelaySeconds: 2
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 3
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: false
|
||||
runAsNonRoot: true
|
||||
runAsUser: 101
|
||||
securityContext:
|
||||
fsGroup: 101
|
||||
@@ -0,0 +1,90 @@
|
||||
---
|
||||
# Main ingress: using.cash (apex)
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: website
|
||||
namespace: using-cash
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- using.cash
|
||||
secretName: using-cash-tls
|
||||
rules:
|
||||
- host: using.cash
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: website
|
||||
port:
|
||||
number: 80
|
||||
---
|
||||
# www redirect: www.using.cash → using.cash
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: website-www-redirect
|
||||
namespace: using-cash
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
# Permanent redirect www → apex
|
||||
nginx.ingress.kubernetes.io/permanent-redirect: "https://using.cash$request_uri"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- www.using.cash
|
||||
secretName: using-cash-www-tls
|
||||
rules:
|
||||
- host: www.using.cash
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: website
|
||||
port:
|
||||
number: 80
|
||||
---
|
||||
# app.using.cash — DNS slot reserved for future product app.
|
||||
# This ingress intentionally serves no content (503) so the subdomain
|
||||
# is owned and won't collide when the product app launches.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: app-placeholder
|
||||
namespace: using-cash
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/default-backend: "website"
|
||||
nginx.ingress.kubernetes.io/custom-http-errors: "503"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- app.using.cash
|
||||
secretName: using-cash-app-tls
|
||||
rules:
|
||||
- host: app.using.cash
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: website
|
||||
port:
|
||||
number: 80
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: using-cash
|
||||
labels:
|
||||
app.kubernetes.io/managed-by: kubectl
|
||||
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: website
|
||||
namespace: using-cash
|
||||
labels:
|
||||
app: website
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: website
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 8080
|
||||
protocol: TCP
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Next.js static export — trailing slash pages live at /page/index.html
|
||||
location / {
|
||||
try_files $uri $uri/ $uri.html $uri/index.html =404;
|
||||
}
|
||||
|
||||
# Long-lived cache for immutable assets (Next.js _next/static)
|
||||
location /_next/static/ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Long-lived cache for other static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|webp|avif|svg|ico|woff2|woff|ttf|otf)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
|
||||
# Plausible analytics — no cross-origin block needed (script loaded from stats.using.cash)
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
|
||||
gzip_min_length 1024;
|
||||
}
|
||||
Submodule
+1
Submodule using-cash-spike added at faa10a228c
Reference in New Issue
Block a user