Search code examples
angulardockerkuberneteskubernetes-ingress

How to call a golang API(clusterIP svc) from angular(clusterIP svc) in k8s with ingress present?


go version: 1.17
ng version: 9

This project consists of a backend svc and deployment, frontend svc and deployment, ingress

Backend service:

service/fiber-service   ClusterIP   10.105.244.88   <none>        3000/TCP   43m

Ingress File:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-lite-srv
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"

spec:
  rules:
    - host: lite.com
      http:
        paths:
          - path: /api/?(.*)
            pathType: Prefix
            backend:
              service:
                name: fiber-service
                port:
                  number: 3000 # service port
          - path: /?(.*) #need to check order
            pathType: Prefix
            backend:
              service:
                name: forms-service
                port:
                  number: 80 # service port

Currently I am using HTTPClient and doing

 testUrl(url: string): Observable<any> {
    return this._http.get(url)
  }

Above code is from my frontend and it is called on a button click event

Now, After tunnelling, I am able to access frontend when I visit http://lite.com and I can make API calls by requesting on http://lite.com/api/v1 or something

What I am trying to achieve is call the backend API via service name
eg: fiber-service:3000/api/v1 as url to the above function
Basically clusterIP to clusterIP service without involving Ingress

Is this possible or does ingress interfere? What will be the performance difference? (since this is an internal communication)


Solution

  • I found that it is not possible to do this especially when one's frontend has client side rendering

    So, the problem is when user visits the webpage, it is rendered on the client's system. Hence, we are unable to find the fiber-service:3000/api/v1 so, it has to be called via ingress i.e. http://lite.com/api/v1

    If it was server side rendering, then it would have been possible to call the service.