Can't expose port on local Kubernetes cluster (via Docker Desktop)

11/25/2019

I am using the local Kubernetes cluster from Docker Desktop on Windows 10. No virtual machines, no minikubes.

I need to expose a port on my localhost for some service.

For example, I take kubernetes-bootcamp image from the official tutorial:

docker pull jocatalin/kubernetes-bootcamp:v2

Put it in the local registry:

docker tag jocatalin/kubernetes-bootcamp:v2 localhost:5000/kubernetes-bootcamp
docker push localhost:5000/kubernetes-bootcamp

Then create a deployment with this image:

kubectl create deployment kubernetes-bootcamp --image=localhost:5000/kubernetes-bootcamp

Then let's expose a port for accessing our deployment:

kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl get services
kubernetes-bootcamp   NodePort       10.102.167.98    <none>        8080:32645/TCP   8s

So we found out that the exposed port for our deployment is 32645. Let's try to request it:

curl localhost:32645
Failed to connect to localhost port 32645: Connection refused

And nothing is work.


But if I try port-forward everything is working:

kubectl port-forward deployment/kubernetes-bootcamp 7000:8080
Forwarding from 127.0.0.1:7000 -> 8080
Forwarding from [::1]:7000 -> 8080
Handling connection for 7000

Another console:

curl localhost:7000
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b5598d7b5-8qf9j | v=2

What am I doing wrong? I have found out several posts like mine, but none of them help me.

-- Rustam Salakhutdinov
docker
kubernetes

2 Answers

11/25/2019

So I have found out the problem root - local Kubernetes cluster somehow work the inappropriate way.

How I solve the problem:

  1. Remove C:\ProgramData\DockerDesktop\pki
  2. Recreate all pods, services, deployments

Now the same script I use before works great.

-- Rustam Salakhutdinov
Source: StackOverflow

11/25/2019

try to run the this CMD:

kubectl get svc | grep kubernetes-bootcamp 

after this expose the pod to your network by using the CMD:

kubectl expose pod (podname) --type=NodePort

After that, you can check the URL by using the cmd example

minikube 0r kubectl  service (service name) --url
-- udaykiran komati
Source: StackOverflow