Search code examples
httpkuberneteshttpsnginx-ingress

How to disable http access to service using Kubernetes Nginx ingress controller?


I have a service providing an API that I want to only be accessible over https. I don't want http to redirect to https because that will expose credentials and the caller won't notice. Better to get an error response.

How to do I configure my ingress.yaml? Note that I want to maintain the default 308 redirect from http to https for other services in the same cluster.

Thanks.


Solution

  • In the documentation: you can read the following sentence about HTTPS enforcement through redirect:

    By default the controller redirects (308) to HTTPS if TLS is enabled for that ingress. If you want to disable this behavior globally, you can use ssl-redirect: "false" in the NGINX ConfigMap.

    To configure this feature for specific ingress resources, you can use the nginx.ingress.kubernetes.io/ssl-redirect: "false" annotation in the particular resource.

    You can also create two separate configurations: one with http and https and the other one only for http.

    Using kubernetes.io/ingress.class annotation you can choose the ingress controller to be used.

    This mechanism also provides users the ability to run multiple NGINX ingress controllers (e.g. one which serves public traffic, one which serves "internal" traffic).

    See also this and this similar questions.