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.
- Create your service (should be already done)
- Expose the deployment
- Check that all have been created successfully
- 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
- 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
- Expose the deployment
kubectl expose deployment hello-minikube --type=NodePort
The output is :
service "hello-minikube" exposed
- 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
- 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