<p>I've set up a Kubernetes deployment and service for MySQL. I cannot access the MySQL service from any pod using its DNS name... It just times out. Any other port refuses the connection immediately, but the port in my service configuration times out after ~10 seconds.</p>

<ol>
<li>I am able to resolve the MySQL Pod DNS.</li>
<li>I cannot ping the host.</li>
</ol>

<p>Service.yml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  labels:
    run: mysql-service
spec:
  ports:
  - port: 3306
    protocol: TCP
  - port: 3306
    protocol: UDP
  selector:
    run: mysql-service
</code></pre>

<p>Deployment.yml</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-service
  labels:
    app: mysql-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql-service
  template:
    metadata:
      labels:
        app: mysql-service
    spec:
      containers:
      - name: 'mysql-service'
        image: mysql:5.5
        env:
          - name: MYSQL_ROOT_PASSWORD
            value: some_password
          - name: MYSQL_DATABASE
            value: some_database
        ports:
          - containerPort: 3306
</code></pre>

Monstrum
<p>Your deployment (and more specifically its pod spec) says</p>

<pre><code>labels:
  app: mysql-service
</code></pre>

<p>but your service says</p>

<pre><code>selector:
  run: mysql-service
</code></pre>

<p>These don't match, so your service isn't attaching to the pod.  You should also see this if you <code>kubectl describe service mysql-service</code>, the "endpoints" list will be empty.</p>

<p>Change the service's selector to match the pod's labels (or vice versa) and this should be better.</p>
