侧边栏壁纸
  • 累计撰写 84 篇文章
  • 累计创建 34 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

kubesphere平台kubectl工具无法使用

欧泡果奶
2024-10-26 / 0 评论 / 0 点赞 / 42 阅读 / 0 字

kubesphere使用kubectl工具一直在connecting状态或者提示Could not connect to the container. Do you have sufficient privileges?

原因:kubeshpere使用Nginx做了代理转发,没有配置websocket协议转发

img img

解决方案: 配置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;
		}
	}
}
0

评论区