记录一个问题,k8s搭建的jumpserver web界面会提示连接websocket失败,导致连接不上资产
解决
本身用的是ingress做的负载,直接上配制
代码语言:txt复制apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: jumpserver
name: jump-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: "4096m" #这个要加,上传文件大小,不然文件都无法上传
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" #这是解决websocket附带的方法
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" #这是解决websocket附带的方法
nginx.ingress.kubernetes.io/server-snippets: | #加上底下这些
location / {
proxy_set_header Upgrade "websocket"; #最重要
proxy_http_version 1.1; #最重要
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Connection "Upgrade"; #最重要
proxy_cache_bypass $http_upgrade;
}
spec:
# ingressClassName: nginx
rules:
- host: jump-inf.skiffenergy.com
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: jms-k8s-jumpserver-jms-web
port:
number: 80
除了这里要加这些配制外,你的每一层代理都要添加以下参数
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
包括你443转80或80转443,都要写入这些配制