From 5b345477300a4ab4424a58021d1adca58d23ac33 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 1 Aug 2024 09:27:52 -0500 Subject: [PATCH] h-a: Config Zigbee2MQTT w/ env vars Zigbee2MQTT commits the cardinal sin of storing state in its configuration file. This means the file has to be writable and thus stored in persistent storage rather than in a ConfigMap. As a consequence, making changes to the configuration when the application is not running is rather difficult. Case in point: when I added the internal alias for _mqtt.pyrocufflink.blue_ pointing to the in-cluster service, Zigbee2MQTT became unable to connect to the broker because it was using the node port instead of the internal port. Since it could not connect to the broker, it refused to start, and thus the container would not stay running long enough to fix the configuration to point to the correct port. Fortunately, Zigbee2MQTT also allows configuring settings via environment variables, which can be managed with a ConfigMap. Luckily, the values read from environment variables override those from the configuration file, so pointing to the correct broker port with the environment variable was sufficient to allow the application to start. --- home-assistant/kustomization.yaml | 4 ++++ home-assistant/zigbee2mqtt.env | 1 + home-assistant/zigbee2mqtt.yaml | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 home-assistant/zigbee2mqtt.env diff --git a/home-assistant/kustomization.yaml b/home-assistant/kustomization.yaml index 32e81e5..3528244 100644 --- a/home-assistant/kustomization.yaml +++ b/home-assistant/kustomization.yaml @@ -41,6 +41,10 @@ configMapGenerator: files: - mosquitto.conf +- name: zigbee2mqtt + envs: + - zigbee2mqtt.env + patches: - patch: |- apiVersion: apps/v1 diff --git a/home-assistant/zigbee2mqtt.env b/home-assistant/zigbee2mqtt.env new file mode 100644 index 0000000..d5e2d59 --- /dev/null +++ b/home-assistant/zigbee2mqtt.env @@ -0,0 +1 @@ +ZIGBEE2MQTT_CONFIG_MQTT_SERVER=mqtts://mqtt.pyrocufflink.blue:8883 diff --git a/home-assistant/zigbee2mqtt.yaml b/home-assistant/zigbee2mqtt.yaml index be20c00..3b57bc0 100644 --- a/home-assistant/zigbee2mqtt.yaml +++ b/home-assistant/zigbee2mqtt.yaml @@ -61,6 +61,10 @@ spec: containers: - name: zigbee2mqtt image: docker.io/koenkk/zigbee2mqtt:1.33.1 + envFrom: + - configMapRef: + name: zigbee2mqtt + optional: true ports: - containerPort: 8080 name: http