nginx websocket 的配置
通常,我们在 nginx 上配置 websocket 长连接一般会有如下配置:
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
ingress-nginx 的配置
但,ingress-nginx 配置可不是这样,它只需要添加以下 annotations 即可:
1
2
3
|
annotations:
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
|
线上的配置示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# See: https://v1-17.docs.kubernetes.io/docs/concepts/services-networking/ingress/
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: liverpool
namespace: **live-dev
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
spec:
rules:
- host: dev-gw.**tech.com
http:
paths:
- path: /ws
backend:
serviceName: liverpool
servicePort: 9633
|
再次申明不需要手动添加以上的配置,详见:https://github.com/kubernetes/ingress-nginx/issues/4771#issuecomment-558279646
可以通过查看 ingress-nginx 自动生成的配置来证明这一点。
1
|
kubectl ingress-nginx conf -n ingress-nginx | less
|
就是这么神奇,我也是被惊呆了~
kubectl ingress-nginx 命令?
kubectl ingress-nginx
命令不存在?
按如下方式进行安装这个 kubectl plugins
安装 krew https://krew.sigs.k8s.io/docs/user-guide/setup/install/
1
2
3
4
5
6
7
8
9
|
(
set -x; cd "$(mktemp -d)" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
tar zxvf krew.tar.gz &&
KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" &&
"$KREW" install krew
)
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
kubectl krew
|
安装 ingress-nginx 这个kubectl-plugins
1
2
|
kubectl krew install ingress-nginx
kubectl ingress-nginx --help
|
查看自动生成的配置
1
|
kubectl ingress-nginx conf -n ingress-nginx | less
|