Minikube expose MySQL running on localhost as service
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If MySQL is running on your host machine, pods inside Minikube cannot reach it through localhost. Inside a pod, localhost means the pod itself, not your laptop or workstation.
The working pattern is to make MySQL reachable from Minikube on a host-facing address, then give Kubernetes workloads a stable name for that target. In local development, host.minikube.internal is usually the simplest host alias to start with.
Once that networking rule is understood, the rest of the setup is mostly verification and naming rather than Kubernetes magic.
Make the Host Database Reachable
First, confirm that MySQL is not listening only on loopback. If it binds only to 127.0.0.1, traffic from Minikube will never arrive.
A typical MySQL configuration looks like this:
After restarting MySQL, verify that Minikube can reach the port:
If that connection test fails, fix host networking, firewall rules, or MySQL bind settings before writing Kubernetes manifests.
Use the Host Alias Directly
For simple local development, the fastest solution is often to point your application straight at host.minikube.internal:
This avoids unnecessary Kubernetes objects when the real goal is just "pod reaches MySQL on the host."
Add a Kubernetes Service Name if You Want One
If you want an in-cluster DNS name, an ExternalName service is a reasonable lightweight option:
Your application can then use mysql-on-host as the host name and still connect on port 3306.
This does not turn the host MySQL into a normal in-cluster service implementation. It just gives you a stable Kubernetes DNS alias.
That distinction matters because service discovery will work, but lifecycle management and health semantics still belong to the host process, not the cluster.
Test from a Temporary Pod
Before wiring your real application to it, test the connection from inside the cluster:
If DNS resolves but login fails, the remaining issues are usually:
- MySQL user permissions
- password or database configuration
- host firewall rules
Those are MySQL or host-networking problems, not Kubernetes service-definition problems.
Know When to Run MySQL In Cluster Instead
Using a host MySQL instance is fine for local development, especially if you already have seeded data on your machine. But it is not a good substitute for a real Kubernetes-style database deployment when you need to test:
- persistent volumes
- secrets
- service selectors
- pod-to-service traffic patterns
For those cases, running MySQL inside Minikube with a normal Service is closer to production behavior.
Common Pitfalls
- Expecting
localhostin a pod to refer to the host machine. - Leaving MySQL bound only to
127.0.0.1. - Creating Kubernetes objects before proving the host port is reachable from Minikube.
- Assuming a
Serviceobject can solve firewall or MySQL permission problems. - Using a host database for scenarios that really need an in-cluster database deployment.
Summary
- Pods in Minikube cannot use
localhostto reach MySQL running on the host. - Make MySQL listen on a host-reachable interface.
- Test connectivity first with
host.minikube.internal. - Use an
ExternalNameservice if you want a Kubernetes DNS alias. - Run MySQL inside Minikube when you need realistic Kubernetes database behavior.

