Search code examples
kubernetesyamltraefiktraefik-ingress

Why does Traefik v2 response 404 only over http


My problem is that my traefik ingress controller in my kubernetes cluster does response 404 page not found over http, BUT over https I get the real response from the service.

This happened after I added the TLS section to IngressRoute.

This is my IngressRoute:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: example-backend
  namespace: example
spec:
  entryPoints:
    - web
    - websecure
  routes:
  - match: Host(`api.example.com`)
    kind: Rule
    priority: 10
    services:
    - name: example-backend-service
      port: 80
  tls:
    secretName: tls-secret # I'm using my own certificate, not Let's Encrypt

Why I don't get the real/same response like https does?


Solution

  • As the TLS applies on a router, you cannot have only one IngressRoute to handle the 2 cases.

    apiVersion: traefik.containo.us/v1alpha1
    kind: IngressRoute
    metadata:
      name: example-backend
      namespace: example
    spec:
      entryPoints:
        - websecure
      routes:
      - match: Host(`api.example.com`)
        kind: Rule
        priority: 10
        services:
        - name: example-backend-service
          port: 80
      tls:
        secretName: tls-secret
    
    ---
    apiVersion: traefik.containo.us/v1alpha1
    kind: IngressRoute
    metadata:
      name: example-backend-redirect
      namespace: example
    spec:
      entryPoints:
        - web
      routes:
      - match: Host(`api.example.com`)
        kind: Rule
        priority: 10
        services:
        # in this IngressRoute the service will be never called
        # because of the redirect middleware.
        - name: example-backend-service
          port: 80
        middlewares:
        - name: https_redirect
    
    ---
    apiVersion: traefik.containo.us/v1alpha1
    kind: Middleware
    metadata:
      name: https_redirect
    spec:
      redirectScheme:
        scheme: https
        permanent: true