Routing legacy software running on bare metal

Hi,
I'm using k3s on my home server. It runs a few server and use traefik 2.4.8 as default.
I've also a Raspberry Pi runs with Pihole. I want to use it behind traefik. I can't figure out how?
I'm using following yaml file;

http:
  routers:
    pihole-rtr:
      entryPoints:
        - https
      rule: Host(`pihole.domain.ltd`)
      service: pihole-svc
      middlewares:
        - pihole-add-admin
      tls:
        certresolver: letsencrypt-prod
  middlewares:
    pihole-add-admin:
      addPrefix:
        prefix: /admin
apiVersion: networking.k8s.io/v1
kind: Ingress
  services
    pihole-svc
      loadBalancer
        servers
          - url 'http://192.168.1.32:80'
      passHostHeader true

It results with;

error: unable to recognize “app-pihole.yaml”: no matches for kind “Ingress services pihole-svc loadBalancer servers - url ‘http://192.168.1.32:80’ passHostHeader true” in version “[networking.k8s.io/v1](http://networking.k8s.io/v1)”

How can I serve pihole server with traefik?
Thanks in advance.

Hello @catav

There is no need to create the ingress resource to do that - the configuration for Ingress object that has been shared is not correct. See more details at this link to see how the Ingress object should be configured.

However, in order to add legacy routing you need to create a dynamic configuration in file as follows:

http:
  routers:
    my-router:
      rule: "Host(`pihole.domain.ltd`)"
      service: service-foo
   services:
     service-foo:
       loadBalancer:
         servers:
         - url: "[http://<private-ip-server-1>:<private-port-server-1>/]

Basically speaking you have to create a router and service manually - use my example as a reference. Here are some links that might be helpful while creating the final configuration:

The configuration should be mounted as a config map into your Traefik instance.

1 Like

Hi,
I'm not an IT people and my problem is persist. Adding this yaml file to the manifests directory can't solve my problem.
Thanks for your help.

pihole.yaml

---
http:
  routers:
    my-router:
      rule: "Host(`pihole.domain.ltd`)"
      service: service-pihole
  services:
    service-pihole:
      loadBalancer:
        servers:
          - url: "[http://192.168.xxx.xxx:80/]"

kubectl apply -f pihole.yaml
error: error validating "pihole.yaml": error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false

kubectl apply -f pihole.yaml --validate=false
error: unable to decode "pihole.yaml": Object 'Kind' is missing in '{"http":{"routers":{"my-router":{"rule":"Host(pihole.domain.ltd)","service":"service-pihole"}},"services":{"service-pihole":{"loadBalancer":{"servers":[{"url":"[http://192.168.xxx.xxx:80/]"}]}}}}}'

This is a dynamic configuration file for Traefik, it is not a kubernetes manifest.

For this, you would need a configmap like this :

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: traefik-dynamic-configmap
data:
  traefik-dynamic.yml: |
http:
  routers:
    my-router:
      rule: "Host(`pihole.domain.ltd`)"
      service: service-pihole
  services:
    service-pihole:
      loadBalancer:
        servers:
          - url: "[http://192.168.xxx.xxx:80/]"

And then mount the configmap to your deployment, and tell traefik about this dynamic configuration (like --providers.file.filename=/traefik-dynamic.toml).

Hope it helps

1 Like