kubesphere使用kubectl工具一直在connecting状态或者提示
Could not connect to the container. Do you have sufficient privileges?
原因:kubeshpere使用Nginx做了代理转发,没有配置websocket协议转发
解决方案: 配置websocket协议转发
定义$connection_upgrade
变量
# 定义变量,兼容HTTP和WebSocket两种请求协议
map $http_upgrade $connection_upgrade {
default keep-alive; # 默认 keep-alive,表示HTTP协议。
'websocket' upgrade; # 若是 websocket 请求,则升级协议 upgrade。
}
在 location
块中添加如下配置
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
完整内容如下
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream kubesphere {
server 10.0.1.10:30880;
}
# 定义变量,兼容HTTP和WebSocket两种请求协议
map $http_upgrade $connection_upgrade {
default keep-alive; # 默认 keep-alive,表示HTTP协议。
'websocket' upgrade; # 若是 websocket 请求,则升级协议 upgrade。
}
server {
listen 80;
ssl_prefer_server_ciphers on;
client_max_body_size 10m;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://kubesphere;
client_max_body_size 1024m;
client_body_buffer_size 128k;
}
}
}
评论区