traefik / traefik

The Cloud Native Application Proxy
https://traefik.io
MIT License
50.59k stars 5.05k forks source link

traefik.frontend.redirect.permanent not working on k8s #3316

Closed JohnnyCrazy closed 6 years ago

JohnnyCrazy commented 6 years ago

Do you want to request a feature or report a bug?

Bug

What did you do?

I edited my ingress rule and added the following annotation:

traefik.frontend.redirect.permanent: "true"

What did you expect to see?

I expected to be redirected with a 301 status code. Also, I expected the frontend to show "Permanent" instead of "Temporary"

Also, if changing e.g traefik.frontend.redirect.regex, the frontend auto reloads the new config. This does not happen when changing the permanent rule.

What did you see instead?

Instead, my redirect code stays at 302 and the frontend still shows "temporary"

Output of traefik version: (What version of Traefik are you using?)

> kubectl exec -it traefik-ingress-controller-qr2nh -n kube-system /traefik version
Version:      v1.6.0
Codename:     tetedemoine
Go version:   go1.10.1
Built:        2018-04-30_09:28:44PM
OS/Arch:      linux/amd64

What is your environment & configuration (arguments, toml, provider, platform, ...)?

I'm running a Rancher 2.0 stack with the default nginx-ingress removed, and with treafik installed. Traefik routing is working fine, just this one rule is not working.

no dedicated config file

Startup for traefik:

        - --api
        - --kubernetes
        - --logLevel=DEBUG
        - --entrypoints=Name:http Address::80 Redirect.EntryPoint:https
        - --entrypoints=Name:https Address::443 TLS
        - --defaultentrypoints=http,https
        - --acme
        - --acme.storage=/data/traefik/acme.json
        - --acme.entryPoint=https
        - --acme.httpChallenge.entryPoint=http
        - --acme.email=johnny@johnnycrazy.de
        - --acme.onHostRule=true
        - --acme.onDemand=false

Ingress Rule

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    field.cattle.io/creatorId: user-hk989
    traefik.frontend.redirect.permanent: "true"
    traefik.frontend.redirect.regex: ^https://www.hello.example.de/(.*)
    traefik.frontend.redirect.replacement: https://hello.example.de/$1
  creationTimestamp: 2018-05-11T14:45:39Z
  generation: 3
  name: helloworld
  namespace: default
  resourceVersion: "199049"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/helloworld
  uid: f956096e-5529-11e8-a3ab-de1a100d500d
spec:
  rules:
  - host: hello.example.de
    http:
      paths:
      - backend:
          serviceName: helloworld
          servicePort: 80
  - host: www.hello.example.de
    http:
      paths:
      - backend:
          serviceName: helloworld
          servicePort: 80
status:
  loadBalancer: {}

If applicable, please paste the log output in DEBUG level (--logLevel=DEBUG switch)

Not seeing any related output in the console, if needed anyway, I will deliver it subsequently 👍

...
ldez commented 6 years ago

Thanks for your interest in Traefik !

The k8s annotations don't have the same name as labels: https://docs.traefik.io/v1.6/configuration/backends/kubernetes/#general-annotations

  • traefik.ingress.kubernetes.io/redirect-entry-point
  • traefik.ingress.kubernetes.io/redirect-permanent
  • traefik.ingress.kubernetes.io/redirect-regex
  • traefik.ingress.kubernetes.io/redirect-replacement
JohnnyCrazy commented 6 years ago

So I changed my annotations to the following:

traefik.frontend.redirect.permanent: "true"
traefik.frontend.redirect.regex: ^https://www.hello.mydomain.de/(.*)
traefik.ingress.kubernetes.io/redirect-permanent: "true"
traefik.ingress.kubernetes.io/redirect-replacement: https://hello.mydomain/$1

and the resulting config:

image

So the other naming kinda works too? I'm new to k8s, so I don't know why this is happening...

However, both naming conventions don't work for the permanent annotation, like the image shows it's still Temporary

ldez commented 6 years ago

Please use only the annotations prefixed by traefik.ingress.kubernetes.io/. Try traefik.ingress.kubernetes.io/redirect-permanent: true

We dedicate the issue tracker to bug reports and feature requests only.

If you have other questions, please go to the Traefik community Slack, thanks.

traefiker commented 6 years ago

Closed by #3332.