Kubernetes http to https redirect

Hello there,

I haven't found in the v2 documentation how to have http to https redirection.
I'm using IngressRoute and Services

Here is my Traefik Deployment config:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  namespace: default
  name: traefik
  labels:
    app: traefik
spec:
  replicas: 1
  selector:
    matchLabels:
      app: traefik
  template:
    metadata:
      labels:
        app: traefik
    spec:
      serviceAccountName: traefik-ingress-controller
      containers:
        - name: traefik
          image: traefik:v2.0
          args:
            - --api
            - --accesslog
            - --entrypoints.web.Address=:80
            - --entrypoints.websecure.Address=:443
            - --providers.kubernetescrd
            - --certificatesresolvers.default.acme.tlschallenge=true
            - --certificatesresolvers.default.acme.email=email@example.com
            - --certificatesresolvers.default.acme.storage=acme.json
          ports:
            - name: web
              containerPort: 80
            - name: websecure
              containerPort: 443
            - name: admin
              containerPort: 8080

IngressRoute:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
    name: apollo-ingressroutetls
spec:
    entryPoints:
        - websecure
    routes:
        - match: Host(`apollo.example.com`) && PathPrefix(`/`)
          kind: Rule
          services:
              - name: apollo-nginx
                port: 8000
    tls:
        certResolver: default

And a Service:

apiVersion: v1
kind: Service
metadata:
  name: apollo-nginx
  labels:
    app: apollo-nginx
spec:
  type: ClusterIP
  ports:
    - port: 8000
      targetPort: 8000
      name: http
  selector:
    app: apollo-nginx

So if someone has the answer, I'm quite interested ^^

I had the same problem, I ended up creating two IngressRoutes one with entrypoint http and other like the one you described. In the http IngressRoute, I added a middleware to redirect to https.
Refer here for middlewares
https://docs.traefik.io/v2.0/middlewares/redirectscheme/

I tried adding it all to one IngressRoute but didn't have any luck there

Ok I see!
Would you mind sharing your resource definitions? I never worked with middleware so that would definitely be helpful to check out.

You can try this configuration:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: admin-https
spec:
  entryPoints:
    #- web
    - websecure
  routes:
  - match: Host(`pwjtest.zhixueyun.com`) && PathPrefix(`/`)
    kind: Rule
    services:
    - name: traefik
      port: 18080
    #  scheme: https
 #   middlewares:
 #   - name: admin-https
    #- name: admin-auth
    #- name: admin-header
  tls:
    secretName: supersecret
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: admin-auth
spec:
  basicAuth:
    secret: authsecret
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: admin-https
spec:
  redirectScheme:
    scheme: https
    permanent: true
    port: 443