Traefik ingress annotation "redirect http to https" redirecting to another website

Hello everyone,

I'm using Traefik as a ingress for K8S and when I try to redirect with annotations http to https for some reason another website that is being hosted by the same K8S...

My ingress yaml:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: prod
  name: client-ead
  annotations:
    kubernetes.io/ingress.class: traefik
    kubernetes.io/preserve-host: "true"
    traefik.ingress.kubernetes.io/affinity: "true"
    traefik.ingress.kubernetes.io/frontend-entry-points: http,https
    traefik.ingress.kubernetes.io/router.tls: "true"
    traefik.ingress.kubernetes.io/redirect-entry-point: https
spec:
  tls:
  - hosts:
    - client.a.com
    secretName: tlssecret
  rules:
  - client.a.com
    http:
      paths:
      - backend:
          service:
            name: client-ead
            port:
              number: 80
        path: /
        pathType: Prefix

The fun part is that I have another client hosted and when the redirect is applyed, the client.a.com redirects to client.b.com BUT if I type address with https it goes fine (client.a.com).

Note that I have the 2 tls secrets in my K8S.

Am I doing something wrong?

Thx in advance

Hi.
I had the same problem. At the end found out 2 solutions.

The first one is activate the redirect globally. That can be done by uncommenting:

redirectTo: websecure

In my case, I had to uncomment it in my Traefik's "values.yaml" helmchart. So you need to look at your Traefik config, in order to check this one out.

The second solution would be defining two ingresses, one for http and the other one for https. And then you need a "RedirectScheme" Middleware in order to pass the http requests to https.

Since the second one is a bit awkward, I went with the global definition in Traefik configuration.

Hope this helps.

1 Like