<p>So, I wrote an API that is listening on the the path <code>/api/v1/books</code> and is deployed as a deployment on my k8s cluster, created service (<code>restapi-service</code>) so that we can call that from another pods. 
Now I created another deployment (<code>restapi-ui-deployment</code>) that just  has a <code>.html</code> page and and its being deployed on nginx, which eventually calls the the service that we have created earlier to get the response. 
Now, the issue is when I exec into the pods of <code>restapi-ui-deployment</code> I am successfully able to curl <code>http://restapi-service:8081/api/v1/books</code>. But if  we are trying to do the same thing from .html page that is deployed I get </p>

<pre><code>GET http://restapi-service:8081/api/v1/books net::ERR_NAME_NOT_RESOLVED
</code></pre>

<p>Below is the code that is being deployed as <code>restapi-ui-deployment</code></p>

<pre><code>if (xmlObj != null){
      xmlObj.open("GET", "http://restapi-service:8081/api/v1/books", true)
      xmlObj.onreadystatechange = processResponse;
      xmlObj.send(null)
    }
    else{
      console.log("There was an error getting the object.")
    }
    function processResponse(){
      if (xmlObj.status == 200 &amp;&amp; xmlObj.readyState == 4){
        console.log("Got the response successfully")
        response = xmlObj.responseText
      }
      else{
        console.log("There was an issue getting the response.")
      }
    }

</code></pre>

viveksinghggits
<p>I am afraid that you are confused about the way your application works. The XmlHttpRequest is originating in a webbrowser, therefore outside of the kubernetes cluster, not from nginx inside your cluster. (nginx serves the html page)
The kubernetes dns is not available outside of kubernetes, nor would a connection to  a ClusterIP work from the outside.
Solution: Create an appropriate Ingress and call that from your frontend or provide a proxy on your nginx where you got the frontend delivered. (That would lead to really getting the request origin as your nginx)</p>
