Does K8S Ingress Provide any Backend destination path along with the port?

9/18/2019

I have two web application running in same jetty.

If i simply hit the ip:port then it brings the UI application and with context path it brings another REST application.

Below are the configurations:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" 
      "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="war">./webapps/my-ui.war</Set>
</Configure>
<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" 
      "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/api</Set>
    <Set name="war">./webapps/my-rest-api.war</Set>
</Configure>

Is there any option to provide destination path in ingress ?

-- Tutai Dalal
kubernetes
kubernetes-ingress

2 Answers

9/24/2019

I am not clear how it is working, but the below code is working for me. Little confused how two context path pointing to same service and same port.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: common-service
          servicePort: 80
  - http:
      paths:
      - path: /api
        backend:
          serviceName: common-service
          servicePort: 80
-- Tutai Dalal
Source: StackOverflow

9/18/2019

From the Kubernetes documentation here this is an ingress example:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        backend:
          serviceName: test
          servicePort: 80

You can add as many rules as you need to map the path to the right service and port, in your case you can have an ingress like this:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: ui-service
          servicePort: 80
  - http:
      paths:
      - path: /api
        backend:
          serviceName: rest-api-service
          servicePort: 80
-- wolmi
Source: StackOverflow