Search code examples
rancher

Rancher 2.x - HTTP to HTTPS redirect


I installed Rancher 2.4.4 using the docs and everything is working. I can access the server using https using my custom domain rancher.mydomain.com.

I created an Ingress using test.mydomain.com to access a service. I am using self-signed certificate to test https://test.mydomain.com access and it is working. But I can access the same service using http. How can I make a redirect or avoid access to my cluster using http? This is the ingress with sensitive information changed:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    field.cattle.io/creatorId: user-tk7hh
    field.cattle.io/ingressState: '{"dW5pbWVk":"p-pfqlz:test","abc":"deployment:test:httpbin","abc==":"deployment:test:httpbin"}'
    field.cattle.io/publicEndpoints: '[{"addresses":["1.2.3.4"],"port":443,"protocol":"HTTPS","serviceName":"unimed:ingress-5d3e64b41895cfc7d3d354d63a7d83d0","ingressName":"test:test","hostname":"test.mydomain.com","path":"/status","allNodes":false},{"addresses":["1.2.3.4"],"port":443,"protocol":"HTTPS","serviceName":"test:ingress-9922b5a9032d962093476e63c4335d80","ingressName":"test:test","hostname":"test.mydomain.com","path":"/delay","allNodes":false}]'
  creationTimestamp: "2020-06-05T23:28:23Z"
  generation: 11
  labels:
    cattle.io/creator: norman
  managedFields:
  - apiVersion: extensions/v1beta1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:loadBalancer:
          f:ingress: {}
    manager: traefik
    operation: Update
    time: "2020-06-05T23:28:23Z"
  - apiVersion: extensions/v1beta1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:field.cattle.io/creatorId: {}
          f:field.cattle.io/ingressState: {}
          f:field.cattle.io/publicEndpoints: {}
        f:labels:
          .: {}
          f:cattle.io/creator: {}
      f:spec:
        f:rules: {}
        f:tls: {}
    manager: Go-http-client
    operation: Update
    time: "2020-06-08T19:22:11Z"
  name: unimed
  namespace: unimed
  resourceVersion: "998963"
  selfLink: /apis/extensions/v1beta1/namespaces/test/ingresses/test
  uid: b138da9d-9ca8-4a23-a9b9-3ae1e400177d
spec:
  rules:
  - host: test.mydomain.com
    http:
      paths:
      - backend:
          serviceName: ingress-5d3e64b41895cfc7d3d354d63a7d83d0
          servicePort: 80
        path: /status
        pathType: ImplementationSpecific
      - backend:
          serviceName: ingress-9922b5a9032d962093476e63c4335d80
          servicePort: 80
        path: /delay
        pathType: ImplementationSpecific
  tls:
  - hosts:
    - test.mydomain.com
    secretName: test
status:
  loadBalancer:
    ingress:
    - ip: 1.2.3.4


Solution

  • Solved. Rancher 2.4.4 uses Traefik as a load balancer. We need to put this annotation to make a redirect

    traefik.ingress.kubernetes.io/redirect-entry-point: https
    

    It is possible to do this in the Ingress using the interface.

    enter image description here