HTTP to HTTPS redirect

Using kubernetes traefik (2) ingerssroute, I am having problems redirecting from HTTP to HTTPS.

I am using this middleware:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: traefik-middleware-redirectscheme
  namespace: default
spec:
  redirectScheme:
    scheme: https
    permanent: true

Using the above middleware in ingressroute for all the defined routes.

But, when I go to http://my-server-dns, I am not redirected to https://my-server-dns.
Instead http://my-server-dns resturns 404

is there any more configuration necessary? Kindly help

On which IngressRoutes do you add this middleware?

I added it for all the routes something like this (one of the routes shown)

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
  name: traefik-ingressroute
  namespace: default
spec:
  entryPoints:
    - web
    - websecure
  routes:
    - kind: Rule
      match: Host(`my-dns-name`) && PathPrefix(`/path`, `/path/`)
      middlewares:
        - name: traefik-middleware-headers
          namespace: default
        - name: traefik-middleware-redirectscheme
          namespace: default
      services:
        - kind: Service
          name: service-name
          namespace: default
          port: <PORT>
    - kind: Rule
    .......................

  tls:
    secretName: ca-key-pair

You cant use the IngressRoute like that. If you have an IngressRoute with a TLS section, attach that to the websecure entrypoint. Then, have the "same" Ressource but without the tls section and attached to the web entrypoint. Then your 404 should be resolved.

Works like a charm! Thanks for the solution