Traefik with Home Assistant running in a VM

Hi

I am running successfully a Traefik v2.4 Docker container and manage to use it on a Home Assistant installation running on another Docker container in the same host (IP: 10.0.5.11). The files I used for that are the following:

docker-compose.yaml:

version: '3'

services:
  traefik:
    image: traefik:v2.4.6
    container_name: traefik
    network_mode: host
    environment:
      - CF_API_EMAIL=hsmptg@gmail.com
      - CF_API_KEY=343...daa # Global API Key
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /root/docker/traefik:/etc/traefik
    restart: unless-stopped

  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    volumes:
      - /root/docker/hass:/config
    environment:
      - TZ=Europe/Lisbon
    privileged: true      
    network_mode: host
    labels:
      - traefik.enable=true
      - traefik.http.routers.homeassistant.rule=Host(`my.domain.com`)
      - traefik.http.routers.homeassistant.tls=true
      - traefik.http.routers.homeassistant.entrypoints=websecure
      - traefik.http.routers.homeassistant.tls.certresolver=le
      - traefik.http.services.homeassistant.loadbalancer.server.port=8123
    restart: unless-stopped

traefik.yml:

entryPoints:
  traefik:
    address: :8780  
  web:
    address: :80
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https

  websecure:
    address: :443

providers:
  docker:
    endpoint: unix:///var/run/docker.sock
    watch: true
    exposedByDefault: false

api:
  dashboard: true
  insecure: true

log:
  level: DEBUG

accessLog: {}

certificatesResolvers:
  le:
    acme:
      email: hsmptg@gmail.com
      storage: /etc/traefik/acme.json
      caServer: "https://acme-v02.api.letsencrypt.org/directory"
      dnsChallenge:
        provider: cloudflare
        delayBeforeCheck: 0
        resolvers:
          - 1.1.1.1:53
          - 8.8.8.8:53

But now I would like to run Home Assistant on a separate VM (because using a Docker container, I can not use the Supervisor features of Home Assistant).

But using this setup I do not know how to setup Traefik in order the access of https://my.domain.com will access 10.0.5.249:8123 (the IP:port of the Home Assistant running on the VM).

I suppose I have to change something in the traefik.yml file, somewhere in the providers section, but I did not found any example that I could follow.

Could you please help me, suggesting what I have to do or at least give me some link that can explain this?

Best Regards
Hélio

Hi

Meanwhile, I think I solved the issue.

For that a added a file subsection inside the providers section in the traefik.yml:

providers:
  docker:
    endpoint: unix:///var/run/docker.sock
    watch: true
    exposedByDefault: false
  file:
    filename: /etc/traefik/dynamic_conf.yml    
    watch: true

And created the new dynamic_conf.yml file, with:

http:
  routers:
    homeassistant:
      service: hass-service
      rule: "Host(`my.domain.com`)"
      tls:
        certresolver: le
  services:
    hass-service:
      loadBalancer:
        servers:
        - url: http://10.0.5.27:8123

I wonder if there is a simpler solution (namely without the use of this last additional file).

Regards
Hélio

Hi @hsmptg

By removing it from docker, you have to use an alternate provider like the file provider you used. Conceptually you could use one of a variety of providers(redis, etcd, zookeeper, consul) and have your VM dynamically register with one of those.

If you're using a static ip and port for the VM file provider is likely the simplest.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.