0

I apologize for the confusion, I hope I am not missing something.

I am trying to understand the way I forward http request through ingress in Kubernetes cluster. I have a spring-boot microservice. if I run an image of it locally (NOT IN KUBERNETES)then I would send the following HTTP request:

  http://localhost:8088/reader/info 

and get the response. it uses the port 8088 and has "reader/info " API defined in it.

Now moving forward to Kubernetes:

I have deployed:

  1. ingress resource

  2. deployment of my application (same microservice that works with http://localhost:8088/reader/info locally and not in Kubernetes)

  3. service of type clusterIP for my application

in the ingress resource: I have defined the host name: debug.com, and I would like the requests to be forwarded to service "reader-service".

my question is: how do I forward the request "reader/info" to the service through ingress(which is the original path that the application expects)? do I need to define that URL reader/info in the ingress itself? or in the parameters of the request? what should be in the URL that I send? because obviously I can have 100 microservices with completely different URL.

obviously, I am missing something here..

Ingress resource

apiVersion: networking.k8s.io/v1  
kind: Ingress
   
metadata:
   
  name: ingress-rules
  namespace: default
    
spec:
  ingressClassName: nginx
  rules: 
    - host: debug.com
      http:  
        paths:  
          - path: /  
            pathType: Prefix  
            backend:  
              service: 
                name: reader-service 
                port:
                  #same port of clusterIp
                   number: 80
          
          - path: /search
            pathType: Prefix  
            backend:  
              service: 
                name: reader-service
                port:
                  #same port of clusterIp
                  number: 80

deployment + service:

apiVersion: apps/v1

 kind: Deployment

 metadata:
   name: reader-deployment
   labels: 
    app: reader

 spec:

   replicas: 3
   selector:
    matchLabels:
      app: reader
      version: v1
   
   template:
    metadata:
      labels:
        app: reader
        version: v1
    spec:
      containers:
      - name: reader
        image: artifactory-iky.com:5654/reader:v1.0.0
        ports:
        - containerPort: 8088       
      imagePullSecrets:
        - name: registrykey
---
apiVersion: v1 
kind: Service 

metadata:
  name: reader-service
spec:
  type: ClusterIP

  selector:
    app: reader

  ports:
    - targetPort:  8088
      port: 80


      
Ohad
  • 1,563
  • 2
  • 20
  • 44
  • The path is passed through automatically. Are you saying it isn't working? – Luke Briner Nov 09 '22 at 12:39
  • I think I might got confused with host name and path.. it's the same host name but different paths, and in the path, I should place the path of the microservice API? – Ohad Nov 09 '22 at 12:43

1 Answers1

2

My recommendation is:

  1. Configure your applications to work without path (at location "/").
  2. Configure Ingress with desired application path.
  3. Configure Ingress to strip path in the requests to the backend.

See: Remove routing path from Kubernetes ingress

Of course, You can use the application path in the Ingress configuration or you can rewrite the location to the application path, but then you'll have to configure each application rewrite rule.

Rafael Guillen
  • 1,343
  • 10
  • 25