'How to use ingress so that services can talk to each other?

On AWS EKS, I have three pods in a cluster each of which have been exposed by services. The problem is the services can not communicate with each other as discussed here Error while doing inter pod communication on EKS. It has not been answered yet but further search said that it can be done through Ingress. I am having confusion as to how to do it? Can anybody help ?

Code:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: test
  name: ingress-test
  annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  ingressClassName: alb
  rules:
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: server-service
              port:
                number: 8000

My server-service has APIs like /api/v1/getAll, /api/v1/updateAll, etc. So, what should I write in path and for a database service what should I do??

And say in future I make another microservice and open another service which has APIs like /api/v1/showImage, /api/v1/deleteImage will I have to write all paths in ingress or is their another way for it to work?



Solution 1:[1]

A Ingress is a really good solution to expose both a frontend and a backend at the same domain with different paths (but reading your other question, it will be of no help in exposing the database)

With this said, you don't have to write all the paths in the Ingress (unless you want to) as you can instead use pathType: Prefix as it is already in your example.

Let me link you to the documentation Examples which explain how it works really well. Basically, you can add a rule with:

path: /api
pathType: Prefix

In order to expose your backend under /api and all the child paths.


The case where you put a second backend, which wants to be exposed under /api as the first one, is way more complex instead. If two Pods wants to be exposed at the same paths, you will probably need to list all the subpaths in a way that differentiate them.

For example:

Backed A

/api/v1/foo/listAll
/api/v1/foo/save
/api/v1/foo/delete

Backend B

/api/v1/bar/listAll
/api/v1/bar/save
/api/v1/bar/delete

Then you could expose one under subPath /api/v1/foo (Prefix) and the other under /api/v1/bar (Prefix).

As another alternative, you may want to expose the backends at different paths from what they actually expect using a rewrite target rule.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1