0

I am struggling configuring traefik:v2.6 so I can access a self-hosted netdata instance running on docker. This is my compose file:

version: "3"
services:
  netdata:
    image: netdata/netdata
    volumes:
      - "netdataconfig:/etc/netdata"
      - "netdatalib:/var/lib/netdata"
      - "netdatacache:/var/cache/netdata"
      - "/etc/passwd:/host/etc/passwd:ro"
      - "/etc/group:/host/etc/group:ro"
      - "/proc:/host/proc:ro"
      - "/sys:/host/sys:ro"
      - "/etc/os-release:/host/etc/os-release:ro"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.netdata.rule=Host(`netdata.$myserver`)"
      - "traefik.http.services.netdata.loadbalancer.server.port=19999"
      - "traefik.http.routers.netdata.entrypoints=http"
      - "traefik.docker.network=proxy"
    restart: unless-stopped
    cap_add:
      - SYS_PTRACE
    security_opt:
      - apparmor:unconfined
    networks:
      - proxy
volumes:
  netdataconfig:
  netdatalib:
  netdatacache:
networks:
  proxy:
    external: true

When I try to access netdata via netdata.$myserver I see the backdrop only but no dashboard:

netdata_without_dashboard

Checking developer settings in Firefox reveal the following message:

Loading failed for the <script> with source “http://netdata.$myserver/dashboard-react.js”. [netdata.$myserver:16:1](http://netdata.$myserver/)
Uncaught ReferenceError: NETDATA is not defined
    225 main.js:435
    p (index):16
    566 main.7d1bdca1.chunk.js:2
    p (index):16
    324 main.7d1bdca1.chunk.js:2
    p (index):16
    f (index):16
    e (index):16
    <anonymous> main.7d1bdca1.chunk.js:2

The documentation has templates for several reverse proxy configurations, but I cannot translate them into settings I might have missed for traefik.

I tried adding a && Path('/netdata') to the rule traefik.http.routers.netdata.rule=Host('netdata.$myserver')" but there was no difference. The traefik dashboard does not show any errors related to netdata. What am I missing here?

OneK
  • 613
  • 1
  • 7
  • 12

2 Answers2

1

If you use a Subpath like /netdata you have to call the directory with a slash at the end, then it will work.

 labels:
   - "traefik.enable=true"
   - "traefik.http.routers.netdata.entrypoints=web"
   - "traefik.http.routers.netdata.rule=Host(`yourdomain`) && PathPrefix(`/netdata`)"
   - "traefik.http.routers.netdata.service=netdata"
   - "traefik.http.services.netdata.loadbalancer.server.port=19999"
   - "traefik.http.routers.netdata.middlewares=netdatapathstrip"
   - "traefik.http.middlewares.netdatapathstrip.stripprefix.prefixes=/netdata"

I can reach the dashboard under http://yourdomain/netdata/ If I call http://yourdomain/netdata I get the same behaviour as you mentioned.

0

It looks like you're using a subdomain. That Host value needs to actually resolve to something. (as in the dns needs to be setup or be added to the docker host machine's /etc/hosts file.)

Here's my docker-compose file which is almost verbatim from the netdata documentation.

version: '3.4'

networks:
  traefikweb:
    external: true

services:
  netdata:
    image: netdata/netdata
    container_name: netdata
    pid: host
    labels:
      - "traefik.enable=true"
      - "traefik.ports=19999"
      - "traefik.http.routers.netdata.rule=Host(`netdata.traefik.example.com`)"
      - "traefik.http.routers.netdata.entrypoints=websecure"
      - "traefik.http.routers.netdata.tls=true"   
    networks:
      - traefikweb
    restart: unless-stopped
    cap_add:
      - SYS_PTRACE
      - SYS_ADMIN
    security_opt:
      - apparmor:unconfined
    volumes:
      - netdataconfig:/etc/netdata
      - netdatalib:/var/lib/netdata
      - netdatacache:/var/cache/netdata
      - /etc/passwd:/host/etc/passwd:ro
      - /etc/group:/host/etc/group:ro
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /etc/os-release:/host/etc/os-release:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro

volumes:
  netdataconfig:
  netdatalib:
  netdatacache:
txyoji
  • 6,680
  • 1
  • 44
  • 46
  • My subdomain does resolve - how else am I getting the backdrop when connecting. This started to work without any changes to my config after netdata update to 1.40. – OneK Aug 09 '23 at 04:47
  • Issue reported here: https://github.com/netdata/netdata/issues/14709 Fixed in 1.41 – txyoji Aug 09 '23 at 21:31