问题描述
我正在尝试将本地 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;
}
}