Pi-hole
Pi-hole provides DNS with network-wide ad blocking for the homelab. This page documents the in-cluster Pi-hole, which runs in k3s with a dedicated IP (192.168.1.21) assigned by kube-vip.
Role: secondary resolver (DNS2). This
192.168.1.21instance is the in-cluster secondary to the primary hardware Pi-hole at192.168.1.60. It is kept in sync (blocklists and local*.local.spaelling.xyzrecords) by a per-pod nebula-sync sidecar — see DNS redundancy for the architecture and full apply steps. Before adding it to DHCP, make sure the sync is working so it is a true equivalent of the primary.
The deployment uses the pihole-kubernetes classic manifests.
Install
Apply the kube-vip ConfigMap so Pi-hole gets its dedicated IP, then create the namespace and deploy:
kubectl apply -f kubevip-configmap.yaml
kubectl create namespace pihole
# One shared web/API password: generated once, used by both secrets so the
# nebula-sync sidecar can always authenticate against its local Pi-hole.
# (-base64 24 stays on one line; larger values wrap and embed a newline.)
PIHOLE_WEBPASSWORD=$(openssl rand -base64 24)
kubectl create secret -n pihole generic pihole-webpassword --from-literal="password=$PIHOLE_WEBPASSWORD"
# nebula-sync credentials (the primary entry is set from the gateway token below; the localhost replica uses the generated password):
kubectl create secret -n pihole generic nebula-sync-credentials --from-literal="primary=set-by-the-gateway-section-below" --from-literal="replicas=http://localhost|$PIHOLE_WEBPASSWORD"
kubectl apply -f pihole.yaml
kubevip-configmap.yaml is in the k3s/kubevip directory. The generated password is stored as a Kubernetes secret — retrieve it later with kubectl get secret -n pihole pihole-webpassword -o jsonpath='{.data.password}' | base64 --decode. The nebula-sync-credentials secret and the sync design are covered in DNS redundancy.
Verify DNS is working
Once pods are running, test that Pi-hole is answering DNS queries on its dedicated IP:
tcping -f 4 -t 5 192.168.1.21 53
nslookup google.com 192.168.1.21
Both should succeed. If nslookup returns an answer from 192.168.1.21, Pi-hole is operational.
Expose the admin UI
Apply the ingress for the primary Pi-hole instance:
kubectl apply -f pihole-0-ingress.yaml
This creates a Traefik IngressRoute for the Pi-hole web UI.
Single sign-in through Authentik
pihole.local.spaelling.xyz is protected by the Authentik forward-auth (../../authentik/authentik.md). Pi-hole v6 cannot accept an external sign-in, and its own 2FA blocks an empty web password, so the Ingress sends traffic to pihole-sso-proxy (pihole-sso-proxy.yaml, script pihole-sso-proxy.py) rather than to Pi-hole directly. The proxy signs in to the primary Pi-hole API with an application password and passes the resulting session on every request, so the Pi-hole login page and 2FA prompt do not appear after the passkey. Every client shares that one session, and the proxy renews it when Pi-hole drops it. Pi-hole's sign-out button has no effect. Only Traefik pods can reach the proxy port 8080 (a NetworkPolicy; the gateway port 8081 has its own policy below), and 192.168.1.60 itself still shows the login page. The application password signs in there too, without the 2FA code and without Authentik, so keep it in the vault and in the Secret only.
Create the Secret from a Pi-hole application password (an app password signs in without the 2FA code; the web password does not), stored as pihole_api_key on the Homelab vault item. The value goes in through standard input, never on a command line:
openssl rand -base64 24 | tr -d '/+=\n' | kubectl create secret generic pihole-sync-gateway -n traefik --from-file=token=/dev/stdin
PIHOLE_KEY='pass://CM-Homelab/Homelab/pihole_api_key' pass-cli run -- sh -c 'printf %s "$PIHOLE_KEY" | kubectl create secret generic pihole-sso-proxy -n traefik --from-file=password=/dev/stdin'
kubectl create configmap pihole-sso-proxy -n traefik --from-file=pihole-sso-proxy.py
kubectl apply -f pihole-sso-proxy.yaml
kubectl rollout status deploy/pihole-sso-proxy -n traefik
kubectl apply -f pihole-0-ingress.yaml
Check it: curl -skI https://pihole.local.spaelling.xyz/admin/ answers 302 to Authentik, and after the passkey the dashboard opens without the Pi-hole password prompt. If the page answers 502, read kubectl logs deploy/pihole-sso-proxy -n traefik: a failed sign-in is logged with Pi-hole's HTTP status (401 means the app password is wrong; 429 means Pi-hole has no free session slots, which clear after 30 minutes) and is not retried for five seconds. After a proxy restart a tab that was open earlier gets a 401 on its next action; reload it.
After editing the script, update the ConfigMap and restart:
kubectl create configmap pihole-sso-proxy -n traefik --from-file=pihole-sso-proxy.py --dry-run=client -o yaml | kubectl apply -f -
kubectl rollout restart deploy/pihole-sso-proxy -n traefik
The proxy buffers nothing except small request bodies; requests with a chunked body are refused with 411.
Metrics
The proxy serves /metrics on port 8082 with pihole_up, pihole_domains_being_blocked, pihole_blocking_enabled and pihole_gravity_last_update_timestamp_seconds for the primary Pi-hole, read with the proxy's own session. The pihole ServiceMonitor in monitoring/prometheus/cluster-targets.yaml scrapes it, and only the Prometheus pod can reach the port (a NetworkPolicy). The Grafana alert group DNS fires on an empty blocklist, a Pi-hole that does not answer, blocking switched off, blocklists not rebuilt for 10 days, and repeated nebula-sync failures. The in-cluster replicas are not scraped. A proxy that was deployed before the metrics port existed needs kubectl apply -f pihole-sso-proxy.yaml as well as the ConfigMap update, so the Service port and the NetworkPolicy exist.
Read-only sync gateway
The same proxy has a second listener, the Service pihole-sync-gateway.traefik (port 80), that the nebula-sync sidecars use to read the primary. The Pi-hole application password stays in the proxy and the primary needs webserver.api.app_sudo on (Settings, Web interface / API, expert mode, "Permit app password to modify config"); without it the primary answers 403 to the Teleporter export and every sync fails. A sidecar signs in to the gateway with its own token (the Secret pihole-sync-gateway in traefik, the same value as the password part of primary in the Secret nebula-sync-credentials in pihole). The gateway forwards GET requests to /api/teleporter, /api/config, /api/info/, /api/stats/, /api/history and /api/dns/blocking, and one POST, /api/action/gravity (nebula-sync rebuilds gravity on the primary after a sync); everything else answers 403 and is logged. Homarr's Pi-hole card reads through the same gateway, so its blocking toggle does not work. A sidecar that starts before the NetworkPolicy has admitted its pod fails its first sync with connection refused and restarts once or twice before it succeeds; the sid header, X-FTL-SID header, cookie and query parameter are all accepted as the gateway session. Only pods in the pihole namespace and the Homarr pods can reach it (a NetworkPolicy).
Create the token Secret before applying pihole-sso-proxy.yaml (the first command in the block above), then point the sidecars at the gateway (the token never goes on a command line):
T=$(kubectl get secret pihole-sync-gateway -n traefik -o jsonpath='{.data.token}' | base64 -d)
printf '{"stringData":{"primary":"http://pihole-sync-gateway.traefik.svc.cluster.local|%s"}}' "$T" | kubectl patch secret nebula-sync-credentials -n pihole --patch-file=/dev/stdin
kubectl rollout restart statefulset/pihole -n pihole
Gateway sessions expire 30 minutes after their last use and sign-out ends them; after rotating the token run kubectl rollout restart deploy/pihole-sso-proxy -n traefik so sessions opened with the old token end too. A sync log line Sync failed ... 403 means the primary still has app_sudo off; 401 means the token in nebula-sync-credentials differs from the one in pihole-sync-gateway.
Check logs
# Latest logs from the primary instance
kubectl logs pihole-0 -n pihole
# Stream logs in real time
kubectl logs -f pihole-0 -n pihole
# Logs from all replicas simultaneously
kubectl logs -l app=pihole -n pihole --all-containers
# DNS query log (inside the pod)
kubectl exec -it pihole-0 -n pihole -- tail -f /var/log/pihole/pihole.log
Check rollout status
After making changes to the StatefulSet (e.g. updating the image or config), monitor the rollout:
kubectl rollout status statefulset pihole -n pihole
Troubleshooting: ads getting through (empty gravity)
If ads start appearing network-wide, the usual cause is not that Pi-hole has become too weak but that its blocklists have been wiped: the adlist set is empty, so the compiled blocklist (Pi-hole calls it gravity) has zero domains and there is nothing to block against. This happened on 2026-09-13 when a gravity database auto-restore on the primary came back with no adlists; blocking was still switched on, but only a few percent of queries were blocked and those were mostly iCloud Private Relay (mask.icloud.com), not ads.
Confirm it. In the admin UI the dashboard shows Domains on Adlists at or near 0, and Settings -> Lists is empty. Over the API, GET /api/info/ftl reports database.gravity: 0 and GET /api/lists returns an empty list.
Local DNS records are safe, so do not reach for a full restore. The local *.local.spaelling.xyz hosts and CNAMEs live in Pi-hole's DNS config, entirely separate from gravity, and survive an empty-gravity event untouched. A full older-version Teleporter restore would overwrite the whole config, including those local records, with whatever smaller set the backup happened to hold, so it can lose current local records while fixing the blocklist. Restore the blocklist on its own instead; it never touches local DNS.
Fix via the admin UI (simplest). Settings -> Lists, add the default blocklist https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts as a block list, then Tools -> Update Gravity. Gravity rebuilds to tens of thousands of domains and blocking resumes.
Fix via the API (scripted). First authenticate to get a session id, then send it as the X-FTL-SID header on each call. The add-list call takes type as a query parameter, not a body field; passing it only in the body fails with bad_request: Specify type parameter:
# Authenticate with the instance's app password; capture the session id.
SID=$(curl -sk -X POST "http://192.168.1.60/api/auth" \
-H 'Content-Type: application/json' \
-d '{"password":"<pihole app password>"}' | jq -r '.session.sid')
# Add the default blocklist (type is a QUERY parameter).
curl -sk -H "X-FTL-SID: $SID" -X POST \
"http://192.168.1.60/api/lists?type=block" \
-H 'Content-Type: application/json' \
-d '{"address":"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts","comment":"Pi-hole default blocklist","groups":[0],"enabled":true}'
# Rebuild gravity from the adlists.
curl -sk -H "X-FTL-SID: $SID" -X POST "http://192.168.1.60/api/action/gravity"
Verify. GET /api/info/ftl should show a non-zero database.gravity, and a live query is the real proof: nslookup doubleclick.net 192.168.1.60 returns 0.0.0.0 (blocked) while nslookup k3s.local.spaelling.xyz 192.168.1.60 still returns the real address (local DNS intact).
The cluster replicas heal themselves. Fix the primary (192.168.1.60) only. The per-pod nebula-sync sidecar pulls the primary's adlists and reruns gravity on each in-cluster replica on its 15-minute cycle (offset by pod index, see Nebula Sync), so DNS2 starts blocking within about sixteen minutes without any manual step. See DNS redundancy.