Sidekiq UI在基于Kubernetes路径的路由中加载错误的资产路径

问题描述 投票:1回答:1

我有一个网站:

xyz.com - >独立的Angular4 APP(容器)

xyz.com/api/ - >独立Rails API APP(容器 - ruby​​-2.4.0)

xyz.com/api/sidekiq - >安装到Rails api路由。

当我尝试访问/ api / sidekiq时,它会加载数据,但资源仍然指向xyz.com/sidekiq而不是xyz.com/api/sidekiq。所有当我点击重试时,它会尝试提交到xyz.com/sidekiq而不是xyz.com/api/sidekiq。有没有办法强制sidekiq使用不同的资产路径和基本URL路径?

有没有办法将sidekiq Web视图作为一个单独的独立应用程序容器?

我使用Kubernetes作为我的编排工具。我正在使用Nginx Ingress来进行基于路径的路由。当我去xyz.com/api/sidekiq它加载数据,但网址和资产指向xyz.com/sidekiq这就是为什么我不能重试sidekiq工作,因为sidekiq网络不起作用。

ruby-on-rails kubernetes sidekiq devops kubernetes-ingress
1个回答
1
投票

你可以看看我用sidekiq团队“Sidekiq Route Mount doesn't rewrite URL in Rails API”提出的线程,这有助于我理解sidekiq mount "/sidekiq"是如何工作的。

我有一个简单的解决此问题的方法,并发现它是解决基于路径的路由问题的最佳方法。您可以通过编写2个Ingress规则在Ingress配置中使用nginx.ingress.kubernetes.io/rewrite-target注释来执行此操作,如下所示:

  1. 将“/”路径路由到rails-app-service的根路径(xyz.com/* -> rails-app-service/*
  2. 将“/ sidekiq”路径路由到rails-app-service的sidekiq web挂载路径(xyz.com/sidekiq/* -> rails-app-service/sidekiq/*

要了解有关Nginx Ingress Controller重写目标注释的更多信息,请查看官方存储库以获取详细信息:https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#rewrite-target

这是我的解决方案的最终代码段:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "rails-app-ingress"
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: xyz.com
    http:
      paths:
      - path: /
        backend:
          serviceName: "rails-app-service"
          servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "rails-sidekiq-ingress"
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /sidekiq
spec:
  rules:
  - host: xyz.com
    http:
      paths: 
      - path: /sidekiq
        backend:
          serviceName: "rails-app-service"
          servicePort: 80
© www.soinside.com 2019 - 2024. All rights reserved.