Sidekiq UI loading wrong assets path in Kubernetes path based routing

4/4/2018

I have a website:

xyz.com -> Standalone Angular4 APP (Container)

xyz.com/api/ -> Standalone Rails API APP (Container - ruby-2.4.0)

xyz.com/api/sidekiq -> Mounted to Rails api routes.

When I try to access the /api/sidekiq it loads the data but assets are still pointing to xyz.com/sidekiq instead of xyz.com/api/sidekiq. And all when I click retry it tries to submit to xyz.com/sidekiq instead of xyz.com/api/sidekiq. Is there a way to force sidekiq to use a different assets path and base url path?

Is there a way to get the sidekiq web view as a seperate standalone application container?

I am using Kubernetes as my orchestration tool. I am using Nginx Ingress to do path based routing. When I go to xyz.com/api/sidekiq it loads the data but the urls and assets point xyz.com/sidekiq which is why I cant retry a sidekiq job as the sidekiq web doesn't work.

-- Anto Dominic
devops
kubernetes
kubernetes-ingress
ruby-on-rails
sidekiq

1 Answer

3/5/2019

You can have a look at the thread I raised with sidekiq team "Sidekiq Route Mount doesn't rewrite URL in Rails API" that helped me understand how sidekiq mount "/sidekiq" works.

I have a simple work around for this problem and found it to be the best way to resolve my path based routing issue. You can do this using nginx.ingress.kubernetes.io/rewrite-target annotations in your Ingress configurations by writing 2 Ingress rules as shown below:

  1. Routing the "/" path to the root path of the rails-app-service ( xyz.com/* -> rails-app-service/* )

  2. Routing the "/sidekiq" path to the sidekiq web mount path of the rails-app-service ( xyz.com/sidekiq/* -> rails-app-service/sidekiq/* )

To know more about Nginx Ingress Controller rewrite target annotation check the official repository for details: https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#rewrite-target

This is my final code snippet with the solution:

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
-- Anto Dominic
Source: StackOverflow