基于路径的规则导致 AKS Ingress 控制器返回 404 错误。

huangapple go评论89阅读模式
英文:

Path based rules giving 404 for AKS ingress controller

问题

我有两个ClusterIP服务在AKS上,以及一个Ingress控制器ingress-nginx-4.6.1,当我尝试使用以下配置将流量路由到每个服务时,我收到404错误。

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. name: spark-ingress
  5. annotations:
  6. nginx.ingress.kubernetes.io/backend-protocol: HTTPS
  7. nginx.ingress.kubernetes.io/rewrite-target: /$2
  8. nginx.ingress.kubernetes.io/use-regex: "true"
  9. spec:
  10. ingressClassName: nginx
  11. tls:
  12. - hosts:
  13. - spark.company.net
  14. secretName: tls-secret
  15. rules:
  16. - host: spark.company.net
  17. http:
  18. paths:
  19. - path: /service1(/|$)(.*)
  20. pathType: Prefix
  21. backend:
  22. service:
  23. name: service-1
  24. port:
  25. number: 443
  26. - path: /service2(/|$)(.*)
  27. pathType: Prefix
  28. backend:
  29. service:
  30. name: service-2
  31. port:
  32. number: 443

kubectl describe ing的输出是:

  1. Name: spark-ingress
  2. Labels: <none>
  3. Namespace: apache-spark
  4. Address: 10.0.0.0
  5. Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
  6. TLS:
  7. tls-secret terminates spark.company.net
  8. Rules:
  9. Host Path Backends
  10. ---- ---- --------
  11. spark.company.net
  12. /service1(/|$)(.*) service-1:443 (100.64.101.8:4440)
  13. /service1(/|$)(.*) service-2:443 (100.64.101.0:4440)
  14. Annotations:
  15. nginx.ingress.kubernetes.io/backend-protocol: HTTPS
  16. nginx.ingress.kubernetes.io/rewrite-target: /$2
  17. nginx.ingress.kubernetes.io/use-regex: true
  18. Events:
  19. Type Reason Age From Message
  20. ---- ------ ---- ---- -------
  21. Normal Sync 2m9s (x3165 over 26h) nginx-ingress-controller Scheduled for sync
  22. 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.

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. name: spark-ingress
  5. annotations:
  6. nginx.ingress.kubernetes.io/backend-protocol: HTTPS
  7. nginx.ingress.kubernetes.io/rewrite-target: /$2
  8. nginx.ingress.kubernetes.io/use-regex: "true"
  9. spec:
  10. ingressClassName: nginx
  11. tls:
  12. - hosts:
  13. - spark.company.net
  14. secretName: tls-secret
  15. rules:
  16. - host: spark.company.net
  17. http:
  18. paths:
  19. - path: /service1(/|$)(.*)
  20. pathType: Prefix
  21. backend:
  22. service:
  23. name: service-1
  24. port:
  25. number: 443
  26. - path: /service2(/|$)(.*)
  27. pathType: Prefix
  28. backend:
  29. service:
  30. name: service-2
  31. port:
  32. number: 443

the output of kubectl describe ing is:

  1. Name: spark-ingress
  2. Labels: <none>
  3. Namespace: apache-spark
  4. Address: 10.0.0.0
  5. Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
  6. TLS:
  7. tls-secret terminates spark.company.net
  8. Rules:
  9. Host Path Backends
  10. ---- ---- --------
  11. spark.company.net
  12. /service1(/|$)(.*) service-1:443 (100.64.101.8:4440)
  13. /service1(/|$)(.*) service-2:443 (100.64.101.0:4440)
  14. Annotations:
  15. nginx.ingress.kubernetes.io/backend-protocol: HTTPS
  16. nginx.ingress.kubernetes.io/rewrite-target: /$2
  17. nginx.ingress.kubernetes.io/use-regex: true
  18. Events:
  19. Type Reason Age From Message
  20. ---- ------ ---- ---- -------
  21. Normal Sync 2m9s (x3165 over 26h) nginx-ingress-controller Scheduled for sync
  22. 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中添加以下属性:

  1. --conf spark.ui.proxyBase=/service1\
  2. --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

  1. --conf spark.ui.proxyBase=/service1\
  2. --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.

huangapple
  • 本文由 发表于 2023年6月5日 00:53:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定