<p>Similar question: <a href="https://stackoverflow.com/questions/37449121/how-to-expose-kube-dns-service-for-queries-outside-cluster">How to expose kube-dns service for queries outside cluster?</a></p>

<p>I have a PerconaDB instance in a VM in Google compute engine. Next to it is running Kubernetes cluster where services connect to the PerconaDB.</p>

<p>When I login with MySQL client and do <code>show processlist;</code>, I see following:</p>

<pre><code>| 175 | user       | 10.12.142.24:46124 | user | Sleep   |   14 |                                       | NULL                                                                                                 |         0 |             0 |
| 176 | user       | 10.12.142.24:46126 | user | Sleep   |   14 |                                       | NULL                                                                                                 |         0 |             0 |
| 177 | user       | 10.12.122.42:60806 | user | Sleep   |    2 |                                       | NULL                                                                                                 |         0 |             0 |
| 178 | user       | 10.12.122.43:55164 | user | Sleep   |   14 |                                       | NULL                                                                                                 |         1 |             0 |
| 179 | user       | 10.12.122.43:55166 | user | Sleep   |    4 |                                       | NULL                                                                                                 |         1 |             0 |
| 180 | user       | 10.12.141.11:35944 | user | Sleep   |   14 |                                       | NULL                                                                                                 |         1 |             0 |
</code></pre>

<p>Notice the number of different IPs for which I have no idea what they belong to. These are the pods inside the Kubernetes cluster and I would like to know their names so instead of <code>10.12.142.24:46124</code> I could see <code>myservice-0dkd0:46124</code>.</p>

<p>I thought the solution would be to somehow link the <code>kube-dns</code> service to the PerconaDB VM, but I have no idea, how to do that correctly. Also this is now running in production, so I don't want to experiment too much.</p>

<p>At this moment, the reverse DNS lookup or PTR type lookup for a POD IP is possible only in case of pods that are part of a headless service (details: <a href="https://github.com/kubernetes/dns/pull/25" rel="nofollow noreferrer">https://github.com/kubernetes/dns/pull/25</a>) but even that has it's limitations. Furthermore, kubernetes has no default per POD dns name at all, even inside kubernetes cluster you are not able to say <code>curl http://&lt;pod_name&gt;</code>. You have services for that. What you are asking for is not really achievable with kubernetes and DNS as it is now. Please do remember that PTR record (IP->name) should go hand in hand with regular record for resolving name (name->IP) which also makes things complicated, and means you can not have just <code>myservice-0dkd0</code> in there.</p>

<p>That said, you can achieve what you want in a non-dns way here. Assuming you run on linux, you can use <code>/etc/hosts</code> to maintain a name-to-ip and ip-to-name list that is exclusive to that particular system, and does not need to adhere to all the limitations of real DNS.</p>

<p>If, on your mysql host you run something like following say from cron every 1 min, you should get correctly mapped names in your <code>/etc/hosts</code> almost all the time :</p>

<pre><code>NAMESPACE=default
sed -i "/^[0-9\.]*\t[a-zA-Z0-9-]*\.$NAMESPACE/d" /etc/hosts
kubectl get pod --namespace default --field-selector=status.phase==Running -o jsonpath='{range .items[*]}{.status.podIP}{"\t"}{.metadata.name}.{.metadata.namespace}{"\n"}{end}' &gt;&gt; /etc/hosts
</code></pre>
