K8s Ingress 资源不添加原始 URL 前缀到 Location 响应 header
K8s Ingress resource does not add original URL prefix to Location response header
我无法正确指定 Ingress
资源,因此应用程序的 Location
header 被重写以在前面包含原始 URL 路径。
使用配置:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-fanout-namespace-xyz
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
namespace: namespace-xyz
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /analytics/spark/master(/|$)(.*)
pathType: Prefix
backend:
service:
name: spark-master-svc
port:
number: 80
- path: /analytics/jupyter/lab(/|$)(.*)
pathType: Prefix
backend:
service:
name: jupyter-proxy-public
port:
number: 80
请求URL:https://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/
响应header:location: /hub/
重定向到 https://xx-xx.yyy.elb.amazonaws.com/hub/,404s。
这应该为 location: /analytics/jupyter/lab/
发送重定向
这似乎是 add-base-url
的用途,现在已弃用。 什么是正确的替换,我怎样才能有效地使 Location
变成 /analytics/jupyter/lab/hub/
?
如果我完全删除 rewrite-target
,那么 http://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/ 根本不会重定向,它只是 404s。
信息:
NGINX Ingress 控制器版本:
-------------------------------------------------------------------------------
NGINX Ingress controller
Release: v1.0.5
Build: 7ce96cbcf668f94a0d1ee0a674e96002948bff6f
Repository: https://github.com/kubernetes/ingress-nginx
nginx version: nginx/1.19.9
-------------------------------------------------------------------------------
Kubernetes 版本(使用kubectl version
):
Client Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.2-13+d2965f0db10712", GitCommit:"d2965f0db1071203c6f5bc662c2827c71fc8b20d", GitTreeState:"clean", BuildDate:"2021-06-26T01:02:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.2-eks-0389ca3", GitCommit:"8a4e27b9d88142bbdd21b997b532eb6d493df6d2", GitTreeState:"clean", BuildDate:"2021-07-31T01:34:46Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
环境:
- AWS EKS
- 亚马逊 Linux 2
ingress-nginx-controller 是通过 ArgoCD / Helm 安装的,上面显示了版本信息,并且没有覆盖任何值。
$ kubectl describe ingressclasses
Name: nginx
Labels: app.kubernetes.io/component=controller
app.kubernetes.io/instance=ingress-controller
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=ingress-nginx
app.kubernetes.io/version=1.0.5
helm.sh/chart=ingress-nginx-4.0.9
Annotations: <none>
Controller: k8s.io/ingress-nginx
Events: <none>
jupyter-proxy
需要为该服务背后的工作负载设置其 base_url。现在它不知道它是从子路径提供服务的事实,所以当它发送重定向时,它发送就好像它是(实际上是)从根 url.
快速测试表明
helm install my-jupyterhub jupyterhub/jupyterhub -n jupyterhub \
--create-namespace \
--set hub.baseUrl="/analytics/jupyter/lab" \
--set ingress.enabled=true \
--set ingress.pathType="ImplementationSpecific" \
--set proxy.service.type=NodePort \
--set ingress.annotations.'kubernetes\.io/ingress\.class'=nginx
使用 Ingress
为我部署 jupyter hub
,我可以通过 <X.X.X.X>/analytics/jupyter/lab/
访问它
我无法正确指定 Ingress
资源,因此应用程序的 Location
header 被重写以在前面包含原始 URL 路径。
使用配置:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-fanout-namespace-xyz
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
namespace: namespace-xyz
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /analytics/spark/master(/|$)(.*)
pathType: Prefix
backend:
service:
name: spark-master-svc
port:
number: 80
- path: /analytics/jupyter/lab(/|$)(.*)
pathType: Prefix
backend:
service:
name: jupyter-proxy-public
port:
number: 80
请求URL:https://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/
响应header:location: /hub/
重定向到 https://xx-xx.yyy.elb.amazonaws.com/hub/,404s。
这应该为 location: /analytics/jupyter/lab/
这似乎是 add-base-url
的用途,现在已弃用。 什么是正确的替换,我怎样才能有效地使 Location
变成 /analytics/jupyter/lab/hub/
?
如果我完全删除 rewrite-target
,那么 http://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/ 根本不会重定向,它只是 404s。
信息:
NGINX Ingress 控制器版本:
-------------------------------------------------------------------------------
NGINX Ingress controller
Release: v1.0.5
Build: 7ce96cbcf668f94a0d1ee0a674e96002948bff6f
Repository: https://github.com/kubernetes/ingress-nginx
nginx version: nginx/1.19.9
-------------------------------------------------------------------------------
Kubernetes 版本(使用kubectl version
):
Client Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.2-13+d2965f0db10712", GitCommit:"d2965f0db1071203c6f5bc662c2827c71fc8b20d", GitTreeState:"clean", BuildDate:"2021-06-26T01:02:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.2-eks-0389ca3", GitCommit:"8a4e27b9d88142bbdd21b997b532eb6d493df6d2", GitTreeState:"clean", BuildDate:"2021-07-31T01:34:46Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
环境:
- AWS EKS
- 亚马逊 Linux 2
ingress-nginx-controller 是通过 ArgoCD / Helm 安装的,上面显示了版本信息,并且没有覆盖任何值。
$ kubectl describe ingressclasses
Name: nginx
Labels: app.kubernetes.io/component=controller
app.kubernetes.io/instance=ingress-controller
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=ingress-nginx
app.kubernetes.io/version=1.0.5
helm.sh/chart=ingress-nginx-4.0.9
Annotations: <none>
Controller: k8s.io/ingress-nginx
Events: <none>
jupyter-proxy
需要为该服务背后的工作负载设置其 base_url。现在它不知道它是从子路径提供服务的事实,所以当它发送重定向时,它发送就好像它是(实际上是)从根 url.
快速测试表明
helm install my-jupyterhub jupyterhub/jupyterhub -n jupyterhub \
--create-namespace \
--set hub.baseUrl="/analytics/jupyter/lab" \
--set ingress.enabled=true \
--set ingress.pathType="ImplementationSpecific" \
--set proxy.service.type=NodePort \
--set ingress.annotations.'kubernetes\.io/ingress\.class'=nginx
使用 Ingress
为我部署 jupyter hub
,我可以通过 <X.X.X.X>/analytics/jupyter/lab/