Cannot access Microk8s service from browser using NodePort service

7/15/2020

I installed microk8s on my ubuntu machine based on steps here https://ubuntu.com/kubernetes/install#single-node

Then I followed kubernetes official tutorial and created and exposed a deployment like this

microk8s.kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8083

This is my kubectl get services output

akila@ubuntu:~$ microk8s.kubectl get services
NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.152.183.1    <none>        443/TCP          25h
kubernetes-bootcamp   NodePort    10.152.183.11   <none>        8083:31695/TCP   17s

This is my kubectl get pods output

akila@ubuntu:~$ microk8s.kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-6f6656d949-rllgt   1/1     Running   0          51m

But I can't access the service from my browser using http://localhost:8083 OR using http://10.152.183.11:31695

When I tried http://localhost:31695 I'm getting ERR_CONNECTION_REFUSED.

How can I access this "kubernetes-bootcamp" service from my browser ? Am I mising anything ?

-- AMendis
kubernetes
kubernetes-ingress
kubernetes-pod
microk8s

2 Answers

7/15/2020

The IP 10.152.183.11 is CLUSTER-IP and not accessible from outside the cluster i.e from a browser. You should be using http://localhost:31695 where 31695 is the NodePort opened on the host system.

The container of the gcr.io/google-samples/kubernetes-bootcamp:v1 image need to listen on port 8083 because you are exposing it on that port. Double check that because otherwise this will lead to ERR_CONNECTION_REFUSED error.

If the container is listening on port 8080 then use below command to expose that port

microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8080
-- Arghya Sadhu
Source: StackOverflow

7/15/2020

Try this

kubectl port-forward <pod_name> <local_port>:<pod_port> 

then access http://localhost:<local_port>

-- Dashrath Mundkar
Source: StackOverflow