Kubernetes ingress-nginx - 如果未配置 TLS,如何禁用对 https 的侦听?

Kubernetes ingress-nginx - How can I disable listening on https if no TLS configured?

我正在使用 kubernetes ingress-nginx and this is my Ingress spec. http://example.com works fine as expected. But when I go to https://example.com 它仍然有效,但指向带有假 Ingress Controller 证书的默认后端。我怎样才能禁用此行为?我想在此特定入口上完全禁用 https 侦听,因为没有配置 TLS。

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: http-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: example.com
      http:
        paths:
          - backend:
              serviceName: my-deployment
              servicePort: 80

我试过这个 nginx.ingress.kubernetes.io/ssl-redirect: "false" 注释。然而这没有效果。

我不知道 ingress-nginx configmap value or ingress annotation 可以轻松禁用 TLS。

您可以从入口控制器服务定义中删除端口 443。

spec.ports 数组中删除 https 条目

apiVersion: v1
kind: Service
metadata:
  name: mingress-nginx-ingress-controller
spec:
  ports:
  - name: https
    nodePort: NNNNN
    port: 443
    protocol: TCP
    targetPort: https

nginx 仍将侦听 TLS 端口,但集群外的客户端将无法连接到它。

您的问题不涉及重定向。

ingress-controller 正在侦听 80 和 443 这两个端口。当您配置只有 80 端口的入口时,如果您到达 443 端口,您将被重定向到默认后端,这是预期的行为。

一个解决方案是添加另一个 nginx-controller,它只会侦听 80 端口。然后你可以用 kubernetes.io/ingress.class: myingress 配置你的入口。 创建新的 nginx-controller 时,更改 daemonset 的命令 --ingress-class=myingress。然后它将只处理用 class.

注释的入口

如果您使用 helm 部署它,只需覆盖 controller.ingressClass 值。