0

I am having trouble to create a none www redirect. I tried examples which worked for others but in my case there is nothing happening. Can anybody help me? I am Using Kubernetes 1.13.5 with traefik:1.7.8-alpine. The Config looks as following.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/redirect-entry-point: https
    traefik.ingress.kubernetes.io/redirect-permanent: "true"
    traefik.ingress.kubernetes.io/redirect-regex: ^https?://xn--neophytenbekmpfung-wtb.ch/?(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://www.xn--neophytenbekmpfung-wtb.ch$${1}
    traefik.ingress.kubernetes.io/redirect-permanent: "true"
    ingress.kubernetes.io/protocol: http
    traefik.backend.loadbalancer.sticky: "true"
    traefik.ingress.kubernetes.io/affinity: "true"
    traefik.ingress.kubernetes.io/session-cookie-name: neophytenbekaempfung-sticky
    traefik.ingress.kubernetes.io/error-pages: |-
        fives:
          status:
          - "500-600"
          backend: global-default-backend
          query: "/500s.html"
        fouro3:
          status:
          - "403"
          backend: global-default-backend
          query: "/403.html"
        fours:
          status:
          - "400-499"
          backend: global-default-backend
          query: "/400s.html"
  name: neophytenbekaempfung-sitebuilder-ingress
  namespace:    sitebuilder
spec:
  rules:
  - host: xn--neophytenbekmpfung-wtb.ch
    http:
      paths:
      - backend:
          serviceName: sitebuilder-app-service
          servicePort: 80
        path: /
  - host: www.xn--neophytenbekmpfung-wtb.ch
    http:
      paths:
      - backend:
          serviceName: sitebuilder-app-service
          servicePort: 80
        path: /    

Kind regards Gradlon

4

1 回答 1

2

Ok. The reason for the problem is simple. You can not use

    traefik.ingress.kubernetes.io/redirect-entry-point: https
    traefik.ingress.kubernetes.io/redirect-permanent: "true"

and

    traefik.ingress.kubernetes.io/redirect-regex: ^https?://xn--neophytenbekmpfung-wtb.ch/?(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://www.xn--neophytenbekmpfung-wtb.ch$${1}
    traefik.ingress.kubernetes.io/redirect-permanent: "true"

together. The reason for this can be found here: https://github.com/containous/traefik/blob/v1.7/provider/kubernetes/kubernetes.go#L992

The solution for this Particulare case looks like this.

    traefik.ingress.kubernetes.io/redirect-regex: ^http://.*?xn--neophytenbekmpfung-wtb.ch/|^https://xn--neophytenbekmpfung-wtb.ch/(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://www.xn--neophytenbekmpfung-wtb.ch/$1
    traefik.ingress.kubernetes.io/redirect-permanent: "true"

I need to make both none www to www but also http to https, with this config I am able to achieve both.

Hope this helps ohters faced with the same problem.

于 2019-08-08T15:54:04.413 回答