K8S - Ingress - Route 2 different applications

3/5/2019

In my minikube k8s cluster, I have 2 applications/services.

This is my ingress controller for the services I have.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-tutorial
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  backend:
    serviceName: default-http-backend
    servicePort: 80
  rules:
  - host: mysite.com
    http:
      paths:
      - path: /sva
        backend:
          serviceName: app-a
          servicePort: 8080
      - path: /svb
        backend:
          serviceName: app-b
          servicePort: 8150

When i type mysite.com/sva or mysite.com/svb it routes to appropriate services. However, none of the static files (js, css, images etc) is loaded as they seem to request for the resources from mysite.com instead of mysite.com/sva/

How can I make it look for the resources under specific service?

-- KitKarson
kubernetes
kubernetes-ingress
nginx

2 Answers

3/5/2019

Try to Add the following annotation in ingress

ingress.kubernetes.io/add-base-url: "true"

will solves this problem.

You can also review : https://github.com/kubernetes/ingress-nginx/issues/333

-- Harsh Manvar
Source: StackOverflow

3/5/2019

Based on Harsh Manvar answer, Looks like rewrite does not work on the static resources as of now.

This is a workaround I am planning to follow to route diff apps like sva.mysite.com or svb.mysite.com. It works fine. Just adding this as an answer if somebody faces similar problem.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-tutorial
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  backend:
    serviceName: default-http-backend
    servicePort: 80
  rules:
  - host: sva.mysite.com
    http:
      paths:
      - path: /
        backend:
          serviceName: app-a
          servicePort: 8080
  - host: svb.mysite.com
    http:
      paths:
      - path: /
        backend:
          serviceName: app-b
          servicePort: 8150
-- KitKarson
Source: StackOverflow