Exposing service in Kubernetes

I'm new in Kubernetes and there are some doubts I have. I have setup a Kubernetes cluster that consists of one master/node and one node. I have deployed a very simple NodeJS-based app, using Deployment kind with 2 replicas. Then, I have exposed it as a service by kubectl expose deployment my-app --port=80.

Now, my services looks like:

root@sw-kubernetes01:~# kubectl get services
NAME             CLUSTER-IP        EXTERNAL-IP   PORT(S)   AGE
my-app           192.168.100.167   <none>        80/TCP    10m
kubernetes       192.168.100.1     <none>        443/TCP   1h

Is it supposed that I should access to my app navigating to http://192.168.100.167:? I'm getting a timeout error. Otherwise, how can I get the external IP to access to the service externally?

I know that if I declare the service as type: NodePort, I can access my app using nodes IP, doesn't exist a way to auto-balance the load between pods?


Solution 1:

If you are working on local cluster you could use the --type=NodePort

kubectl expose deployment my-app --port=80 --type=NodePort

and then grep for the port

kubectl get svc my-service -o yaml | grep nodePort

and you could browse that using the cluster ip and the port which is output from the previous grep result.

Solution 2:

If you're running on GCE, EC2, or OpenStack, it typically takes a minute or two for a load balancer to be created and for the EXTERNAL_IP field to get populated. The IP in that field is the one you should use to access your service.

If you aren't running on GCE, EC2, or OpenStack, the external load balancer feature isn't going to work for you, since Kubernetes won't know how to create one in your environment.