How can I set http & https router config in k8s ingress config?

I'm trying to setting http to https redirection in k8s Ingress. Traefik document is hard to apply to k8s.

I want to apply routers for HTTP & HTTPS section in this document

I found redirect configuration guide from this RedirectScheme | Traefik | v2.2

My ingress controller configuration is bellow. The middleware is the same middlewares/redirectschema guide.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-service-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.tls: "true"
    traefik.ingress.kubernetes.io/router.middlewares: default-redirect@kubernetescrd
spec:
  rules:
    - host: my-serivce.myapp.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 80
  tls:
    - secretName: whildcard.myapp.com

But traefik return 404 for every port and HTTP, HTTPS both,

I removed the middleware configuration from ingress config, Then treafik can route only https to my service . I found this guide When a TLS section is specified, it instructs Traefik that the current router is dedicated to HTTPS requests only (and that the router should ignore HTTP (non TLS) requests). .

If then, How can I configure HTTP to https redirect from ingress configuration?
Traefik guide document is hard to apply k8s. Because there is no description for combining existing features.

The basic approach is two create to ingress resources, one that is using HTTP and the second which is using HTTPS.

The redirect scheme middleware should be assigned to the HTTP ingress.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami-http
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web
    traefik.ingress.kubernetes.io/router.middlewares: default-redirectscheme@kubernetescrd
spec:
  rules:
    - host: whoami.<FIXME>.demo.traefiklabs.tech
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: whoami-svc
                port:
                  number: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami-https
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.tls: "true"
    traefik.ingress.kubernetes.io/router.tls.certresolver: le
spec:
  rules:
    - host: whoami.<FIXME>.demo.traefiklabs.tech
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: whoami-svc
                port:
                  number: 80
1 Like

Thanks to reply. I separate http and https. It works fine :slight_smile:

1 Like