<p>I have deployed mongodb on Kubernetes using mongodb-operator (verison: 1.9.2). The ReplicaSet consists of 3 instances: 1 primary and 2 secondary. I am able to access the ReplicaSet from any of given Kubernetes pods but if I try to do the same from the local machine  with pymongo client I am getting error as shown below. Can anyone suggest the reason for such behavior?</p>
<pre><code>pymongo.errors.ServerSelectionTimeoutError: mongodb-2.mongodb-svc.mongodb-new.svc.cluster.local:27017: [Errno -2] Name or service not known,mongodb-0.mongodb-svc.mongodb-new.svc.cluster.local:27017: [Errno -2] Name or service not known,mongodb-1.mongodb-svc.mongodb-new.svc.cluster.local:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: &lt;TopologyDescription id: 610292f511a5060cc91f8a11, topology_type: ReplicaSetNoPrimary, servers: [&lt;ServerDescription ('mongodb-0.mongodb-svc.mongodb-new.svc.cluster.local', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb-0.mongodb-svc.mongodb-new.svc.cluster.local:27017: [Errno -2] Name or service not known',)&gt;, &lt;ServerDescription ('mongodb-1.mongodb-svc.mongodb-new.svc.cluster.local', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb-1.mongodb-svc.mongodb-new.svc.cluster.local:27017: [Errno -2] Name or service not known',)&gt;, &lt;ServerDescription ('mongodb-2.mongodb-svc.mongodb-new.svc.cluster.local', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb-2.mongodb-svc.mongodb-new.svc.cluster.local:27017: [Errno -2] Name or service not known',)&gt;]&gt;
</code></pre>

steve steel
<p>I have posted Community wiki answer for better visibility.</p>
<p>As <a href="https://stackoverflow.com/users/13866186/steve-steel">steve steel</a> has mentioned in the comment, he has found the solution in <a href="https://stackoverflow.com/questions/44730112/exposing-mongodb-on-kubernetes-statefulsets-to-external-world">this link</a>:</p>
<blockquote>
<p>I have found this link helpful: <a href="https://stackoverflow.com/questions/44730112/exposing-mongodb-on-kubernetes-statefulsets-to-external-world">Exposing mongodb on kubernetes statefulsets to external world</a></p>
</blockquote>
