Kubernetes 仪表板无法与 Nginx Ingress Controller 配合使用,出现错误“客户端通过 HTTPS 服务器发送 http 请求”

Kubernetes 仪表板无法与 Nginx Ingress Controller 配合使用,出现错误“客户端通过 HTTPS 服务器发送 http 请求”

开始之前:在在此处发布我的问题之前,我已经查看了与此相关的所有帖子,但是所有建议的解决方案都不适用于我 - 甚至添加以下注释也无济于事:

    nginx.ingress.kubernetes.io/backend-protocol: HTTPS

问题:我无法让 Kubernetes 仪表板与 Nginx Ingress Controller 配合使用。访问入口 URL 时,我总是收到错误“客户端通过 HTTPS 服务器发送 http 请求”。

软件版本:

    helm kubernetes dashboard chart version: 6.0.8
    nginx ingress version: 0.16.1 (nginx-stable)

Nginx 控制器已启用启用TLSPassthrough = true

配置文件: 我的 Ingress 对象如下:

    ingress:
     enabled: true
     annotations:
       kubernetes.io/ingress.class: nginx
       nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
       nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
       nginx.ingress.kubernetes.io/rewrite-target: /
       nginx.ingress.kubernetes.io/secure-backends: "true"
       nginx.ingress.kubernetes.io/ssl-passthrough: "true"
     hosts:
     - k8s-dashboard.hpsc.prod.mycompany.com
     ingressClassName: nginx
     secretName: admin-user
     backend:
       service:
         name: kubernetes-dashboard
       port:
         name: 443
       pathType: ImplementationSpecific
       paths:
       - /
       host: k8s-dashboard.hpsc.prod.mycompany.com
     tls:
     - hosts:
       - k8s-dashboard.hpsc.prod.mycompany.com
       secretName: nginx-custom-certificate-secret

Nginx Controller for Kubernetes 仪表板中生成的结果配置如下:

    upstream kubernetes-dashboard-kubernetes-dashboard-k8s-dashboard.hpsc.prod.mycompany.com-kubernetes-dashboard-443 {
       zone kubernetes-dashboard-kubernetes-dashboard-k8s-dashboard.hpsc.prod.mycompany.com-kubernetes-dashboard-443 256k;
       random two least_conn;
    
    server 10.233.69.180:8443 max_fails=1 fail_timeout=10s max_conns=0;
    
    }
    
    server {
    
    listen 80;
       listen [::]:80;
    
    listen unix:/var/lib/nginx/passthrough-https.sock ssl proxy_protocol;
       set_real_ip_from unix:;
       real_ip_header proxy_protocol;
    
    ssl_certificate /etc/nginx/secrets/kubernetes-dashboard-nginx-custom-certificate-secret;
       ssl_certificate_key /etc/nginx/secrets/kubernetes-dashboard-nginx-custom-certificate-secret;
    
    server_tokens on;
       server_name k8s-dashboard.hpsc.prod.mycompany.com;
    
    set $resource_type "ingress";
       set $resource_name "kubernetes-dashboard";
       set $resource_namespace "kubernetes-dashboard";
    
    if ($scheme = http) {
          return 301 https://$host:443$request_uri;
       }
    
    location / {
          set $service "kubernetes-dashboard";
    
    proxy_http_version 1.1;
          proxy_connect_timeout 60s;
          proxy_read_timeout 60s;
          proxy_send_timeout 60s;
          client_max_body_size 1m;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Host $host;
          proxy_set_header X-Forwarded-Port $server_port;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_buffering on;
    
    proxy_pass http://kubernetes-dashboard-kubernetes-dashboard-k8s-dashboard.hpsc.prod.mycompany.com-kubernetes-dashboard-443;
       }
    }

我观察到,如果我通过将“proxy_pass”中的 http url 更改为 https 来手动更改上述配置(例如 https://kubernetes-dashboard-kubernetes-dashboard-........-443),当我访问时,我的 k8s 仪表板可以正常工作https://k8s-dashboard.hpsc.prod.mycompany.com在浏览器中。

有人可以帮我修复它吗?

相关内容