Image showing How to expose a port on Minikube

How to expose a port on Minikube

affiliate best offer

When using minikube, you need to expose ports to access your services. In docker, you have a command flag to do that. How do you do the same thing in minikube?

Remeber that kubernetes has more components than docker. A matter of fact, docker is among the components of kubernetes, hence minikube.

TL;DR

The solution is to use the minikube service <SERVICE_NAME> --url command. This command will give you a url that will allow you to connect to the backend service running on minikube.

  1. Create your service (should be already done)
  2. Expose the deployment
  3. Check that all have been created successfully
  4. Expose the port of the service on minikube

There is an alternate solution using the port forwading kubectl port-forward <service> 27017:27017.

The steps to open a port on minikube

  1. Create a deployment

Think of this as a container.

kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080

You will get this output.

deployment "hello-minikube" created
  1. Expose the deployment
kubectl expose deployment hello-minikube --type=NodePort

The output is :

service "hello-minikube" exposed
  1. Check that all is setup correctly
kubectl get svc

You will get the output.

NAME             CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
hello-minikube   10.0.0.102   <nodes>       8080/TCP   7s
docker           10.0.0.1     <none>        443/TCP    13m
  1. Expose the port on minikube
minikube service hello-minikube --url 

This command will print the url where you can reach the service :

http://192.168.99.100:31167

If you want to open the url directly in your browser, run this command :

minikube service hello-minikube

Tips and tricks

  1. Make sure you can ping your minikube VM. 192.168.99.100
  2. If your cluster is not working as expected, you can delete the .minikube folder and recreate the cluster. All will be reset.
  3. To inspect easily a docker container, take a look to [[2020-08-04-docker-tip-inspect-and-jq docker and jq tutorial]]
Full Bright

Full Bright

A professional and sympathic business man.

Contact

Contact Us

To order one of our services, navigate to the order service page

Address

10 rue de Penthièvre,
75008 Paris

Email Us

hello at bright-softwares dot com

Open Hours

Monday - Friday
9:00AM - 05:00PM