Unable to connect to the API deployed in docker-desktop kubernetes?. Loadbalancer service not working

5/10/2021

I am trying to deploy and verify my API solution to docker-desktop kubernetes. I successfully deployed my application to docker-desktop k8s, I am able to run the application using swagger with the kubectl port-forward command. When I tried to apply deployment, service and loadbalancer yml files, I am unable to run the application in my browser. I am getting a message that localhost didn't sent any data. Below are my yml, docker files and screenshot of the error message in browser.

Working option enter image description here

enter image description here

Not working option

Docker file enter image description here

Deployment.yml enter image description here

Service.yml

enter image description here

Loadbalancer.yml enter image description here

Browser Error

enter image description here

K8s Details enter image description here

Please check the above configuration on not working option and help me to identify where I did mistake.

-- Purushothaman
docker
docker-desktop
kubernetes
kubernetes-pod

1 Answer

5/10/2021

In your service YAML you have did mistake in ports

in your deployment container port is : 45678

while inside the service target port is : 34567

ideally, it should be 45678 or 80 as the service will be forwarding the traffic to a container or we can say the pods.

also same apply for the service load balancer

where the target port is not getting a match for the pod and load balancer port. due to this matches your traffic is not getting forward to the PODS and you are not able to access the service on the browser.

keep the load balancer port 45678 and target port 45678

-- Harsh Manvar
Source: StackOverflow