Skip to content

About

Self-hosted Raspberry Pi homelab network stack using Tailscale as overlay VPN, Pi-hole as centralized DNS, and exit-node routing for secure remote access.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Homelab Logo

Homelab Stack

Containerized Network & Monitoring Stack on Low-Resource Hardware

Overview • Stack • Architecture • Monitoring • Design • Security


Overview

Homelab built on a Raspberry Pi 2B running as an always-on infrastructure node. The Pi handles DNS filtering, overlay networking, containerized services, lightweight NAS storage, and infrastructure monitoring, all without exposing any public ports.


Stack

Hardware

  • Raspberry Pi 2B (1GB RAM, always-on)
  • NVMe drive (container volumes and persistent data)

Networking

  • Tailscale (WireGuard-based mesh VPN)
  • Subnet router for 192.168.1.0/24
  • Exit node capability for full-tunnel routing
  • Split DNS routing for internal services

Private HTTPS access

Internal services are exposed through a Caddy reverse proxy using private HTTPS.

DNS resolution is handled by Pi-hole with the home.arpa namespace:

  • grafana.home.arpa
  • 4get.home.arpa
  • portainer.home.arpa
  • prometheus.home.arpa

Pi-hole resolves service names to the Raspberry Pi Tailscale address, and Caddy routes HTTPS requests to the correct local Docker service.

Caddy uses an internal CA for TLS certificates trusted by local clients.


Internal DNS

Services use the reserved home.arpa namespace.

Ansible provisions Pi-hole and Unbound, internal DNS names, upstream resolution, web settings and required blocklists through ops/pihole.

DNS lookup:

Client → Tailscale DNS → Pi-hole → Raspberry Pi Tailscale IP

Examples:

Containers

  • Docker
  • Portainer (management UI)

Monitoring components

  • Prometheus + Node Exporter → Grafana
  • Tracks CPU, memory, disk, network, and load metrics

Services

  • Pi-hole (DNS filtering + query logging)
  • 4get (self-hosted search frontend)

Resilience

  • log2ram (optional; reduces SD card writes by buffering logs in RAM)
  • Watchdog (automatic reboot on system hang)

Provisioning

  • Ansible (automated setup and deployment)

Incidents & Troubleshooting

Incident Root Cause Doc
Host unreachable, Docker/SSH/Tailscale unavailable, metrics curl failures NVMe USB power/bridge instability causing unclean shutdown and service loss nvme-usb-power-instability.md
System instability, DNS failures, container hangs Swap thrashing on SD card under memory pressure swap-migration.md
Docker containers unresponsive despite showing as Up Memory pressure causing inconsistent Docker state docker-unresponsive-incident.md

Getting Started

Configuration

Before deploying, create your local Ansible config from the example:

cp group_vars/all.yml.example group_vars/all.yml

Then edit group_vars/all.yml to match your setup:

user: pi
compose_path: /home/pi/homelab-stack
compose_file: docker-compose.yml

nvme_uuid: YOUR_NVME_FILESYSTEM_UUID
docker_data_root: /mnt/nvme/docker
service_bind_address: 127.0.0.1
enable_log2ram: false

tailscale_authkey: XXXXX
tailscale_hostname: homelab-pi
tailscale_advertise_routes: 192.168.1.0/24
tailscale_advertise_exit_node: true

With healthchecks enabled, set nvme_uuid to the filesystem UUID reported by findmnt -n -o UUID --mountpoint /mnt/nvme. If the local DNS prerequisites are still being set up, set install_homelab_healthcheck: false until they are ready.

You can generate a Tailscale auth key at login.tailscale.com/admin/settings/keys. The auth key can also be supplied with the TAILSCALE_AUTHKEY environment variable for the first provisioning run.

By default, the playbook binds Docker-published backend ports to 127.0.0.1 and binds Caddy's HTTPS listener to the node's Tailscale IPv4 address. This prevents clients from bypassing Caddy while keeping service access inside the tailnet.

log2ram is disabled by default because it is not supplied by every Raspberry Pi OS package source. To enable it, first configure a trusted repository that provides the log2ram package, then set enable_log2ram: true. The playbook does not add a Debian repository to Raspberry Pi OS.

Prometheus config and alert rules live in prometheus/ and are copied by the playbook.

Pull requests are checked by the validation workflow in .github/workflows/validate.yml. It validates shell scripts, YAML, Docker Compose, Ansible syntax, Prometheus configuration, and the host healthcheck test suite. See validation-ci.md.

Container data is stored under docker_data_root, so Caddy, Grafana, Prometheus, and Portainer state can live on NVMe instead of the SD card. Volume permissions are set automatically by the playbook. No manual chown is required.

Memory limits are set per container in docker-compose.yml and tuned for the Pi 2B (1GB RAM). Adjust mem_limit values if running on different hardware.

External images are pinned to explicit ARMv7-compatible releases to keep deployments reproducible. The stack currently uses Caddy 2.11.4, Prometheus 3.5.5 LTS, Node Exporter 1.12.1, Grafana 13.2.1-slim, and Portainer 2.39.7-linux-arm-alpine. Review and test version updates deliberately rather than tracking mutable latest tags.

Healthchecks are configured for Caddy, Prometheus, Node Exporter, Grafana, and Portainer. Check their status after deployment with:

docker compose ps

After provisioning, the host-level homelab-healthcheck.timer checks containers, local DNS, the NVMe mount, SSH, and Tailscale. It attempts service recovery and saves bounded diagnostic logs, including container logs before restarts. Containers that Docker reports as starting can finish starting before their HTTP probes count towards recovery. A critical container that stays unhealthy after a restart attempt can still count towards the host reboot threshold.

Eligible host reboots share a persistent cooldown of 10, 20, then 30 minutes after boot. Limits apply per recovery episode, and 30 minutes of continuously healthy checks reset the counters. Storage faults such as ext4 errors or a read-only mount block automatic reboots. See the healthcheck guide for limits, setup, and diagnostics.

Thermal and NVMe SMART samples are logged by /etc/systemd/system/homelab-thermal-monitor.timer and exported to Prometheus through Node Exporter's textfile collector. Logs are kept under /var/log/homelab-thermal/thermal.log; source files live under ops/thermal-monitor/.

The 4get scraper service is behind the optional Compose profile. To include it, run Compose with --profile optional.

Phone photo backups

FolderSync uploads phone photos and videos over encrypted SFTP to the photo-backup-sftp container on port 2222. Uploads are stored on the NVMe; the container has a 128 MiB memory limit and key-only authentication. See photo backup setup and the data flow for provisioning and phone configuration. Keep uploads one-way, disable remote deletion, and retain another independent backup before deleting originals or cloud copies.

Automated provisioning (Ansible)

Once configured, provision and deploy everything with a single command:

ansible-playbook -i inventory.ini playbook.yml

The playbook handles installing Docker, Docker Compose, Tailscale, Samba, and SMART tooling. It configures Tailscale authentication, IPv4 and IPv6 forwarding for advertised routes, the hardware watchdog, and optional log2ram. It copies the Prometheus configuration and deploys the container stack. The host healthcheck timer is enabled at the end of provisioning when configured. The playbook also installs the thermal monitor.

After the first Tailscale run, approve the advertised subnet route and exit node in the Tailscale admin console if required by your tailnet policy.

Manual deployment

If Docker is already set up, bring up the stack directly:

cp .env.example .env
$EDITOR .env
docker compose up -d

For manual deployment, keep SERVICE_BIND_ADDRESS=127.0.0.1 and set TAILSCALE_IP in .env to the output of tailscale ip -4. Persistent data is stored under DOCKER_DATA_ROOT from .env.

Trust the private CA

Caddy issues certificates from its private internal CA. After the first start, copy the generated root certificate out of the container:

docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt ./caddy-root.crt

Import that certificate into the operating system or browser trust store, then verify the connection:

curl --cacert ./caddy-root.crt https://grafana.home.arpa

Architecture

The Pi serves as subnet router, exit node, DNS server (Pi-hole), reverse proxy (Caddy), Docker host, and monitoring node.

flowchart LR
    Client[Remote client<br/>Laptop or phone]

    subgraph Pi[Raspberry Pi 2B]
        TS[Tailscale<br/>subnet router and exit node]
        DNS[Pi-hole and Unbound<br/>via Ansible]
        Caddy[Caddy HTTPS<br/>internal CA]
        Apps[Docker services<br/>Grafana, Prometheus, Node Exporter, Portainer<br/>4get optional]
        Host[Host services<br/>Samba, log2ram, watchdog]
    end
    LAN[Home LAN<br/>192.168.1.0/24]
    Internet[Internet]

    Client -->|Encrypted overlay| TS
    TS -->|DNS query for *.home.arpa| DNS
    DNS -.->|Returns Pi Tailscale IP| Client
    TS -->|HTTPS| Caddy
    Caddy -->|Loopback-only backends| Apps
    TS -->|Subnet route| LAN
    TS -->|Exit-node traffic| Internet
Loading

Traffic flow

DNS lookup:    Client → Tailscale DNS → Pi-hole → Raspberry Pi Tailscale IP
HTTPS request: Client → Tailscale overlay → Caddy → Docker service

Application and monitoring services run in Docker. Tailscale, Samba, the hardware watchdog, optional log2ram, and the current Pi-hole/Unbound setup run on the host. No router port forwarding is required; remote HTTPS access is bound to the Tailscale interface.


Monitoring

Metrics pipeline: Node Exporter → Prometheus → Grafana

Prometheus scrapes host-level metrics from Node Exporter at regular intervals. Grafana provides dashboards for tracking resource usage and identifying bottlenecks on constrained hardware.

Basic Prometheus alert rules are included for unreachable Node Exporter, high memory usage, swap usage, low disk space, and sustained load.

The GitHub Actions badge update workflow runs through the private homelab network using Tailscale, internal DNS resolution, and Caddy HTTPS validation.

See GitHub Actions Metrics Pipeline for the complete architecture and security model.


Network Behavior

Normal operation: Devices connect via Tailscale mesh. Traffic is peer-to-peer where possible. DNS queries go through Pi-hole.

Restricted networks (e.g. university Wi-Fi): Exit node is enabled, routing all traffic through the Pi. DNS filtering stays active.

No router port forwarding is required or expected. Remote access is handled through Tailscale, Caddy listens on the Tailscale address, and container backend ports are bound to loopback by default when deployed with Ansible.


Design Rationale

No port forwarding and no public-facing services. The overlay VPN handles remote access, Caddy is the only HTTPS entry point, and application backends remain on loopback. Docker provides service isolation and portability, while Portainer is treated as a privileged administration component because it can access the Docker socket. Prometheus + Grafana provide system visibility, optional log2ram can reduce SD card wear, and the hardware watchdog provides automatic recovery from hangs. Ansible keeps the setup reproducible and version-controlled.


Threat Model

Threat Mitigation
Automated internet scans No public inbound ports
Open port exposure Overlay VPN (Tailscale) for all access
Unencrypted traffic on public Wi-Fi Exit node + WireGuard encryption
DNS tracking / malicious domains Pi-hole DNS filtering
Container breakout / Docker socket abuse Loopback-only backends, tailnet-restricted management access, and explicit treatment of Portainer as a privileged component
Management plane exposure Bind Caddy to the Tailscale IP and keep backend services on loopback

Limitations

  • Pi 2B: constrained CPU and 1GB RAM
  • USB 2.0 bottleneck for NVMe storage
  • Single point of failure (no redundancy)
  • Dependent on Tailscale's coordination server
  • Not suitable for compute-heavy workloads
  • Portainer requires Docker socket access, which should be treated as highly privileged
  • DNS deployment requires outbound recursive DNS access and successful blocklist downloads
  • The local fourget-armhf image must be built separately before enabling the optional profile

TODO

  • Container memory limits (mem_limit / --memory)
  • NVMe-backed container data paths
  • Prometheus alert rules
  • Tailscale subnet route / exit node provisioning
  • Provision phone photo intake with FolderSync and containerized SFTP
  • Private HTTPS reverse proxy with Caddy
  • Internal DNS with Pi-hole + home.arpa
  • NAS backup automation
  • Expand homelab with an additional node (offload heavy services)
  • Infrastructure as Code (Ansible / Docker Compose versioning)

About

Self-hosted Raspberry Pi homelab network stack using Tailscale as overlay VPN, Pi-hole as centralized DNS, and exit-node routing for secure remote access.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages