<p>These are my yaml files referenced by <a href="https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/" rel="nofollow noreferrer">here (kubernetes.io/docs)</a></p>
<p><a href="https://gist.github.com/darknisfire/8010f989fb3f90b59fab1dd50daa872f" rel="nofollow noreferrer">deployment gists</a></p>
<p>And I use command <code>kubectl apply -f backend-deployment.yaml -f frontend-configmap.yaml -f frontend-deployment.yaml</code></p>
<p>Backend were launched successfully, but Frontend occured error.</p>
<pre><code>[emerg] 1#1: host not found in upstream &quot;backend-service&quot; in /etc/nginx/conf.d/nginx.conf:2
#nginx: [emerg] host not found in upstream &quot;backend-service&quot; in /etc/nginx/conf.d/nginx.conf:2
</code></pre>
<p>Even if 'backend-service' is declared, nginx couldn't recognize it.</p>
<p>Command <code>nslookup backend-service</code> result is:</p>
<pre><code>Server:         127.0.0.53
Address:        127.0.0.53#53

** server can't find backend-service: SERVFAIL
</code></pre>
<p>What am I missing?</p>

01hanst
<p>I have gotten closer to the issue/solution.</p>
<p>First of all, you if the images in your supplied answer are correct, you are running nginx in your backend deployment and node-js server on your frontend deployment. This is a mistake.</p>
<p>after changing the images frontend is running (as expected) but backend pod is crashing.</p>
<p>However, the backend pod is successfully resolving the mysql-service to its internal clusterIp and I appear to have wrong authentication setup.</p>
<pre><code>`&gt; server@1.0.0 start /usr/src/app
 &gt; node backend.js
 
 (node:18) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
 (Use `node --trace-warnings ...` to show where the warning was created)
 (node:18) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
 (node:18) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
 (node:18) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
 listening on 3000
 events.js:292
       throw er; // Unhandled 'error' event
       ^
 
 Error: connect ECONNREFUSED 10.100.77.32:3306
     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1142:16)
     --------------------
     at Protocol._enqueue (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
     at Protocol.handshake (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
     at Connection.connect (/usr/src/app/node_modules/mysql/lib/Connection.js:116:18)
     at Object.&lt;anonymous&gt; (/usr/src/app/backend.js:58:12)
     at Module._compile (internal/modules/cjs/loader.js:1185:30)
     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
     at Module.load (internal/modules/cjs/loader.js:1034:32)
     at Function.Module._load (internal/modules/cjs/loader.js:923:14)
     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
     at internal/main/run_main_module.js:17:47
 Emitted 'error' event on Connection instance at:
     at Connection._handleProtocolError (/usr/src/app/node_modules/mysql/lib/Connection.js:423:8)
     at Protocol.emit (events.js:315:20)
     at Protocol._delegateError (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
     at Handshake.&lt;anonymous&gt; (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:153:12)
     at Handshake.emit (events.js:315:20)
     at Handshake.Sequence.end (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:12)
     at Protocol.handleNetworkError (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:369:14)
     at Connection._handleNetworkError (/usr/src/app/node_modules/mysql/lib/Connection.js:418:18)
     at Socket.emit (events.js:315:20)
     at emitErrorNT (internal/streams/destroy.js:96:8)
     at emitErrorCloseNT (internal/streams/destroy.js:68:3)
     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
   errno: -111,
   code: 'ECONNREFUSED',
   syscall: 'connect',
   address: '10.100.77.32',
   port: 3306,
 &gt; node backend.js
   fatal: true
 }
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! server@1.0.0 start: `node backend.js`
 npm ERR! Exit status 1
 npm ERR! 
 npm ERR! Failed at the server@1.0.0 start script.
 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
 
 npm ERR! A complete log of this run can be found in:
 npm ERR!     /root/.npm/_logs/2021-07-21T08_46_32_833Z-debug.log`
</code></pre>
<p>if you look at the log. it says it tries to connect to 10.100.77.32:3306 and the output of kubectl get svc is the following <code>mysql-service      ClusterIP   10.100.77.32     &lt;none&gt;        3306/TCP       17m </code></p>
<p>with the matching ip of my service.</p>
<p>kubectl get endpoints shows that the mysql-service has indeed found an endpoint:</p>
<pre><code>mysql-service      ClusterIP   10.100.77.32     &lt;none&gt;        3306/TCP       17m
</code></pre>
<p>and here is additional log information showing that the authentication mechanism of your nodejs application appearently is not working for the mysql pod.</p>
<pre><code>  Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Handshake.Sequence._packetToError (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Handshake.ErrorPacket (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
    at Protocol._parsePacket (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/usr/src/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/usr/src/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.&lt;anonymous&gt; (/usr/src/app/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.&lt;anonymous&gt; (/usr/src/app/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:296:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
    --------------------
    at Protocol._enqueue (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/usr/src/app/node_modules/mysql/lib/Connection.js:116:18)
    at Object.&lt;anonymous&gt; (/usr/src/app/backend.js:58:12)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
Emitted 'error' event on Connection instance at:
    at Connection._handleProtocolError (/usr/src/app/node_modules/mysql/lib/Connection.js:423:8)
    at Protocol.emit (events.js:315:20)
    at Protocol._delegateError (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
    at Handshake.&lt;anonymous&gt; (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:153:12)
    at Handshake.emit (events.js:315:20)
    at Handshake.Sequence.end (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:12)
    at Handshake.ErrorPacket (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Handshake.js:125:8)
    at Protocol._parsePacket (/usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    [... lines matching original stack trace ...]
    at readableAddChunk (_stream_readable.js:272:9) {
  code: 'ER_NOT_SUPPORTED_AUTH_MODE',
  errno: 1251,
  sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
  sqlState: '08004',
  fatal: true
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server@1.0.0 start: `node backend.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the server@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-07-21T08_55_22_133Z-debug.log
</code></pre>
<p>However, with the changes suggest at the beginning of the answer the issues around resolving the service name and communicating inside of kubernetes should be resolved.</p>
