monitoring
Whole-cluster metrics: Prometheus + Grafana + node-exporter + kube-state-metrics, via
kube-prometheus-stack.
Two Argo apps, deliberately split:
| App | Source | What it is |
|---|---|---|
monitoring | upstream kube-prometheus-stack chart, apps/base/monitoring.yaml | The stack itself, configured through valuesObject |
monitoring-extras | this directory, apps/base/monitoring-extras.yaml | Static PVs + ServiceMonitors for things the chart knows nothing about |
They are split because the second depends on CRDs the first installs. One app would have to sync both in a single pass and would fail on first install; two apps let the second one retry.
Install
2026-10-31 — sealed secrets re-sealed. Everything sealed before the 2026-09-01 cluster rebuild is undecryptable (the old controller key was not restored).
grafana-admin-secretwas re-sealed with a fresh random password — read it withkubectl -n monitoring get secret grafana-admin-secret -o jsonpath='{.data.admin-password}' | base64 -dand store it in Proton Pass.grafana-oauth-secretwas re-sealed with the Google client secret (see "Google SSO").alertmanager-telegrammust be re-sealed with the real bot token before Alertmanager can start.
1. Create the data directories on node1, with the UIDs each image actually runs as:
sudo mkdir -p /srv/k8s-volumes/monitoring/{prometheus,grafana}
sudo chown -R 1000:2000 /srv/k8s-volumes/monitoring/prometheus
sudo chown -R 472:472 /srv/k8s-volumes/monitoring/grafana
2. Seal the Grafana admin credentials:
kubectl create secret generic grafana-admin-secret \
--namespace monitoring \
--from-literal=admin-user=admin \
--from-literal=admin-password="$(openssl rand -base64 24)" \
--dry-run=client -o yaml \
| kubeseal --controller-namespace sealed-secrets \
--controller-name sealed-secrets-controller \
--format yaml \
> infra/monitoring/grafana-admin-sealedsecret.yaml
⚠️ Record the password before you lose it — a SealedSecret cannot be read back out of Git.
The secret must exist in the monitoring namespace, which the monitoring app creates. On a
cold install: sync monitoring first, then seal, then sync monitoring-extras. Grafana
CrashLoops until the secret is there.
3. Seal the remaining secrets — alertmanager-telegram (see "Delivering alerts") and
grafana-oauth-secret (see "Google SSO"). All three sealed secrets live in this directory and
are delivered by the monitoring-extras app.
4. Register BOTH Argo apps. apps/base/ is not driven by an app-of-apps in this repo — the
manifests there are applied by hand:
kubectl apply -f apps/base/monitoring.yaml
kubectl apply -f apps/base/monitoring-extras.yaml # ← easy to forget, and everything below depends on it
⚠️ Forgetting monitoring-extras is the failure mode to know. Everything in this directory —
StorageClasses, PVs, both SealedSecrets, ServiceMonitors, alert rules — is delivered by that
app and by nothing else. Skip it and you get three symptoms that look unrelated:
| Symptom | Actual cause |
|---|---|
Grafana pod Pending forever | its PVC has no PV to bind |
Alertmanager stuck Init:0/1 | waiting on the alertmanager-telegram secret mount |
No Prometheus pod at all, CR Reconciled=False | storage class "monitoring-prometheus-local" does not exist |
| Grafana up but SSO button 500s | grafana-oauth-secret not mounted |
Check with kubectl get app monitoring-extras -n devops before debugging anything else.
Grafana lands at https://grafana.tiktuzki.com (ingress class public, same path as
argocd/keycloak/kafka-ui).
What gets scraped
Both Patroni HA Postgres clusters — postgresql-ha (running) and timescaledb-ha (chart kept,
not deployed) — are scraped by servicemonitors-patroni-ha.yaml. Every series carries a
pg_cluster label; the alerts (alerts-patroni-ha.yaml) aggregate by it and the dashboard
(Patroni HA Postgres, uid patroni-ha) has a Cluster picker. Patroni, pgdog and HAProxy
expose metrics natively; Postgres internals come from the postgres_exporter sidecar:
| Target | Port | Series worth knowing |
|---|---|---|
| Patroni (all 3 pods) | :8008/metrics | patroni_primary, patroni_cluster_unlocked, patroni_xlog_replayed_location |
| pgdog | :9102/metrics | clients, servers, pools — pool waiters and checkout time |
| HAProxy | :7000/metrics | haproxy_backend_active_servers{proxy="primary"} |
| postgres_exporter (sidecar, all 3 pods) | :9187/metrics | pg_replication_slot_*, pg_replication_slots_pg_wal_lsn_diff, pg_settings_max_slot_wal_keep_size_bytes |
patroni_cluster_unlocked == 1 means nobody holds the leader lock — writes are failing
cluster-wide. It is the first alert worth writing.
haproxy_backend_active_servers{proxy="primary"} == 0 means no node passes Patroni's
/primary check, so everything on :5433 (Debezium, migrations) has nowhere to go.
⚠️ pgdog exports unprefixed metric names — clients, servers, pools, not
pgdog_clients. Always qualify in PromQL: clients{pg_cluster="postgresql-ha", job=~".+-pgdog"}.
A bare clients will silently pick up anything else that exports the same name.
Not covered yet
- Postgres query-level metrics (table sizes, bloat, slow queries): the
postgres_exportersidecar runs only its default collectors — replication slots, WAL, settings — notpg_stat_statementsor per-table stats. - Kafka needs a JMX exporter sidecar.
- Alert delivery. Alertmanager is running and routing, but every route currently ends at
the
nullreceiver — see "Alerting" below.
Alerting
Rules: alerts-patroni-ha.yaml (20 alerts, every one per pg_cluster), alerts-linkerd.yaml, and
alerts-backup.yaml (8: off-site upload, run completeness, WAL-G base backups and archiving — see
docs/operations/backup-restore/dr-plan.md). Routing: the alertmanager block in
apps/base/monitoring.yaml.
Every expression was written against metric names read off the live endpoints, then checked
with promtool check rules. Do the same when adding rules — Patroni and pgdog both export
names that are easy to guess wrong (patroni_xlog_replayed_location, not ..._replay_lsn;
cl_waiting, not pgdog_clients_waiting).
Node, pod, PV and kubelet alerts are not here — kube-prometheus-stack ships those.
| Severity | Alert | Fires when |
|---|---|---|
| critical | PatroniClusterUnlocked | No leader lock held — whole cluster is read-only |
| critical | PatroniNoPrimary | No node reports itself primary |
| critical | PatroniSplitBrain | More than one node claims primary |
| critical | HAProxyNoPrimaryBackend | :5433 has no writable node — Debezium/migrations dead |
| critical | PgdogDown | Applications have no database, however healthy the cluster is |
| warning | PatroniNodeDown | Postgres down on a node |
| warning | PatroniReplicaNotStreaming | Replica up but not replaying — not a failover candidate |
| warning | PatroniReplicationLagHigh | >16MB behind (the point pgdog bans it from reads) |
| warning | HAProxyNoReplicaBackends | :5434 has nowhere to send reads |
| warning | PatroniDcsUnreachable | Patroni can't reach the k8s API — ~20s before the lease expires |
| warning | PatroniFailsafeModeActive | Leader kept primary only by failsafe — the k8s API has been unreachable for 2m |
| warning | PgdogClientsWaiting | Pool exhausted, clients queuing |
| warning | PgdogServerErrors | Backend connections erroring |
| warning | PatroniPendingRestart | Config in the DCS ≠ config actually running |
| warning | PatroniPaused | Auto-failover left disabled for 30m |
| warning | PostgresLogicalSlotInactive | A logical slot has no consumer — CDC stopped, WAL piling up |
| warning | PostgresReplicationSlotRetainingWAL | A slot pins >4GB of WAL on the 20Gi volume |
| critical | PostgresReplicationSlotLost | A slot was invalidated — Debezium must re-snapshot |
| warning | PostgresSlotWalKeepSizeUnbounded | max_slot_wal_keep_size = -1, nothing stops a full volume |
| info | PatroniFailoverOccurred | Timeline advanced — a promotion happened |
Routing decisions
The inhibit rule is the important one. A failover sets off the whole redundancy group at
once — replicas stop streaming, lag spikes, HAProxy loses backends, pgdog logs errors. None of
that is separately actionable while there is no leader, so PatroniClusterUnlocked /
PatroniNoPrimary suppress all of it. You get "no leader", not six symptoms of the same event.
Watchdog is routed to null on purpose. It fires constantly by design — it is the dead
man's switch proving the alert pipeline is alive. It is only useful pointed at a service
watching for its absence (healthchecks.io, Cronitor). Anywhere else it is noise.
repeat_interval is 12h, not the 4h default. Re-notifying every 4h about something you
already know is how you learn to mute the channel.
Delivering alerts
Delivery is Telegram. Two steps, both required before the app will sync cleanly.
1. Create the bot and seal its token. Talk to @BotFather,
/newbot, keep the token:
kubectl create secret generic alertmanager-telegram \
--namespace monitoring \
--from-literal=token='<bot-token-from-BotFather>' \
--dry-run=client -o yaml \
| kubeseal --controller-namespace sealed-secrets \
--controller-name sealed-secrets-controller \
--format yaml \
> infra/monitoring/alertmanager-telegram-sealedsecret.yaml
The token is read via bot_token_file, so it never appears in monitoring.yaml, in Git, or in
kubectl get alertmanager -o yaml. The operator mounts it at
/etc/alertmanager/secrets/alertmanager-telegram/token.
2. Set the chat ID. Send any message to the bot (or add it to a group and post there), then:
curl -s "https://api.telegram.org/bot<TOKEN>/getUpdates" | jq '.result[-1].message.chat.id'
Put that number in chat_id in apps/base/monitoring.yaml. Group chats are negative
(-1001234567890); a direct message is positive. It is an integer — do not quote it.
⚠️ chat_id ships as 0, which is invalid. Alertmanager will CrashLoop with
missing chat_id on telegram_config until you replace it. That is deliberate: a loud failure at
config load beats the alternative, where a plausible-but-wrong ID lets Alertmanager start and
then drop every alert on a Telegram 400. Prometheus and Grafana are unaffected either way.
Verify before syncing:
# extract the rendered config and check it
amtool check-config <(...) # SUCCESS expected: 2 receivers, 1 inhibit rule
On the HTML formatting: parse_mode: HTML makes Telegram reject the entire message with a
400 if the text contains an unescaped <, > or & — and Alertmanager does not retry a 400,
so the alert is silently dropped. No current rule annotation contains those characters (checked),
but keep it that way when adding rules, or set parse_mode: "" to make it structurally
impossible.
Testing the pipeline end to end
Fire a synthetic alert straight at Alertmanager, bypassing Prometheus:
kubectl -n monitoring port-forward svc/monitoring-kube-prometheus-alertmanager 9093 &
curl -XPOST http://localhost:9093/api/v2/alerts -H 'Content-Type: application/json' -d '[{
"labels": {"alertname":"TestAlert","severity":"critical"},
"annotations": {"summary":"pipeline test","description":"delete me"}
}]'
A Telegram message should arrive within group_wait (30s). To test a real rule instead, delete
the leader pod and wait for PatroniFailoverOccurred — see charts/postgresql-ha/README.md.
Google SSO
Grafana signs users in with Google (auth.google in apps/base/monitoring.yaml, OAuth client
tik-k8s in Google Cloud Console). It is the only interactive login: the username/password
form is disabled (disable_login_form: true).
Break-glass (Google down, client deleted, secret drifted): set disable_login_form: false,
commit, kubectl apply -f apps/base/monitoring.yaml, log in as the local admin
(grafana-admin-secret), fix the problem, then set it back to true.
HTTP basic auth (auth.basic) stays on: both k8s-sidecars reload provisioned dashboards and
datasources through /api/admin/provisioning/*/reload with the admin credentials. So the admin
password still works against the API — keep it long and random, and rotate it by re-sealing
grafana-admin-secret.
Keycloak is not deployed; the old auth.generic_oauth block is in git history if it ever is.
Who gets in
Authorization is an email allow-list, deny by default:
role_attribute_path: "email_verified && contains(['[email protected]', '[email protected]'], email) && 'Admin'"
role_attribute_strict: true
A listed, verified address becomes Admin; anyone else, an unverified address, or a listed
address with different capitalisation is refused (role_attribute_strict), not made Viewer.
There is no allowed_domains because these are personal Gmail accounts — any Google account can
reach the consent screen, so the allow-list is the only gate. Never add a trailing || 'Viewer':
that would let every Google account on earth into Grafana.
To add a person: append their address to the list, commit, kubectl apply -f apps/base/monitoring.yaml.
To give someone a lower role, extend the expression, e.g.
contains([...admins], email) && 'Admin' || contains([...viewers], email) && 'Viewer'.
Roles are re-synced on every login (skip_org_role_sync: false), so removing an address from the
list demotes them on their next login. Their existing session lasts until it expires — delete
the user in Grafana (Administration → Users) to cut access immediately.
Google Cloud Console settings
| Setting | Value |
|---|---|
| Application type | Web application |
| Authorised redirect URI | https://grafana.tiktuzki.com/login/google (must match exactly) |
| Authorised JavaScript origin | https://grafana.tiktuzki.com |
| Client ID | in apps/base/monitoring.yaml (not secret) |
| Client secret | pass://athena/tik-k8s-google-auth/Secret |
Sealing the client secret
Never print or paste the value — inject it from Proton Pass:
printf 'GOOGLE_CLIENT_SECRET=pass://athena/tik-k8s-google-auth/Secret\n' > /tmp/g.env
pass-cli run --env-file /tmp/g.env -- sh -c \
'kubectl create secret generic grafana-oauth-secret -n monitoring \
--from-literal=client-secret="$GOOGLE_CLIENT_SECRET" --dry-run=client -o yaml' \
| kubeseal --controller-namespace sealed-secrets --controller-name sealed-secrets-controller \
--format yaml > infra/monitoring/grafana-oauth-sealedsecret.yaml
rm /tmp/g.env
Mounted at /etc/secrets/oauth/client-secret and read via Grafana's $__file{} expansion, so
the secret never reaches grafana.ini, the rendered ConfigMap, or Git. Re-seal whenever the
secret is rotated in Google Cloud Console.
Troubleshooting
| Symptom | Cause |
|---|---|
Google: Error 400: redirect_uri_mismatch | Redirect URI in Google Cloud Console ≠ https://grafana.tiktuzki.com/login/google |
| Grafana: "Login failed … role" after Google consent | Address not on the allow-list (or different capitalisation) — working as intended |
Grafana: invalid_client / 500 after consent | grafana-oauth-secret stale or not mounted — re-seal and check monitoring-extras |
| Locked out entirely | Break-glass above: re-enable the login form and use the local admin |
Prometheus and Alertmanager
Neither has any authentication, and neither is behind SSO — because neither is exposed. Both
are ClusterIP-only; reach them with kubectl port-forward. If you ever add an Ingress for
them, put oauth2-proxy in front — they have no auth of their own, and the Alertmanager UI can
silence every alert in the cluster.
Decisions worth knowing
microk8s control-plane scrape jobs are off. kubeControllerManager, kubeScheduler,
kubeProxy and kubeEtcd run as host processes bound to localhost on microk8s, not as pods
with the labels the chart's ServiceMonitors expect. Left enabled they sit permanently DOWN and
fire *Down alerts forever, which is how you learn to ignore alerts.
serviceMonitorSelectorNilUsesHelmValues: false is load-bearing. Without it the Prometheus
CR only selects ServiceMonitors carrying this release's labels, so everything in this directory
is ignored — no error, no warning, targets just never appear.
ServerSideApply=true is required, not stylistic. The Prometheus CRDs are hundreds of KB;
a client-side apply stuffs the whole manifest into the last-applied-configuration annotation
and blows the 256KB limit with metadata.annotations: Too long.
Grafana's PV is a scratchpad. Dashboards built in the UI survive a restart, but anything you want reproducible belongs in Git as a provisioned dashboard ConfigMap.
Resource budget
Sized for a single 15Gi node that was already ~78% committed on limits before this landed:
| requests | limits | |
|---|---|---|
| Prometheus | 200m / 512Mi | 1 / 1536Mi |
| Grafana | 50m / 128Mi | 300m / 256Mi |
| kube-state-metrics | 20m / 64Mi | 200m / 128Mi |
| node-exporter | 20m / 32Mi | 100m / 64Mi |
| operator | 50m / 64Mi | 200m / 128Mi |
≈2.1Gi of limits, taking node1 to roughly 13.9Gi of 15.3Gi. That is tight. Watch
prometheus_tsdb_head_series — past ~500k, raise Prometheus's limit before the OOM killer
finds it, or cut retention.