Home Assistant on Kubernetes

Running Home Assistant on Kubernetes

Running Home Assistant on Kubernetes. It is about time to put your IoT devices under control. Everything runs off the cloud on my on-premise Kubernetes. Clean and secure.

This blog will not cover what Home Assistant is or how Kubernetes works. I assume you already have that covered.

Separate network traffic for IoT devices

I created a separate VLAN just for IoT devices on my OpenWRT. Some things to notice about this VLAN.

  • A separate AP exists for devices communicating over WiFi.
  • This VLAN does have access neither to other networks nor to the Internet. So no IoT device will be able to phone home. And most probably you cannot use the official Apps.
  • Kubernets has a dedicated Nginx Ingress Controller listening in this VLAN, opposite to the Traefik Ingress Controller which listens in the default network.
  • The host running Kubernetes does have a network connection in both VLANs (optional).

If you would like to create VLANs but don’t know how to start I highly recommend watching Mark’s great video about VLANs in OpenWrt 21. It will give you a head start.

Use K3s lightweight Kubernetes distribution for IoT

Although there are many Kubernetes distributions to choose from, I have picked K3s.

It is a lightweight Kubernetes and it is proven to work on a bunch of inexpensive unavailable Raspberry Pi4s running in a basement just like Jeff’s Pi Dramble. Make sure to check him out, it is unbelievable. 🙂

The Deployment problem of Home Assistant

There are a couple of supported ways of installing Home Assistant. Unfortunately Kubernetes is not among them. I do not blame them. Probably it simply does not worth the effort to support it, because people using Home Assistant is already a niche market, even more people running Kubernetes at home.

There are 4 options to install it.

  • Home Assistant Operating System – their own operating system based on Docker (no go)
  • Home Assistant Container – A container image containing only the core of Home Assistant (we’ll use this)
  • Home Assistant Supervised – “This way of running Home Assistant will require the most of you. It also has strict requirements you need to follow.” (still requires Docker’s socket – no go)
  • Home Assistant Core – Same as Home Assistant Container but without the container (no go)

The biggest drawback of using their container image is that there will be no “Addons store” feature. And you will need to find the necessary howtos in forums, github issues, etc.

So I will rely on their container image but what about deployment descriptions?

I cannot really use their docker-compose.yml in Kubernetes for other purposes than as a base for creating my own manifests.

There were Helm charts available for some time but at the time of writing this article, none of them are maintained anymore but at least they are better source for creating something new than using the docker-compose YMLs. I decided to roll my own version of manifest and keeping things as simple as possible.

Installing Home Assistant with Kustomize

So I have the official container image but I will need services other than the plain Core of Home Assistant. I need the following functionalities.

  • Home Assistant itself. You can grab the Kubernetes manifest from abalage/home-assistant-k8s.
  • MQTT support (Mosquitto) which is a frequently required integration interface for lots of IoT devices. You can download the Kubernetes manifest from abalage/mosquitto-mqtt-k8s.
  • Nginx Ingress Controller to expose HTTP(s) and MQTT’s TCP port 1883 (later one is not HTTP protocol)
  • MetalLB for acquiring an externally addressable IP address for Home Assistant’s service (LoadBalancer)

Like I mentioned before the Helm charts are outdated and I needed some customization anyway,  hence I use Kustomize to get all the dependencies properly configured and patched to fit my network environment.

You do not need to individually download the manifests. Just check out the GitHub project abalage/Home-Assistant-on-Kubernetes which contains everything you need to start.

Make sure you edit `kustomization.yaml` to fit to your environment. Check out the README for details.

Now you can run your own Home Assistant on Kubernetes.

What do you think? Isn’t it awesome? 🙂

7 thoughts on “Running Home Assistant on Kubernetes”

  1. How many instances of Home Assistant are you running in your cluster?

    1. Currently only one. If the LoadBalancer provides enough IP addresses, there could be many more.

  2. Just curious, why would you need to run more replicas of HA? Is that to make sure it’s always accessible? 99.xxx% uptime/availability?

  3. I guess if you have at least two servers and kubernetes, if one server goes down you still have a working instance of HA.

  4. Interesting. Often HA have hardware attached. Eg. zigbee , og bluetooth controllers. How would that hook up?

    1. As there is a way to hook up GPUs to pods, I am sure there is a way to attach other devices too.

  5. Thanks for the manifests which I took as a base for my own; looks like it’s working fine.
    One thing I changed was Deployment+PVC to StatefulSet, WDYT?
    @nykaer: for USB devices, there is https://akri.sh which I’ve used with FHEM so far. Still on the way to integrate it with Homegear + Home Assistant. The nice thing is you can even automatically remote USB devices through the cluster so it doesn’t matter which node it’s attached to vs. where the consuming service lives.

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 10 =