文章目录
在使用aws 的NLB转发流量到ingress时,发现NLP上生成的转发配置不符合正常预期,如下图:
ingress-nginx service 配置如下:
apiVersion: v1
kind: Service
metadata:annotations:service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "60"service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ipservice.beta.kubernetes.io/aws-load-balancer-scheme: internet-facingservice.beta.kubernetes.io/aws-load-balancer-ssl-cert: xxxxxxxxxxxxxservice.beta.kubernetes.io/aws-load-balancer-ssl-ports: httpsservice.beta.kubernetes.io/aws-load-balancer-type: nlblabels:app.kubernetes.io/component: controllerapp.kubernetes.io/instance: ingress-nginxapp.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginxapp.kubernetes.io/version: 1.10.1name: ingress-nginx-controllernamespace: ingress-nginx
spec:allocateLoadBalancerNodePorts: trueloadBalancerClass: service.k8s.aws/nlbports:- appProtocol: httpname: httpnodePort: 30587port: 80protocol: TCPtargetPort: tohttps # 2443 端口- appProtocol: httpsname: httpsnodePort: 31999port: 443protocol: TCPtargetPort: httpselector:app.kubernetes.io/component: controllerapp.kubernetes.io/instance: ingress-nginxapp.kubernetes.io/name: ingress-nginxtype: LoadBalancer
到这里可以看到 配置是没有问题的, 80端口的流量确实是指到了tohttp端口(2443),但这个端口又是什么端口呢。 为什么会有这样一个设定呢。
接下来查看ingress-nginx服务对于2443的设定,
server {listen 2443;return 308 https://$host$request_uri;}
这里可以看出,对于2443端口,是强制对访问做了https跳转。
通过查看ingress-nginx官方文档,得到如下结果: “如果为该入口启用了 TLS,则控制器默认会将 (308) 重定向到 HTTPS”。
如何关闭呢。 参考:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-side-https-enforcement-through-redirect