Not able to call another pod

58 Views Asked by At

I have a backend pod, service related to it "backend-service" and another frontend pod trying to access the backend on url http://backend-service:8000 . I port forward my frontend , open the url in browser I could see backend url called on networks tab but no request is coming on my backend.

But when port-forward my backend and use url "http://localhost:8000", things work

2

There are 2 best solutions below

0
R10t-- On

A few things to check:

Are you deploying a Service for your backend? Without a Service you won't be able to access the backend's ports from anywhere unless you port-forward them manually. This is likely why you can't access the backend without a port-forward.

Second: Are your Services in different namespaces? If you are deploying in different namespaces, you can't just use the service name to connect like you can in docker. To connect to a service in Kubernetes, the format is <serviceName>.<namespace>.svc.cluster.local. So for you it might be backend-server.backend.svc.cluster.local. Check your Services and namespaces and also update your connection strings to use the k8s format.

0
Jolly On

Since, the frontend was trying to call the backend service through a backend api endpoint, so I had to actually pass the url format like "local.example.com/backend". In the url, there should be an ingress path (here /backend) pointing to your backend service.

When we try to hit the backend on a browser based setup, its actually the url that needs to be passed not "serviceName.namespace"