NGINX 背后的 Kubectl 代理:无效的升级响应

Kubectl proxy behind NGINX: invalid upgrade response

我正在尝试将本地 Kubernates 集群添加到我的 GitLab 组以进行 CI/CD 部署。我从 运行 以下命令开始:

kubectl proxy --address 0.0.0.0 --accept-hosts '.*'

我测试了它从同一网络中的另一台机器执行 curl http://localhost:8001/api 和 运行 curl http://192.168.1.2:8001/api。代理在我的本地网络中可用。

下一步是在 kubernates.example.com 后面的 Internet 上提供代理。为此,我将 NGINX 配置如下:

server {
    server_name kubernates.example.com;
    listen 443 ssl;
    listen 80;

    include ssl_standart_conf;

    location / {
        proxy_pass http://192.168.1.2:8001/;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

执行 curl https://kubernates.example.com/api 返回了以下错误:

invalid upgrade response: status code 200

Kubernates 代理日志

E0225 22:33:50.944018 1642369 upgradeaware.go:312] Proxy upgrade error: invalid upgrade response: status code 200
E0225 22:33:50.944060 1642369 proxy_server.go:144] Error while proxying request: invalid upgrade response: status code 200

好的,我已经设法解决了这个问题。下面的nginx配置做了个小把戏

server {
    server_name kubernates.example.com;
    listen 443 ssl;
    listen 80;

    include ssl_standart_conf;

    location / {
        proxy_pass http://192.168.1.2:8001/;
        proxy_set_header Host $host;
    }
}