OpenShift环境下phpMyAdmin连接MySQL提示No Route to Host问题求助
Hey there, let's work through this "No Route to Host" issue between phpMyAdmin and your MySQL service in OpenShift. Since you shared part of your MySQL Service YAML, let's start with the most common, actionable checks first:
First up, verify your MySQL service is running and has a valid ClusterIP assigned. Run this command in your OpenShift project namespace:
oc get svc mysql
You should see a valid ClusterIP listed (not <none>). If it shows <none>, that means the service isn't tied to any running pods. Double-check your MySQL pod status with oc get pods—and make sure the service's spec.selector matches the labels on your MySQL pod. Looking at your partial YAML, the service has labels app: mysql-persistent—your MySQL pod needs to have that exact label for the service to find it.
In OpenShift, services are discoverable via internal DNS using their service name. Instead of hardcoding a ClusterIP (which can change), phpMyAdmin should connect to mysql:3306 (assuming your MySQL service uses the standard port 3306).
Check your phpMyAdmin's configuration—whether it's using environment variables, a config map, or a deployment YAML—ensure the database host is set to the service name mysql, not an IP address.
OpenShift uses Network Policies to control traffic between pods. If a policy is in place that blocks incoming traffic to MySQL from phpMyAdmin, you'll get this "No Route to Host" error.
Check if there are any network policies in your namespace:
oc get networkpolicy
If policies exist, make sure one allows traffic from phpMyAdmin's pods to MySQL. For example, a policy like this would grant access:
apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-phpmyadmin-to-mysql spec: podSelector: matchLabels: app: mysql-persistent ingress: - from: - podSelector: matchLabels: app: phpmyadmin
Let's narrow down the issue by testing from the phpMyAdmin pod itself. First, exec into the pod:
oc exec -it <your-phpmyadmin-pod-name> -- /bin/bash
Then try resolving the MySQL service via DNS:
nslookup mysql
If that fails, there might be a DNS issue in your OpenShift cluster. If DNS works, test port connectivity with telnet or nc:
telnet mysql 3306 # Or if telnet isn't installed: nc -zv mysql 3306
This will tell you if the MySQL port is reachable from the phpMyAdmin pod.
Make sure your MySQL pod is listening on all interfaces (not just localhost), so the service can route traffic to it. Exec into the MySQL pod:
oc exec -it <your-mysql-pod-name> -- /bin/bash
Then check listening ports:
netstat -tulpn | grep mysql
You should see output showing MySQL listening on 0.0.0.0:3306—if it's only 127.0.0.1, you'll need to adjust your MySQL config to bind to all interfaces.
If none of these steps fix the issue, could you share the full MySQL Service YAML (including the spec section with ports and selector) and your phpMyAdmin deployment configuration? That will help us dig into more edge cases.
内容的提问来源于stack exchange,提问作者Srikant Karnani

