<p>Can anybody let me know how can we access the service deployed on one pod via another pod in a kubernetes cluster?</p>

<p><em>Example:</em></p>

<p>There is a nginx service which is deployed on Node1 (having pod name as nginx-12345) and another service which is deployed on Node2 (having pod name as service-23456). Now if 'service' wants to communicate with 'nginx' for some reason, then how can we access 'nginx' inside the 'service-23456' pod?</p>

Aditya Datta
<p>There are various ways to access the service in kubernetes, you can expose your services through NodePort or LoadBalancer and access it outside the cluster. </p>

<p>See the official documentation of <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-services/" rel="noreferrer">how to access the services</a>.</p>

<p>Kubernetes official document states that:</p>

<blockquote>
  <p>Some clusters may allow you to ssh to a node in the cluster. From there you may be able to access cluster services. This is a non-standard method, and will work on some clusters but not others. Browsers and other tools may or may not be installed. Cluster DNS may not work.</p>
</blockquote>

<p>So access a service directly from other node is dependent on which type of Kubernetes cluster you're using.</p>

<p>EDIT:</p>

<p>Once the service is deployed in your cluster you should be able to contact the service using its name, and <code>Kube-DNS</code> will answer with the correct <code>ClusterIP</code> to speak to your final pods. ClusterIPs are governed by IPTables rules created by kube-proxy on Workers that NAT your request to the final container’s IP.</p>

<p>The Kube-DNS naming convention is <code>service.namespace.svc.cluster-domain.tld</code> and the default cluster domain is <code>cluster.local</code>.</p>

<p>For example, if you want to contact a service called <code>mysql</code> in the <code>db</code> namespace from any namespace, you can simply speak to <code>mysql.db.svc.cluster.local</code>.</p>

<p>If this is not working then there might be some issue with kube-dns in your cluster.
Hope this helps. </p>

<p>EDIT2 :
There are some known issue with dns resolution in ubuntu, Kubernetes official document states that</p>

<blockquote>
  <p>Some Linux distributions (e.g. Ubuntu), use a local DNS resolver by default (systemd-resolved). Systemd-resolved moves and replaces /etc/resolv.conf with a stub file that can cause a fatal forwarding loop when resolving names in upstream servers. This can be fixed manually by using kubelet’s --resolv-conf flag to point to the correct resolv.conf (With systemd-resolved, this is /run/systemd/resolve/resolv.conf). kubeadm 1.11 automatically detects systemd-resolved, and adjusts the kubelet flags accordingly.</p>
</blockquote>
