0

I do have a container that runs an image and exposes the application on a specific path and port (e.g. localhost:8080/app_A).

In K8s, I have set up a service like this:

apiVersion: v1
kind: Service
...
spec:
  selector:
    application: "{{{APPLICATION}}}"
    component: "{{{COMPONENT}}}"
    environment: "{{{ENVIRONMENT}}}"
  type: ClusterIP
  ports:
    - protocol: TCP
      targetPort: 8080
      port: 80
      name: http

And the ingress as following:

apiVersion: extensions/v1beta1
kind: Ingress

metadata:
  name: "{{{COMPONENT}}}"
  namespace: "{{{NAMESPACE}}}"
  labels:
    application: "{{{APPLICATION}}}"
    component: "{{{COMPONENT}}}"
    environment: "{{{ENVIRONMENT}}}"
spec:
  rules:
  - host: "{{{COMPONENT}}}.{{{TARGET_K8S}}}.company.domain"
    http:
      paths:
      - backend:
          serviceName: "{{{COMPONENT}}}"
          servicePort: 80
        path: /app_A
        pathType: ImplementationSpecific

With the above setup, I can access the desired path via the following ingress endpoint:

{{{COMPONENT}}}.{{{TARGET_K8S}}}.company.domain/app_A

Is is possible to map the targetPath somehow in Service component so that it exposes the endpoint localhost:8080/app_A from the container directly? This way, I don't need to add app_A in the ingress endpoint when I want to access this application.

KSync
  • 51
  • 6
  • if you only have this service you can set the path to `/` and then add the `app_A` in the application router. – Pentux Aug 09 '21 at 10:49
  • @Pentux - Thanks for your comment. However, I cannot modify the application router as this is a third party image that I just download and run it. This image exposes by default the application to http://localhost:8080/app_A. Is there a way to specify on service definition to which specific path the service should be looking on the container? – KSync Aug 09 '21 at 11:01
  • path cannot be set in service component – Abhishek D K Aug 09 '21 at 11:13
  • https://stackoverflow.com/questions/58007073/how-to-route-to-specific-pod-through-kubernetes-service-like-a-gateway-api – Abhishek D K Aug 09 '21 at 11:14
  • That's what I suspected as I couldn't find any information on the K8s documentation. @AbhishekDK is there any workaround for my use case? I definitely don't want to type /app_A in the ingress endpoint. Ideally, this should be mapped/redirected somehow and when I go to my ingress endpoint, I would get redirected to the full container path. – KSync Aug 09 '21 at 11:43
  • can you also update the complete ingress file – Abhishek D K Aug 09 '21 at 13:22
  • @AbhishekDK I have updated the complete ingress file in the original post. – KSync Aug 11 '21 at 15:08
  • @KSync I propose you to use rewriting with a dedicated [App Root annotation](https://kubernetes.github.io/ingress-nginx/examples/rewrite/#app-root). It defines the Application Root that the Controller must redirect if it's in '/' context. – Andrew Skorkin Aug 17 '21 at 14:16

1 Answers1

0

can you try the following , this should work

- backend:
    serviceName: "{{{COMPONENT}}}"
    servicePort: 80
  path: /app_A
  pathType: ImplementationSpecific
Abhishek D K
  • 2,257
  • 20
  • 28
  • I tried this but it is not working. When I go to the base directory (ingress host {{{COMPONENT}}}.{{{TARGET_K8S}}}.company.domain it says not found). – KSync Aug 11 '21 at 15:14