<p>I have 2 pods, one for server and one for client. both have services. both services is of type NodePort.</p>
<blockquote>
<pre><code>basic-to-do-client   NodePort    10.110.80.200   &lt;none&gt;        80:32295/TCP     44h     appName=basic-to-do-client
basic-to-do-server   NodePort    10.102.32.120   &lt;none&gt;        3000:31912/TCP   45h     appName=basic-to-do-server
</code></pre>
</blockquote>
<p>when trying to reach the server from the client js code, I used the svc name and port.</p>
<blockquote>
<p>http://basic-to-do-server:3000</p>
</blockquote>
<p>and I get nothing.
when trying to make a curl request from the client pod, I get the data I need, but it doesn't work from the js code.</p>
<p>do I not understand something correctly? As the client code runs in a pod inside the cluster, shouldn't it recognize the svc name as a valid dns?</p>
<p>this is a simplified api call:</p>
<pre><code>const API_URL = &quot;http://basic-to-do-server:3000/api&quot;  

async function addTodo(text) {
            try {
                const response = await fetch(`${API_URL}/todos`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ text }),
                });
                const todo = await response.json();
                fetchTodos();
            } catch (error) {
                console.error('Error adding todo:', error);
            
</code></pre>
<p>The error i get in the chrome console is:</p>
<pre><code>GET http://basic-to-do-server:3000/api/todos net::ERR_NAME_NOT_RESOLVED
</code></pre>
<p>can anyone explain me what am i missing?</p>

CC BY-SA 4.0
2024-10-27T22:14:21.010Z
If the curl request from client pod to server pod is OK and if JavaScript request from client pod to server pod is not OK, the problem is with JavaScript code. If you are trying to access http://basic-to-do-server:3000 from Chrome on your laptop, you need to create a DNS entry to resolve basic-to-do-server to NodePort service IP address.
Indika K
CC BY-SA 4.0
2024-10-28T07:48:38.257Z
Yes, thank you. I got what i was missing. The client code isn't actually running on the cluster, so it can't communicate through an internal dns name
stonedvolk
<kubernetes>
Client Kubernetes pod can't connect to server pod using internal svc name
stonedvolk
# Client Kubernetes pod can't connect to server pod using internal svc name

(Asked by: username_0 on 2024-10-25)

I have 2 pods, one for server and one for client. both have services. both services is of type NodePort.

basic-to-do-client   NodePort    10.110.80.200           80:32295/TCP     44h     appName=basic-to-do-client
basic-to-do-server   NodePort    10.102.32.120           3000:31912/TCP   45h     appName=basic-to-do-server


when trying to reach the server from the client js code, I used the svc name and port.

http://basic-to-do-server:3000

and I get nothing.
when trying to make a curl request from the client pod, I get the data I need, but it doesn't work from the js code.
do I not understand something correctly? As the client code runs in a pod inside the cluster, shouldn't it recognize the svc name as a valid dns?
this is a simplified api call:
const API_URL = "http://basic-to-do-server:3000/api"  

async function addTodo(text) {
            try {
                const response = await fetch(`${API_URL}/todos`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ text }),
                });
                const todo = await response.json();
                fetchTodos();
            } catch (error) {
                console.error('Error adding todo:', error);
            

The error i get in the chrome console is:
GET http://basic-to-do-server:3000/api/todos net::ERR_NAME_NOT_RESOLVED

can anyone explain me what am i missing?

**Tags:** kubernetes

> **Comments:**
> **username_1**: If the curl request from client pod to server pod is OK and if JavaScript request from client pod to server pod is not OK, the problem is with JavaScript code. If you are trying to access http://basic-to-do-server:3000 from Chrome on your laptop, you need to create a DNS entry to resolve basic-to-do-server to NodePort service IP address.  
> **username_0**: Yes, thank you. I got what i was missing. The client code isn't actually running on the cluster, so it can't communicate through an internal dns name  

---

## 0 answers

