Kubectl proxy behind NGINX: invalid upgrade response

2/25/2021

I'm trying to add a local Kubernates cluster to my GitLab group for CI/CD deployments. I've started with running the following command:

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

I've tested it executing curl http://localhost:8001/api and running curl http://192.168.1.2:8001/api from another machine in the same network. Proxy was available in my local network.

The next step was to make the proxy available on the internet behind kubernates.example.com. For that I've configured NGINX as the following:

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";
    }
}

Executing curl https://kubernates.example.com/api returned the following error:

invalid upgrade response: status code 200

Kubernates proxy logs

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
-- Sergius
kubectl
kubernetes
nginx
nginx-reverse-proxy
proxy

1 Answer

2/25/2021

Okay, I've managed to resolve the issue. The following nginx configuration made a trick

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;
    }
}
-- Sergius
Source: StackOverflow