How to use the TLS certificate/ https in k3s for traefik

Objective: all the traffic should happen on https (443) only. Any http calls should be redirected to https

Given:

  1. k3s with trafik as the Ingress. this is the default and no changes are made to the traefik or k3s specifically for ingress routing.

  2. the current routing is using http and is working fine. I want to move to https.

  3. all the examples on internet use let's encrypt which uses cert-manager and a complex configuration. Some have even recommended to remove default traefik and install a newer version). I do not have much knowledge about traefik.

  4. my certificate consists of two files. domain.com.cert and domain.com.key

  5. I have already loaded the certificate in the k3s in k8s secret. the secret name is tls-security. the two keys are tls.crt and tls.key

  6. I need to use the certificate and also want to redirect the traffic, if it comes on http (80) should be redirected to https (443)

here is my current file:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: scm-ingress
  namespace: scm
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
  tls:
  - hosts:
    - domain.com
    secretName: tls-secret  
  rules:
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: gateway
              port:
                number: 80

I'm getting 404 when I access using https://domain.com/myEP.
If I change that to http://domain.com/myEP then everything works as before.

  • How do I redirect to https from http and
  • why I get 404 when https is used