Orchestrating Home Automation via K3s and Home Assistant

The convergence of lightweight Kubernetes distributions and open-source home automation represents a significant shift for the modern homelab enthusiast. Integrating Home Assistant into a K3s cluster transforms a standalone smart home hub into a resilient, scalable, and professionally managed microservice. While the traditional deployment method involves Home Assistant OS (HAOS), which provides a turnkey experience, it mandates the dedication of an entire hardware asset—typically a Raspberry Pi—to a single application. For users already operating a K3s environment, this dedication is an inefficient use of compute resources. By migrating Home Assistant into a containerized environment managed by K3s, users can leverage the orchestration power of Kubernetes to run multiple side projects, ensure high availability, and implement sophisticated networking strategies that far exceed the capabilities of a standalone OS.

Running Home Assistant within a K3s cluster involves deploying the official Docker image as a pod. This transition shifts the management paradigm from a monolithic OS to a container-orchestrated architecture. The primary motivation for this move is often resource optimization; since Home Assistant is not excessively resource-intensive, it can coexist with other services on a single node or be distributed across a multi-node cluster. This approach allows the underlying hardware, whether it be Raspberry Pi clusters, mini PCs with NVME storage, or ARM64-based Nvidia Jetson Nano devices, to be utilized to their full potential. However, this architectural shift introduces specific complexities, particularly regarding the loss of the "Add-ons" ecosystem and the necessity for manual integration of third-party services.

Architectural Trade-offs and the Add-on Dilemma

The decision to deploy Home Assistant via K3s instead of the dedicated Home Assistant OS involves a critical trade-off regarding integrated features. The most prominent loss is the official "Add-ons" functionality. In a standard HAOS installation, Add-ons are simplified, one-click containers that integrate third-party services—such as databases, Dynamic DNS tools, and Zigbee2MQTT—directly into the Home Assistant UI for easy management.

When running Home Assistant as a container in K3s, these integrated Add-ons are not available. This is because the Add-on store is a feature of the HAOS supervisor, which is not present in a standard Kubernetes pod deployment. However, from an expert DevOps perspective, this is not a limitation but an opportunity for better orchestration. Every "Add-on" is essentially just another container. In a K3s environment, users can manually deploy these services as separate pods or deployments within the same namespace. This provides granular control over resource limits, scaling, and updates for each individual service, rather than relying on the Home Assistant supervisor to manage them.

Hardware Implementation Paths and Resource Optimization

The hardware requirements for a K3s-based Home Assistant deployment vary based on the desired scale and the specific integrations being used. Several distinct hardware paths have been validated:

Raspberry Pi Clusters
Deploying on a 2-node K3s cluster using Raspberry Pis allows for a distributed home automation setup. This prevents the waste of a dedicated Pi for HAOS and allows the user to self-host other side projects on the same hardware.

Mini PC Architectures
Utilizing a mini PC equipped with high RAM capacities and fast NVME drives significantly improves performance and reliability. This setup addresses common failures associated with Raspberry Pi deployments, specifically the volatility and wear-and-tear of SD card storage.

Nvidia Jetson Nano (ARM64)
The Nvidia Jetson Nano provides a powerful ARM64 environment capable of running K3s on a single device. This is particularly useful for users who want to integrate edge computing or AI capabilities into their home automation.

Network Infrastructure and External Access

Exposing Home Assistant to the internet or making it accessible across a local network requires a robust ingress strategy. In a Kubernetes environment, the pod's internal IP is volatile; therefore, a stable entry point is mandatory.

Traefik and Ingress Controllers
K3s comes bundled with Traefik, which can be utilized to define custom ingress resources. This allows the user to proxy traffic to the Home Assistant service and handle TLS handshaking. By configuring a specific hostname, such as https://hass.k3s.example.com, the user can access the instance via port 443. This removes the need to use the default Home Assistant port 8123 and ensures that the instance remains accessible even if the pod is rescheduled to a different node in the cluster.

Cloudflare Tunneling
For secure public access without opening firewall ports, a Cloudflare tunnel service can be deployed as a daemon within the cluster. This setup utilizes:
- Cloudflare's secure tunnel for external ingress.
- Google Domain Servers for DNS management.
- Cloudflare name server integration for domain resolution.
- Custom domain mapping for streamlined access.

TLS and Security
Implementing TLS is a critical step to move away from insecure HTTP connections. By utilizing Traefik with automatic TLS certificates or manual configuration, the communication between the client and the Home Assistant pod is encrypted. This is a significant security upgrade over standard Docker Compose or HAOS installations that lack proper SSL configuration.

Advanced Hardware Integrations and Device Discovery

One of the most complex aspects of running Home Assistant in a container is accessing physical hardware attached to the host node, such as USB coordinators for Zigbee or Bluetooth adapters.

Bluetooth Integration
To enable Bluetooth functionality on an Nvidia Jetson Nano, a Bluez service pod is deployed. This pod interfaces with the Bluetooth Low Energy (BLE) hardware via a direct USB connection to the Jetson device, allowing Home Assistant to communicate with devices like plant soil sensors.

Zigbee Integration
Similar to Bluetooth, a Zigbee coordinator service is deployed to handle communication with Zigbee-based sensors. This service connects via USB to the host and manages the hardware-level communication, which is then bridged to Home Assistant.

mDNS and Avahi Reflector
A common issue in Kubernetes is the inability of Home Assistant to "see" smart devices on the local network because mDNS (Multicast DNS) traffic does not natively cross the bridge between the pod network and the host network. To resolve this without granting the pod full host network access, Avahi can be installed on each K3s node.

The following sequence is required to enable the Avahi reflector:

  1. Update the package list and install the daemon:
    sudo apt-get update
    sudo apt-get install avahi-daemon

  2. Modify the configuration file at /etc/avahi/avahi-daemon.conf to enable the reflector section:
    [reflector] enable-reflector=yes reflect-ipv=no

  3. Restart the service to apply changes:
    sudo systemctl restart avahi-daemon

This configuration allows the node to reflect mDNS packets, ensuring that Home Assistant can discover devices on the network while maintaining the security boundary of the container.

K3s Cluster Deployment and Configuration

The initialization of the K3s cluster varies based on the hardware and the desired networking stack. For a specialized setup on an Nvidia Jetson Nano, the installation command includes specific flags to disable default services and configure the network CIDR.

The installation command for a K3s server with specific configurations is as follows:

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 cluster initialization, specific device plugins must be installed to leverage hardware acceleration, such as the Nvidia GPU. This is achieved by running:

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

For managing external IP addresses within the cluster, MetalLB is often applied:

kubectl apply -f <metallb-manifest-url>

Deployment Strategies and Image Selection

Selecting the correct container image is vital for stability. A common mistake is using the Raspberry Pi-specific image in an environment that does not strictly match those requirements. The official Home Assistant container image should be used to ensure compatibility across various ARM64 and x86_64 architectures.

Deployment Methods

Manifest-based Deployment
For simple setups, using raw Kubernetes manifests allows for quick deployment. A user can initialize the environment by running:

kubectl apply -f ./

Helm-based Deployment
For more complex environments, Helm charts are preferred. Helm allows for parameterized configuration, making it easier to manage environment variables, persistent volume claims (PVCs) for configuration data, and resource limits.

Namespace Management
To simplify management, all Home Assistant-related services—including the main pod, the Zigbee coordinator, the Bluez pod, and the Cloudflare daemon—should be deployed within a dedicated namespace. This prevents configuration drift and simplifies the process of deleting or migrating the entire stack.

Comparison of Home Assistant Deployment Methods

Feature Home Assistant OS (HAOS) HA in Docker Compose HA in K3s (Kubernetes)
Ease of Setup Extremely High Medium Low
Resource Efficiency Low (Dedicated HW) Medium High (Shared HW)
Add-on Store Integrated Manual Containers Manual Pods/Deployments
Fail-over Support None Limited High (Self-healing pods)
TLS/SSL Management Basic Manual/Reverse Proxy Advanced (Ingress/Traefik)
Hardware Access Native Privileged Mode Device Plugins/Host Path
Scalability None Vertical Only Horizontal/Orchestrated

Troubleshooting and Performance Tuning

When migrating to K3s, users often encounter specific bottlenecks related to I/O and networking.

Storage Performance
The transition from SD cards to NVME drives is the single most impactful hardware upgrade. Kubernetes creates significant I/O overhead due to logging and etcd operations. Using a fast NVME drive prevents the "SD card death" common in Raspberry Pi setups and reduces the boot time of the Home Assistant pod.

Network Latency
Using a Cloudflare tunnel or Traefik ingress can introduce minimal latency. However, this is negligible compared to the benefit of secure, hostname-based access. Ensuring that the http configuration within Home Assistant is set to trust the proxy is essential; otherwise, the pod will reject requests coming from the Traefik ingress controller.

Node Scheduling
In a multi-node cluster, it is critical to pin the Home Assistant pod to the node that has the physical USB connections for Zigbee and Bluetooth. This is handled via node selectors or taints and tolerations in the Kubernetes manifest, ensuring the pod does not migrate to a node where it cannot access the required hardware.

Final Technical Analysis

The deployment of Home Assistant on K3s represents the professionalization of the smart home. By moving away from a monolithic OS and adopting a microservices architecture, the user gains immense flexibility. The loss of the "Add-on" store is a superficial disadvantage that is more than compensated for by the ability to manage services using industry-standard DevOps tools.

The integration of Avahi reflectors for mDNS discovery and the use of Traefik for TLS termination creates a network environment that is both secure and transparent. Furthermore, the ability to run this stack on varied hardware—from the energy-efficient Raspberry Pi to the computationally powerful Nvidia Jetson Nano—demonstrates the versatility of the K3s ecosystem. For the tech enthusiast, the transition to K3s is not merely about running an application; it is about building a resilient infrastructure that can grow alongside their smart home, ensuring that the central brain of the house is as stable and scalable as a production cloud environment.

Sources

  1. Jay Gould - Setting up Home Assistant Kubernetes K3s
  2. DrPump - Deploying Home Assistant on k3s with TLS
  3. MysticRenji - Home Assistant on Kubernetes GitHub
  4. Warren Amphlett - Home Assistant in Kubernetes

Related Posts