Search code examples
nginxkuberneteshttpskubernetes-ingressnginx-ingress

Force only HTTPs Traffic on Kubernetes Nginx Ingress


I am trying to disable all HTTP ingress traffic for a specific API. I tried deleting the ingress and recreating after adding this annotation kubernetes.io/ingress.allow-http: "false" , but that doesn't work too. I can still hit the API and get a response on http://<ingress-dns-name/shipping-address/api

  • Both Nginx Controller and the API are deployed of course on the same azure Kubernetes cluster.
  • A secret my-tls-secret is created in the default namespace
  • Nginx controller has its own namespace

Here is the ingress yaml file:

kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.allow-http: "false"
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  generation: 1
  labels:
    app.kubernetes.io/managed-by: Helm
  name: api-shipping-address-ingress
  namespace: nonprod-dev
  resourceVersion: "31734103"
  uid: c9a698a0-3d2e-4f3b-99a9-c16c6fa83774
spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: api-shipping-address
            port:
              number: 3000
        path: /shipping-address(/|$)(.*)
        pathType: ImplementationSpecific
  tls:
  - secretName: my-tls-secret
status:
  loadBalancer:
    ingress:
    - ip: 10.86.168.200

Solution

  • I had the same problem and solved it by adding nginx.ingress.kubernetes.io/force-ssl-redirect: "true" as described in the ingress-nginx documentation