How to route http requests to a https service

I have a https Service and https/websecure IngressRoute like that.

apiVersion: v1
kind: Service
metadata:
  name: my-https-service
  labels:
    app: my-https-pod
spec:
  type: ClusterIP
  ports:
    - port: 443
      targetPort: https
      protocol: TCP
      name: https
  selector:
    app: my-https-pod
-----
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: my-route
spec:
  entryPoints:
    - websecure
  routes:
  - match: PathPrefix(`/path`)
    kind: Rule
    services:
    - name: my-https-service
      port: 443
  tls: {}

This is working fine.

  • When I switch the entrypoint from https/websecure to http/web and remove the tls: {} part.
  • Then my request fail :frowning:

How can I route http requests to a https service in a Kubernetes cluster?

Thanks for any hint.

Hello @jwausle

Just to clarify, are you looking for the option to have redirection from HTTP to HTTPS?

@jakubhajek right. (hint: it's for development@localhost only)

I would recommend starting with RedirectScheme middleware, here is an example of how to use it.

You can also follow the further exercises in that repo to see how the redirection should be managed by creating two separate routers: the first one for HTTP (where you can assign the redirect scheme middleware) and HTTPS.

Here is also the recording of the workshop we have managed based on the example I've just shared.

I hope that helps.

Thanks @jakubhajek for Your answer.

Redirection is no option in my case.

Background: My problem is that the development setup of my cluster@localhost strict require http as entry point (~web)(functional reasons). There MUST never be a TLS handshake. Afaik lead redirection always to a TLS handshake.

I'm looking for an alternative way,

My current workaround: my-https-pod expose also a http port, which I can use for routing.