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.
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:
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:
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:
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:
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:
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-forwardfor local debugging - use
minikube service --urlfor a quick service URL - use
minikube tunnelwhen you specifically needLoadBalancerbehavior
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:
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
LoadBalancerservices to get an external IP without runningminikube tunnel. - Forgetting that
kubectl port-forwardonly 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-forwardandminikube service --url. - '
NodePortworks well withminikube service.' - '
LoadBalancerservices usually requireminikube 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
- Exposing a TCP port out of cluster in Kubernetes using nginx-Ingress
- Extend service in docker-compose 3
- external-ip remains pending on controller-service after installation of Nginx Ingress Controller on AWS EKS
- External DNS Configure it in all namespaces
- Exposing a port on a live Docker container
- Exposing Kafka as a public API
- failed calling webhook vingress.elbv2.k8s.aws
- Failed create pod sandbox rpc error code Unknown desc NetworkPlugin cni failed to set up pod network

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.