Home Assistant K3s Integration

The deployment of Home Assistant within a Kubernetes environment, specifically utilizing the lightweight K3s distribution, represents a significant shift in how home automation is managed. Home Assistant serves as a robust, open-source alternative to proprietary ecosystems like Ring or Apple HomeKit, which often impose restrictive boundaries on the hardware and software that can control a smart home. While the standard recommendation for Raspberry Pi users is the Home Assistant OS (HAOS), this approach requires dedicating an entire physical device to a single application. Given that Home Assistant is not particularly resource-intensive, allocating a full Raspberry Pi exclusively to this purpose is often viewed as an inefficient use of hardware, especially for users who are already hosting other side projects or services. Integrating Home Assistant into a K3s cluster allows for the consolidation of resources, enabling a single set of hardware to handle multiple containers and applications simultaneously.

Architectural Implications of Containerized Home Assistant

Running Home Assistant in K3s necessitates the use of the official Docker image, effectively transitioning the application from a dedicated OS environment to a containerized workload. This architectural shift introduces a critical trade-off regarding functionality. In a standard HAOS installation, users have access to "Add-ons," which are pre-packaged third-party services that integrate seamlessly with the core Home Assistant instance to extend its capabilities. These include essential tools such as databases, Dynamic DNS utilities, and specialized home automation software like Zigbee2MQTT.

When Home Assistant is deployed in K3s, these official Add-on features are not included by default. This means the convenient, one-click installation of Add-ons is replaced by the need for manual integration. For the end user, this implies a shift in operational complexity; instead of using the Home Assistant UI to add a service, the user must deploy these services as separate pods or containers within the K3s cluster and then configure the communication between them. Despite this loss of the "Add-on" abstraction, the underlying functionality remains available. Tools like Zigbee2MQTT can still be integrated manually within the K3s environment, allowing the user to maintain full control over their smart home ecosystem while leveraging the orchestration benefits of Kubernetes.

K3s Deployment Environments and Hardware Configurations

The deployment of Home Assistant on K3s can vary significantly based on the underlying hardware, ranging from ARM-based single-board computers to high-performance mini PCs.

Raspberry Pi Multi-Node Clusters

Some implementations utilize a 2-node K3s cluster running on Raspberry Pi hardware. This setup allows the user to self-host various side projects alongside Home Assistant. The primary motivation for this configuration is resource optimization. By avoiding the dedicated HAOS installation, the Raspberry Pi's CPU and RAM can be shared across multiple services, reducing the total number of physical devices required in the home lab.

High-Performance Mini PC Implementations

Alternatively, users may deploy K3s on mini PCs equipped with high-capacity RAM and fast NVMe drives. This approach addresses several common pain points associated with Raspberry Pi deployments, such as the inherent reliability concerns regarding SD card storage. A mini PC provides superior performance and stability as the number of sensors and devices in the home network increases. This environment also supports the creation of core platform services that facilitate broader application deployment and management.

ARM64 NVIDIA Jetson Nano Integration

A specialized implementation involves running a K3s cluster on a single ARM64 NVIDIA Jetson Nano device. This configuration is particularly useful for users requiring direct hardware interaction. In this scenario, the Home Assistant pod utilizes the official container image and resides in a simplified namespace for easier management. This hardware allows for specific integrations that require direct USB access, such as:

  • Bluetooth Integration: A Bluez service pod manages the Bluetooth interface, enabling communication with devices like Plant soil sensors via Bluetooth Low Energy (BLE) through a direct USB connection to the Jetson Nano.
  • Zigbee Integration: A Zigbee coordinator service handles communication with Zigbee-based sensors, also connected via USB to the Jetson Nano.

Technical Configuration and Deployment Process

Deploying Home Assistant into K3s requires a series of configuration steps, ranging from cluster initialization to the deployment of specific resources.

K3s Cluster Initialization

For those initializing a cluster, specifically on NVIDIA hardware, the installation can be triggered via a curl command that configures the server with specific flags to manage TLS and networking.

bash curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --tls-san SERVERIP --disable servicelb --disable traefik --write-kubeconfig-mode 644 --cluster-cidr=10.10.0.0/16" INSTALL_K3S_VERSION="v1.35.0+k3s1" sh -s -

Following the initial cluster setup, the NVIDIA device plugin must be deployed to ensure the cluster can manage GPU resources:

bash kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.10.0/nvidia-device-plugin.yml

Deployment Resource Definition

The core of the Home Assistant deployment is defined through a Kubernetes Deployment file. A critical decision in this process is the selection of the container image; users are advised against using the specific Raspberry Pi image and should instead use the general official image.

A standard deployment configuration looks as follows:

yaml apiVersion: apps/v1 kind: Deployment metadata: name: home-assistant spec: replicas: 1 selector: matchLabels: app: home-assistant template: metadata: labels: app: home-assistant spec: hostNetwork: true containers: - name: home-assistant image: ghcr.io/home-assistant/home-assistant:2023.1 ports: - containerPort: 8123 volumeMounts: - name: home-assistant-storage mountPath: /config env: - name: TZ value: Europe/London volumes: - name: home-assistant-storage persistentVolumeClaim: claimName: home-assistant-storage-claim

In this configuration, the hostNetwork: true setting is frequently used to resolve discoverability issues, although it introduces security implications by increasing the attack surface of the host.

Network Management and External Access

Making Home Assistant accessible both internally and externally requires a combination of ingress controllers and tunneling services.

Internal Routing and Traefik Ingress

K3s comes bundled with the Traefik ingress controller, which can be leveraged to proxy requests to the Home Assistant service. This is essential for eliminating the need to use port 8123 in the URL and for providing a professional hostname. By defining a custom IngressRouteTCP resource, users can proxy traffic and pass through TLS handshaking.

This allows the instance to be accessed via a standard HTTPS URL (e.g., https://hass.k3s.example.com) on port 443. The Home Assistant HTTP configuration must be adjusted to ensure it accepts these proxied requests. This setup ensures that regardless of which node the Home Assistant pod is running on within the cluster, the hostname remains consistent.

External Access and Cloudflare Tunnels

For secure public access without exposing the local network to the open internet, a Cloudflare tunnel can be deployed. This involves running a Cloudflare daemon within the cluster.

bash kubectl create -f ./cloudflare-daemon/deployment.yaml

The resolution of the domain is handled through Google Domain Servers and Cloudflare name server integration, providing a secure, encrypted tunnel from the external world to the internal K3s pod.

Load Balancing with MetalLB

To provide a stable IP for services within the cluster, MetalLB can be applied to manage LoadBalancer services.

bash kubectl apply -f

Solving Discoverability and Network Security

One of the most significant challenges when running Home Assistant in Kubernetes is device discovery. Many IoT devices rely on multicast or broadcast protocols to be found by Home Assistant.

The HostNetwork Dilemma

The most common solution is to set hostNetwork: true in the deployment specification. This allows the pod to share the network namespace of the host, making it appear as if Home Assistant is running directly on the hardware. While this resolves discovery issues immediately, it increases the attack surface. If the Home Assistant instance is compromised, the attacker has a more direct path to the host network.

Avahi-Daemon and the Reflector Solution

An alternative to using the host network is the installation of Avahi on each K3s node. Avahi allows for mDNS (multicast DNS) functionality, which is critical for discovering IoT devices. To implement this, the following steps are taken on the nodes:

bash sudo apt-get update sudo apt-get install avahi-daemon

After installation, the configuration file located at /etc/avahi/avahi-daemon.conf must be edited to enable the reflector:

ini [reflector] enable-reflector=no reflect-ipv=no

Once the configuration is saved, the daemon is restarted:

bash sudo systemctl restart avahi-daemon

By using an Avahi reflector, Home Assistant can discover devices across the network without requiring direct access to the host network, thereby improving the security posture of the home lab.

Comparative Analysis of Installation Methods

The choice between HAOS, Docker Compose, and K3s involves various trade-offs regarding ease of use, scalability, and resource management.

Feature Home Assistant OS (HAOS) Docker Compose K3s (Kubernetes)
Installation Ease Extremely High Medium Low
Resource Efficiency Low (Dedicated Hardware) Medium High (Shared Resources)
Add-on Support Native / Integrated Manual Manual (as separate pods)
Fail-over Support Low Medium High
Network Isolation Limited Medium High
TLS Configuration Manual/Simple Manual Integrated via Traefik/Cert-Manager
Hardware Utilization Dedicated Shared Orchestrated

Detailed Analysis of K3s Integration

The migration of Home Assistant into a K3s environment is a transition from a "set-and-forget" appliance model to an "infrastructure-as-code" model. The primary value proposition is not the execution of Home Assistant itself—which runs in a container regardless of whether it is in Docker Compose or K3s—but the orchestration surrounding it.

In a traditional Raspberry Pi HAOS setup, the user is limited by the physical constraints of a single device. If the SD card fails, the entire home automation system goes offline. In a K3s cluster, the application is decoupled from the hardware. If one node in a multi-node cluster fails, Kubernetes can potentially reschedule the Home Assistant pod to another healthy node, providing a level of resilience that is impossible with a single-node HAOS installation.

Furthermore, the use of K3s allows for the implementation of sophisticated networking. The transition from using port 8123 to port 443 via Traefik not only improves the user experience but also allows for the central management of TLS certificates. This removes the burden of managing certificates within the Home Assistant application itself, moving that responsibility to the ingress layer where it can be managed globally for all cluster services.

However, the "manual integration" of Add-ons is the most significant hurdle. In HAOS, an Add-on is essentially a managed container. In K3s, the user is the manager. While this requires more effort—writing YAML files, managing Persistent Volume Claims (PVCs), and configuring network policies—it provides absolute transparency. The user knows exactly how their database is configured, where the logs are stored, and how the communication between the Zigbee coordinator and the Home Assistant core is routed.

The integration of hardware-specific plugins, such as the NVIDIA device plugin for Jetson Nano, demonstrates that K3s can handle complex hardware passthrough that would typically be difficult in a standard container environment. By leveraging the official container image and avoiding the Raspberry Pi-specific image, users ensure they are using the most compatible and updated version of the software, regardless of the underlying architecture.

Ultimately, the shift to K3s is most beneficial for the "power user" who views their home automation as part of a larger home lab. The ability to group Home Assistant with other services, manage them through a single control plane, and secure them with a unified ingress strategy outweighs the convenience of the integrated Add-on store. It transforms the smart home from a collection of isolated devices into a professionally orchestrated microservices architecture.

Sources

  1. Jay Gould
  2. DrPump
  3. MysticRenji
  4. Warren Amphlett

Related Posts