英文:
Path based rules giving 404 for AKS ingress controller
问题
我有两个ClusterIP
服务在AKS上,以及一个Ingress控制器ingress-nginx-4.6.1
,当我尝试使用以下配置将流量路由到每个服务时,我收到404错误。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: spark-ingress
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- spark.company.net
secretName: tls-secret
rules:
- host: spark.company.net
http:
paths:
- path: /service1(/|$)(.*)
pathType: Prefix
backend:
service:
name: service-1
port:
number: 443
- path: /service2(/|$)(.*)
pathType: Prefix
backend:
service:
name: service-2
port:
number: 443
kubectl describe ing
的输出是:
Name: spark-ingress
Labels: <none>
Namespace: apache-spark
Address: 10.0.0.0
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
tls-secret terminates spark.company.net
Rules:
Host Path Backends
---- ---- --------
spark.company.net
/service1(/|$)(.*) service-1:443 (100.64.101.8:4440)
/service1(/|$)(.*) service-2:443 (100.64.101.0:4440)
Annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/use-regex: true
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Sync 2m9s (x3165 over 26h) nginx-ingress-controller Scheduled for sync
Normal Sync 2m9s (x3165 over 26h) nginx-ingress-controller Scheduled for sync
值得注意的是,后端应用程序是开源的Spark,因此当访问该应用程序时,默认行为是将其重定向到/jobs/
。我还想指出,当我为一个服务定义路径为/
的Ingress时,它可以正常工作。我需要为多个服务执行此操作。感谢任何帮助。
英文:
I have two ClusterIP
services on AKS and an ingress controller ingress-nginx-4.6.1
when I try the following config to route the traffic to each service I get 404.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: spark-ingress
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- spark.company.net
secretName: tls-secret
rules:
- host: spark.company.net
http:
paths:
- path: /service1(/|$)(.*)
pathType: Prefix
backend:
service:
name: service-1
port:
number: 443
- path: /service2(/|$)(.*)
pathType: Prefix
backend:
service:
name: service-2
port:
number: 443
the output of kubectl describe ing
is:
Name: spark-ingress
Labels: <none>
Namespace: apache-spark
Address: 10.0.0.0
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
tls-secret terminates spark.company.net
Rules:
Host Path Backends
---- ---- --------
spark.company.net
/service1(/|$)(.*) service-1:443 (100.64.101.8:4440)
/service1(/|$)(.*) service-2:443 (100.64.101.0:4440)
Annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/use-regex: true
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Sync 2m9s (x3165 over 26h) nginx-ingress-controller Scheduled for sync
Normal Sync 2m9s (x3165 over 26h) nginx-ingress-controller Scheduled for sync
It's worth noting that the backend application is open source spark. so the default behavior when hitting the app is to 302 redirect to /jobs/
. I would also like to point out that when I define the ing for one service (does not matter which) on the path /
it works just fine. I need to do this for multiple services. Any help would be appreciated.
答案1
得分: 0
问题是我的后端应用程序(Apache Spark)发送了重定向给客户端。所以客户端现在请求的是http://baseurl/resource
而不是http://baseurl/service1/resource
。
解决方法是在spark-submit中添加以下属性:
--conf spark.ui.proxyBase=/service1\
--conf spark.ui.proxyRedirectUri=localhost/service1\
对于所有的重定向,spark ui 现在将使用service1作为基础,而nginx已经设置了相应的规则来处理它。
英文:
The issue was that my backend application (Apache Spark) was sending redirects to the client. so the client is now requesting http://baseurl/resource
instead of http://baseurl/service1/resource
The fix was to add the following properties to the spark-submit
--conf spark.ui.proxyBase=/service1\
--conf spark.ui.proxyRedirectUri=localhost/service1\
For all redirects spark ui will now use service1 as base which inginx has a rule for and knows how to handle.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论