<p>I have a simple MYSQL pod sitting behind a MYSQL service. </p>

<p>Additionally I have another pod that is running a python process that is trying to connect to the MYSQL pod. </p>

<p>If I try connecting to the IP address of the MYSQL pod manually from the python pod, everything is A-OK. However if I try connecting to the MYSQL <em>service</em> then I get an error that I can't connect to MYSQL. </p>

<pre><code>grant@grant-Latitude-E7450:~/k8s/objects$ kubectl describe pod mysqlpod 
Name:       mysqlpod
Namespace:  default
Node:       minikube/192.168.99.100
Start Time: Fri, 20 Jan 2017 11:10:50 -0600
Labels:     &lt;none&gt;
Status:     Running
IP:     172.17.0.4
Controllers:    &lt;none&gt;

grant@grant-Latitude-E7450:~/k8s/objects$ kubectl describe service mysqlservice
Name:           mysqlservice
Namespace:      default
Labels:         &lt;none&gt;
Selector:       db=mysqllike
Type:           ClusterIP
IP:         None
Port:           &lt;unset&gt; 3306/TCP
Endpoints:      172.17.0.5:3306
Session Affinity:   None
No events.

grant@grant-Latitude-E7450:~/k8s/objects$ kubectl describe pod basic-python-model
Name:       basic-python-model
Namespace:  default
Node:       minikube/192.168.99.100
Start Time: Fri, 20 Jan 2017 12:01:50 -0600
Labels:     db=mysqllike
Status:     Running
IP:     172.17.0.5
Controllers:    &lt;none&gt;
</code></pre>

<p>If I attach to my python container and do an nslookup of the mysqlservice, then I'm actually getting the <strong>wrong</strong> IP. As you saw above the IP of the mysqlpod is 172.17.0.4 while nslookup mysqlservice is resolving to 172.17.0.5. </p>

<pre><code>grant@grant-Latitude-E7450:~/k8s/objects$ k8s exec -it basic-python-model bash
[root@basic-python-model /]# nslookup mysqlservice                    
Server:     10.0.0.10
Address:    10.0.0.10#53

Name:   mysqlservice.default.svc.cluster.local
Address: 172.17.0.5
</code></pre>

<p>I'm fairly new to kubernetes, but I've been banging my head on this issue for a few hours and I can't seem to understand what I'm doing wrong.</p>

<p>So this was the <em>exact correct</em> behavior but I just misconfigured my pods.</p>

<p>For future people who are stuck:</p>

<p>The selector defined in a kubernetes service must match the label of the pod(s) you wish to serve. IE) In my MySqlService.yaml file I have the name selector for "mysqlpod":</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysqlservice
spec:
  clusterIP: None 
  ports:
    - port: 3306
      targetPort: 3306
  selector:
    name: mysqlpod 
</code></pre>

<p>Thus in my MySqlPod.yaml file I need an exactly matching label. </p>

<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: mysqlpod
  labels:
    name: mysqlpod
spec:
  ...
</code></pre>
