<p>I'm running prometheus and grafana under k3s, accessible (respectively) at <a href="http://monitoring.internal/prometheus" rel="nofollow noreferrer">http://monitoring.internal/prometheus</a> and <a href="http://monitoring.internal/grafana" rel="nofollow noreferrer">http://monitoring.internal/grafana</a>. The grafana Ingress object, for example, looks like:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
    - host: monitoring.internal
      http:
        paths:
          - path: /grafana
            pathType: Prefix
            backend:
              service:
                name: grafana
                port:
                  number: 3000
</code></pre>
<p>This works fine, except  that if you land at
<a href="http://monitoring.internal/" rel="nofollow noreferrer">http://monitoring.internal/</a>, you get a 404 error.  I would like
requests for <a href="http://monitoring.internal/" rel="nofollow noreferrer">http://monitoring.internal/</a> to redirect to
<a href="http://monitoring.internal/grafana" rel="nofollow noreferrer">http://monitoring.internal/grafana</a>. I could perhaps create another
service that runs  something like <code>darkhttpd ... --forward-all http://monitoring.internal/grafana</code>, and create  an  Ingress object
that would  map <code>/</code> to that service, but it seems like there  ought to
be a way to do this with Traefik  itself.</p>
<p>It looks like I'm running Traefik 2.4.8 locally:</p>
<pre><code>$ kubectl -n kube-system exec -it deployment/traefik -- traefik version
Version:      2.4.8
Codename:     livarot
Go version:   go1.16.2
Built:        2021-03-23T15:48:39Z
OS/Arch:      linux/amd64
</code></pre>
<p>I've found <a href="https://doc.traefik.io/traefik/v1.7/configuration/backends/kubernetes/" rel="nofollow noreferrer">this documentation for 1.7</a> that suggests there is an annotation for exactly this purpose:</p>
<ul>
<li><code>traefik.ingress.kubernetes.io/app-root: &quot;/index.html&quot;</code>: Redirects
all requests for / to the defined path.</li>
</ul>
<p>But setting that on the grafana ingress object doesn't appear to have
any impact, and I haven't been able to find similar docs for 2.x
(I've looked around
<a href="https://github.com/traefik/traefik/tree/master/docs" rel="nofollow noreferrer">here</a>, for
example).</p>
<p>What's the right way to set up this sort of redirect?</p>

<p>Since I haven't been able to figure out traefik yet, I thought I'd post my solution here in case anyone else runs into the same situation. I am hoping someone comes along who knows The Right Way to to do this, and if I figure out I'll update this answer.</p>
<p>I added a new deployment that runs <a href="https://github.com/emikulic/darkhttpd" rel="nofollow noreferrer">darkhttpd</a> as a simple director:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: redirector
spec:
  replicas: 1
  template:
    spec:
      containers:
        - name: redirector
          image: docker.io/alpinelinux/darkhttpd
          ports:
            - containerPort: 8080
          args:
            - --forward-all
            - http://monitoring.internal/grafana
</code></pre>
<p>A corresponding Service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: redirector
spec:
  ports:
    - port: 8080
      protocol: TCP
      targetPort: 8080
</code></pre>
<p>And the  following Ingress object:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: redirector
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
    - host: monitoring.internal
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: redirector
                port:
                  number: 8080
</code></pre>
<p>These are  all deployed with <a href="https://kustomize.io/" rel="nofollow noreferrer">kustomize</a>, which  takes care of
adding labels and selectors in the appropriate places. The
<code>kustomization.yaml</code> look like:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml
- ingress.yaml
- service.yaml

commonLabels:
  component: redirector
</code></pre>
<p>With all this in place, requests to <code>http://monitoring.internal/</code> hit the redirector pod.</p>
