A key advantage of kubernetes is flexible deployment which makes software agnostic to the underlying infrastructure. Running multiple kubernetes nodes allows runing software such as HomeAssistant without worrying about underlying hardware failures.
Configure the base image deployment
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: homeassistant
name: homeassistant
namespace: homeassistant
spec:
replicas: 1
selector:
matchLabels:
app: homeassistant
template:
metadata:
labels:
app: homeassistant
annotations:
enable.version-checker.io/homeassistant: "true"
match-regex.version-checker.io/homeassistant: ^((\d*).(\d*).(\d*)|(\d*).(\d*))
override-url.version-checker.io/homeassistant: ghcr.io/home-assistant/home-assistant
spec:
priorityClassName: critical-priority
volumes:
- name: ha-storage
persistentVolumeClaim:
claimName: homeassistant-ceph
containers:
# https://github.com/home-assistant/core/releases
- image: ghcr.io/home-assistant/home-assistant:2024.11
name: homeassistant
securityContext:
privileged: true
resources:
limits:
memory: 1024Mi
requests:
cpu: 0.1m
memory: 1024Mi
volumeMounts:
- mountPath: "/config"
name: ha-storage
The stateful set definition is fairly straight forward. The version-checker
annotations allow jetstack/version-checker to provide notifications when new versions are released.
Define a service to expose the homeassistant port
---
apiVersion: v1
kind: Service
metadata:
name: homeassistant
namespace: homeassistant
spec:
selector:
app: homeassistant
ports:
- protocol: TCP
port: 8123
name: http
targetPort: 8123
The HomeAssitant configuration and some of the config files need storage so we define a PVC to make space available. The storage is provided by Ceph File System and is highly available.
---
#! Persistent volume claim to store all homeassistant configuration data
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: homeassistant-ceph
namespace: homeassistant
labels:
app: homeassistant
spec:
accessModes:
- ReadWriteOnce
storageClassName: ceph-filesystem
resources:
requests:
storage: 5Gi
I’m not providing the Home Assitant configuration.yml
file here as there isn’t really anything kubernetes specific in it. One section is worth pointing out though - the recorder uses a sqlite database by default and I’ve moved this to a mariadb galera cluster:
recorder:
db_url: mysql://hass:password@mariadb-galera.example.com/hass?charset=utf8mb4
commit_interval: 30
Finally, we need a ingress route to expose the service to the outside world:
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: homeassistant
namespace: homeassistant
spec:
entryPoints:
- websecure
routes:
- match: Host(`hass.example.com`)
kind: Rule
services:
- name: homeassistant
port: 8123
That’s it, thanks for reading!