I've created a service inside minikube (expressjs API) running on my local machine, so when I launch the service using minikube service wedeliverapi --url i can access it from my browser with localhost:port/api

minikube IP :

enter image description here

enter image description here

But I also want to access that service from another device so I can use my API from a flutter mobile application, how can I achieve this goal?

  • Could you please replace the screenshots with text? Commented Oct 30, 2021 at 7:48
  • which one? minikube service wedeliverapi --url output ?
    – Ali Ourag
    Commented Nov 1, 2021 at 12:06

3 Answers 3



Look at NodePort or Ingress to expose a Kubernetes minikube service externally.

For minikube specifically, there is one last networking layer between the minikube VM and the host. You need to enable port forwarding from the Host into the VM. To forward the entire default minikube NodePort range:

for port in {30000..32767}; do VBoxManage controlvm minikube natpf1 "NodePort$port,tcp,,$port,,$port"; done

To disable the port forwarding when you're done:

for port in {30000..32767}; do VBoxManage controlvm minikube natpf1 delete "NodePort$port"; done

Long Answer

The default Service type is ClusterIP, which only exposes the Service inside the cluster via a cluster-internal IP.

To expose a Service outside the minikube cluster, there are a few options provided by Kubernetes.

First, we can look at ServiceTypes:

  1. NodePort - Exposes a service on each cluster node at a specific port. Cluster networking routes the packets to the target Service's Pods. This is the most basic way to expose a service externally. It has existed for many years in Kubernetes. This is probably the simplest way to expose a Service for testing in minikube. However, if you want to do anything fancy such as TLS/SSL termination, load balacning, virtual hosts, or routing rules... use an Ingress.
  2. LoadBalancer - Exposes a service using a cloud-native Load Balancer. This is for production clusters, and probably not useful for your minikube use case. It usually creates a dynamic NodePort for use as the cloud Load Balancer's backend target port.
  3. ExternalName - A way to use externally hosted services through a cluster DNS CNAME record. Maps the service name directly to an outside DNS address, and bypasses the need for endpoint records. Although it's good to know this exists, this is not very useful for your use case of exposing a cluster service externally.

Next, we can look at port forwarding:

  • kubectl port-forward command is a way to forward local traffic into a Pod within a Kubernetes cluster. This feature is built into kubectl, and is mostly useful for local development and one-off tasks where you need to access a Pod directly. This works with Pod names, Deployments, and ReplicaSets.

     kubectl port-forward podname-nnnnn-xxxx $LOCALPORT:$CONTAINERPORT

This is probably the simplest method for accessing a Pod providing a Service quickly in order to test that it's working properly and accepting traffic.

Finally, we can look at Ingress and Ingress Controllers (default: nginx):

  • Ingress: An Ingress may be configured to give Services externally-reachable URLs, load balance traffic, terminate SSL / TLS, and offer name-based virtual hosting. An Ingress Controller usually runs inside a Pod in the kube-system namespace and provides these features which are configurable through the Ingress Kubernetes API object.

For minikube, you need to enable it as an addon:

minikube addons enable ingress

Follow the minikube Ingress tutorial here to get started using ingress-nginx.

  • I really appreciate your answer but can ingress-nginx help me to expose the service outside my machine for all devices connected to the network?
    – Ali Ourag
    Commented Nov 2, 2021 at 9:12
  • Specifically for minikube LAN access, there is one more networking layer to be aware of: LAN --> Host --> minikube VM. For this, you're probably using VirtualBox and can enable the port forwarding NAT feature to route the LAN traffic to the minikube VM. (See edited answer above for commands)
    – TrinitronX
    Commented Nov 3, 2021 at 11:04

One easy way is to have proxy for outside your machine, I can not comment due to low reputation. You can use apache or any other like HA, nginx

  • sorry, brother for the late reply but can you give me more details on how to setup a reverse proxy using Nginx ? like should I have to install it on my windows machine or in minikube ?
    – Ali Ourag
    Commented Nov 1, 2021 at 10:52
  • on your Windows machine Commented Nov 1, 2021 at 19:54
  • i alrady installed nginx and used this =====> ` server { listen 80; server_name localhost; location / { proxy_pass localhost:3000/api; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }` in my nginx.conf but it not redirect !!
    – Ali Ourag
    Commented Nov 2, 2021 at 9:16

It heavily depends on minikube's start --driver option. I was able to handle it with --driver=none, which requested the cri-docker.service to be running. Summarizing: Preinstall cri-docker service: e.g. Ubuntu 20:

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update -y
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

wget https://github.com/Mirantis/cri-dockerd/releases/download/v${VER}/cri-dockerd-${VER}.amd64.tgz
tar xvf cri-dockerd-${VER}.amd64.tgz
sudo mv cri-dockerd/cri-dockerd /usr/local/bin/
tar xvf cri-dockerd-${VER}.amd64.tgz
sudo mv cri-dockerd/cri-dockerd /usr/bin/
wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.service
wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.socket
sudo mv cri-docker.socket cri-docker.service /etc/systemd/system/
sudo sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
sudo systemctl daemon-reload
sudo systemctl enable cri-docker.service
sudo systemctl start cri-docker.socket
  1. run your minikube, e.g. minikube start --driver=none --container-runtime=docker , also check minikube ip
  2. deploy app - run your service
  3. expose the service
  4. run ingress ( as suggestet above - minikube addons enable ingress )
  5. you should now be able to access it externally.

PS Many thanks to the post creator: https://stackoverflow.com/a/60726849/6571708

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.