minikube
kubernetes
port-forwarding
tutorials
networking

Expose port in minikube

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

In Minikube, the easiest way to expose an application depends on what you need. For quick local access, kubectl port-forward is usually simplest; for a Kubernetes-style service URL, minikube service works well with NodePort; and for LoadBalancer services, minikube tunnel is the missing piece.

Start with a Service

Pods are not the stable interface you should normally expose directly. The usual pattern is to create a Service that targets your app pods by label.

Example deployment and service:

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: web
5spec:
6  replicas: 1
7  selector:
8    matchLabels:
9      app: web
10  template:
11    metadata:
12      labels:
13        app: web
14    spec:
15      containers:
16        - name: web
17          image: nginx:stable
18          ports:
19            - containerPort: 80
20---
21apiVersion: v1
22kind: Service
23metadata:
24  name: web
25spec:
26  selector:
27    app: web
28  ports:
29    - port: 80
30      targetPort: 80
31  type: NodePort

Apply it with kubectl apply -f web.yaml.

Option 1: Use minikube service

If the service is NodePort, Minikube can open or print the reachable URL for you:

bash
minikube service web --url

This is often the most convenient local workflow. Minikube resolves the node IP and node port so you do not need to inspect the service manually.

You can still inspect the service yourself:

bash
kubectl get svc web

Look for the PORT(S) column. A value like 80:31080/TCP means the service is exposed on port 31080 of the Minikube node.

Option 2: Use kubectl port-forward

For one-off debugging, kubectl port-forward is even simpler because it avoids NodePort entirely:

bash
kubectl port-forward service/web 8080:80

Now the app is available on http://127.0.0.1:8080. This is a strong default for development because it is explicit, easy to tear down, and does not require cluster-level exposure.

Option 3: Use LoadBalancer with minikube tunnel

If your manifest uses type: LoadBalancer, Minikube does not magically create an external IP unless you run:

bash
minikube tunnel

After that, kubectl get svc will usually show an external IP for the service. This is useful when you want to test manifests that are meant to behave more like a cloud cluster.

Pick the Right Tool

A simple decision rule works well:

  • use kubectl port-forward for local debugging
  • use minikube service --url for a quick service URL
  • use minikube tunnel when you specifically need LoadBalancer behavior

If the goal is just "open my app in a browser," minikube service <name> --url is usually enough.

Troubleshoot the Route End to End

If the port still is not reachable, inspect the path in order instead of guessing. Start by checking that the pod is running, then confirm that the service has endpoints, and only then inspect the exposure mechanism:

bash
kubectl get pods
kubectl get svc web
kubectl get endpoints web

If the endpoints list is empty, the problem is usually a selector mismatch or a pod that never became ready. If endpoints exist but the app is still unavailable, verify that the container is listening on the same port your service forwards to.

Common Pitfalls

  • Exposing a pod directly and then losing connectivity when the pod is recreated. Use a service as the stable endpoint.
  • Expecting LoadBalancer services to get an external IP without running minikube tunnel.
  • Forgetting that kubectl port-forward only works while the command stays running.
  • Creating a service whose selector does not match the pod labels. In that case, the service exists but has no endpoints.
  • Debugging networking before confirming that the pod is healthy and actually listening on the expected container port.

Summary

  • In Minikube, the fastest exposure methods are kubectl port-forward and minikube service --url.
  • 'NodePort works well with minikube service.'
  • 'LoadBalancer services usually require minikube tunnel.'
  • Always expose a service rather than depending on a pod IP.
  • Verify pod health, service selectors, and container ports before assuming it is a networking problem.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.