k8s笔记——NodePort暴露nginx-controller实现https自动跳转自定义nodePort端口

安装nginx-controller并暴露nodePort

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx/
helm repo update
helm install gateway ingress-nginx/ingress-nginx --set controller.service.type=NodePort --set controller.admissionWebhooks.enabled=false
kubectl patch svc gateway-ingress-nginx-controller  -p '{\"spec\":{\"ports\":[{\"name\":\"http\",\"nodePort\":30882,\"port\":80,\"protocol\":\"TCP\",\"targetPort\":30882},{\"name\":\"https\",\"nodePort\":30883,\"port\":443,\"protocol\":\"TCP\",\"targetPort\":30883}]}}'

修改deployment

kubectl edit deploy gateway-ingress-nginx-controller
      containers:
      - args:
        - /nginx-ingress-controller
        - --publish-service=$(POD_NAMESPACE)/gateway-ingress-nginx-controller
        - --election-id=ingress-controller-leader
        - --ingress-class=nginx
        - --http-port=30882
        - --https-port=30883
        - --configmap=$(POD_NAMESPACE)/gateway-ingress-nginx-controller

修改configmap,新增use-port-in-redirects并禁用hsts(不禁用hsts浏览器在第二次访问时不会走服务器的308让ingress跳转到https_port而是会自动http->https端口不会修改导致https:http_port访问出现访问失败)

kubectl edit configmap gateway-ingress-nginx-controller
apiVersion: v1
data:  
hsts: "false" use
-port-in-redirects: "true" kind: ConfigMap

 

posted @ 2021-06-23 17:55  a1010  阅读(1145)  评论(0编辑  收藏  举报