I am running a command in my terminal
kubectl port-forward svc/egov-user 8080:8080 -n egov
This should make a web server accessible running inside a pod accessible in my localhost:8080.
But when I make a request to localhost:8080 it dosent return anything and shows the following error.
Handling connection for 8080
E0328 18:25:49.956533 48949 portforward.go:400] an error occurred forwarding 8080 -> 8080: error forwarding port 8080 to pod 7e969af36dc4ec6696936a7f052ef75c10e1c73425633c07b6bea37cd25e0441, uid : failed to execute portforward in network namespace "/var/run/netns/cni-005dc260-d493-5241-9f53-d58
3d0998a9c": failed to dial 8080: dial tcp4 127.0.0.1:8080: connect: connection refused
what is this problem and how can I solve it?
I am expecting to get a webserver runnning on localhost:8080 which is attached to a web server. But I am not getting any seeing any such thing running.
The error indicates the service either cannot route your request to a pod or the pod itself is not able to handle that request.
Start at the service.
kubectl get svc -n egov egov-user -o yamlInside the output will be a
selectorblock, e.g.:Look for any pods with this selector, swapping ": " to "="
kubectl get pods -n egov -l app.kubernetes.io/name=app-nameIf you find no pods, then your service selector is wrong
If you find pods, pick one of them and try to portforward directly to that pod as suggested by Tomer Aharon.
Then try to hit localhost:8080 and see what happens. If
kubectlreports being unable to pass the request along, check whether the service is really listening on that port (e.g is it listening on 80 instead of 8080?)Check the logs of the port using
kubectl logsto see whether the process can't start up properly.