Distributed, High-Availability Home Assistant on Kubernetes #5724
Unanswered
liechtir
asked this question in
Experimental ideas
Replies: 1 comment
|
I've dreamed of having something like this for years. My entire stack runs on a k3s cluster in high-availability configurations where possible (e.g. zigbee2mqtt and zwavejs-ui as singleton statefulsets, a 3 replica vernemq MQTT broker), but Home Assistant warranted a multi-node high availability proxmox cluster so I could bounce it around as needed. Being able to bring Home Assistant directly into my cluster would be absolutely amazing. I rely on Home Assistant for a lot, and every extra bit of high availability really helps for my use case. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RFC: Distributed, High-Availability Home Assistant on Kubernetes
Status: Draft / Discussion Base
Objective: Decouple Home Assistant’s monolithic runtime into a horizontally scalable, fault-tolerant, and zero-trust microservices architecture on Kubernetes while preserving compatibility with upstream Home Assistant releases and its 3,000+ integrations.
TL;DR
Secrets, scoped NATS/Redis ACLs (preventing spoofed commands), and NetworkPolicies contain the blast radius if an integration is compromised.1. Executive Summary & Core Problem
Home Assistant (HA) Core is built as a single-process Python
asynciomonolith with an in-memoryStateMachineand local JSON/SQLite storage. Running multiple active replicas causes duplicate automation execution, hardware connection collisions, and file corruption. Furthermore, in a monolith, every custom integration shares the same Python process,/configdirectory, and unrestricted access to all credentials and physical devices.The Solution: Rather than rewriting Home Assistant Core or its 3,000+ integrations, we wrap unmodified HA Core instances inside isolated Integration Worker Pods. A lightweight shim intercepts state mutations and events, synchronizing them with a zero-trust distributed control plane (NATS + Redis), while a custom Kubernetes Operator dynamically provisions sandboxed worker pods as integrations are configured.
2. High-Level System Architecture
3. Core Architectural Components
A. Distributed Control Plane (Stateless & Multi-Replica)
EventBus. Carries state-change events, service call commands, and device discovery payloads across the cluster with per-pod topic ACL enforcement.StateMachine. Holds the real-time state dictionary and entity registry for fast reads, backed by clustered PostgreSQL for historical Recorder data.B. The Integration Shim (
custom_components/distributed_bridge)Instead of forking HA Core, we package a non-invasive bridge component into our base container image:
hass.states.async_setandhass.bus.async_listento asynchronously publish local state updates and events to Redis and NATS.hass.services.async_call()directly into the localasyncioloop.C. Onboarding, UI Pod & User Access Routing
https://home.yourdomain.com) with TLS termination and WebSocket support.distributed_bridge. It pulls initial entity states from Redis and streams live updates over WebSockets as worker pods publish state changes to NATS.2+stateless UI replicas, while Ingress path rules (/config/integrations/*and/auth/external/callback) route interactiveConfigFlowsetup wizards and OAuth redirects to a designated Onboarding Pod..storage/core.config_entriesfor the Operator to pick up.D. Custom Kubernetes Operator (
ha-orchestrator)A controller (built with Python
kopfor Gocontroller-runtime) that manages the lifecycle and security boundaries of Integration Worker Pods:.storage/core.config_entrieson the Onboarding Pod.Secret.Deployment(e.g.,ha-worker-hue) pre-seeded with only that single config entry and scoped credentials.E. Integration Worker Pods & Leader Election
replicas: 2using Kubernetes Lease objects. Only the leader pod activates polling loops; if it dies, the standby acquires the lease in < 5 seconds.4. Security & Zero-Trust Blast-Radius Isolation
In a standard Home Assistant monolith, a hijacked custom integration or malicious AI-generated dependency update has unrestricted access to all secrets, local network devices, and entity states. Because each worker pod believes it is a standalone HA instance running only itself, this architecture enforces defense-in-depth across four layers:
Secretcontaining only its owncore.config_entries. A compromised weather or media pod cannot read alarm codes, camera streams, or OAuth tokens belonging to other integrations.lock.unlock) or overwriting foreign states over the shared bus:ha-worker-huecan only publish toha.state.hue.>and subscribe toha.cmd.hue.>).SETkeys matching its own prefix (~state:hue:*), preventing cross-domain state pollution.NetworkPolicies(Egress Lockdown): Worker pods are isolated at the network layer. Cloud-only integrations are blocked from initiating connections to the local LAN (preventing lateral movement to IoT devices), while LAN-only integrations are blocked from outbound internet egress.readOnlyRootFilesystem: true,runAsNonRoot: true, and dropped Linux capabilities, preventing malicious code from persisting changes or tampering with the host environment.5. Resource Sizing & Memory Footprint
Because each worker pod runs a Python interpreter and
asyncioloop, baseline memory overhead is duplicated per pod. Strippingdefault_config(disablingfrontend,recorder,history,logbook, andmedia_source) keeps worker pods lean:requests: 256Mi,limits: 512Mi)6. Lifecycle, CI/CD, Restarts & Upgrade Strategy
ha.admin.restart.<domain>event rather than rebooting the whole system. The Operator triggers a rolling restart of only that workerDeploymentwhile the UI, automations, and all other integrations remain online.home-assistantimage, injectsdistributed_bridgeviasitecustomize.py/custom_components, runs automated integration tests against a mock NATS/Redis stack, and publishes a versioned internal image.Deployments, updates roll out incrementally (e.g., upgradeha-worker-weatherfirst; if an upstream breaking change or regression occurs, roll back only that single pod)..storageschema migrations before the Operator syncs updatedSecretsto worker pods.7. Open Discussion Points for the Team
core.entity_registryIDs so two sharded pods never collide on entity names?Why is this exciting?
I run my HA for everything at home. From managing lights, dealing with solar power, home battery (soon) and telling my heat pump to heat up the warm water. Whenever HA gets an update, or an integration update needs a restart - everything comes to a full stop. I can't even (automatically) open my garage door or unlock the front door until HA is back. (yes, I could use mechanical overrides in that case, but hey, really...?)
Also, nowadays when we run into AI detected vulnerabilities and git repo's hijacked with malicious PRs, a hardened environment that reduces the blast radius is beneficial.
Potential use cases
Keep all up and running - restart only what is needed! Keep my home safe also when we have malicious integration updates out of nowhere.
All reactions