K3s (Kubernetes) openhab.yaml

  • Platform information:
    • Hardware: ARM/8GB RAM/128 USB
    • OS: Ubuntu 20.10 Server/64bit, k3s
    • Java Runtime Environment: included in Docker Image
    • openHAB version: 3.x
  • Issue of the topic: deploy openHAB on k3s
    The Pod does not get connected to the metallb ip (192.168.188.83). Cannot scan for items in the network (192.168.188.x).
  • Please post configurations (if applicable):
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-openhab
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/mtw/daten/openhab"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-openhab
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: openhab
  labels:
    app: openhab
spec:
  replicas: 1
  selector:
    matchLabels:
      app: openhab
  template:
    metadata:
      labels:
        app: openhab
    spec:
      containers:
      - name: openhab
        image: openhab/openhab
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        - containerPort: 8443
          name: https
          protocol: TCP
        - containerPort: 8101
          name: console
          protocol: TCP
        volumeMounts:
        - name: etc-localtime
          mountPath: /etc/localtime
          readOnly: true
        - name: openhab
          mountPath: /openhab/conf
          subPath: conf
          readOnly: false
        - name: openhab
          mountPath: /openhab/userdata
          subPath: userdata
          readOnly: false
        - name: openhab
          mountPath: /openhab/addons
          subPath: addons
          readOnly: false
        - name: openhab
          mountPath: /openhab/.java
          subPath: java
          readOnly: false
        - name: openhab
          mountPath: /openhab/.karaf
          subPath: karaf
          readOnly: false
      volumes:
      - name: etc-localtime
        hostPath:
          path: /usr/share/zoneinfo/Europe/Berlin
      - name: openhab
        persistentVolumeClaim:
          claimName: pv-openhab
---
apiVersion: v1
kind: Service
metadata:
  name: openhab
spec:
  selector:
    app: openhab
  ports:
    - protocol: TCP
      port: 8080
      targetPort: http
      name: openhab-http
    - protocol: TCP
      port: 8443
      targetPort: https
      name: openhab-https
    - protocol: TCP
      port: 8101
      targetPort: console
      name: openhab-console
  type: LoadBalancer 
  loadBalancerIP: 192.168.188.83
  • Items configuration related to the issue
    metallb ip reserved for openHAB (192.168.188.83)
  • Sitemap configuration related to the issue
  • Rules code related to the issue
  • Services configuration related to the issue
  • If logs where generated please post these here using code fences:
1 Like
  • allow firewall to see UPnP devices
  • use hostNetwork: true (Workaround, preferable LoadBalancer)
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-openhab
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/mtw/daten/openhab"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-openhab
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: openhab
  labels:
    app: openhab
spec:
  replicas: 1
  selector:
    matchLabels:
      app: openhab
  template:
    metadata:
      labels:
        app: openhab
    spec:
      hostNetwork: true
      containers:
      - name: openhab
        image: openhab/openhab
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        - containerPort: 8443
          name: https
          protocol: TCP
        - containerPort: 8101
          name: console
          protocol: TCP
        volumeMounts:
        - name: etc-localtime
          mountPath: /etc/localtime
          readOnly: true
        - name: openhab
          mountPath: /openhab/conf
          subPath: conf
          readOnly: false
        - name: openhab
          mountPath: /openhab/userdata
          subPath: userdata
          readOnly: false
        - name: openhab
          mountPath: /openhab/addons
          subPath: addons
          readOnly: false
        - name: openhab
          mountPath: /openhab/.java
          subPath: java
          readOnly: false
        - name: openhab
          mountPath: /openhab/.karaf
          subPath: karaf
          readOnly: false      
      volumes:
      - name: etc-localtime
        hostPath:
          path: /usr/share/zoneinfo/Europe/Berlin
      - name: openhab
        persistentVolumeClaim:
          claimName: pv-openhab

Problem with the OpenHAB time!

This seems to solve it:

    env:
    - name: "TZ"
      value: "Europe/Berlin"

    volumeMounts:
    - name: etc-localtime
      mountPath: /etc/localtime
    - name: etc-timezone
      mountPath: /etc/timezone

  volumes:
  - name: etc-localtime
    hostPath:
      path: /usr/share/zoneinfo/Europe/Berlin
  - name: etc-timezone
    hostPath:
      path: /usr/share/zoneinfo/Europe/Berlin

→ Settings/Regional Settings → no TimeZone (The underlying system’s time zone is the default.)

1 Like

how would you access the items files etc. I am using Longhorn for persistent storage. I guess I need to add a samba container to the pod?

Hello Geert,

my configs are here:

  - name: openhab
    persistentVolumeClaim:
      claimName: pv-openhab

Greetings