<p>I have an image, which is a simple web server running on port 80. When I run it locally, I get:</p>
<pre class="lang-sh prettyprint-override"><code>The app is listening at http://localhost:80

</code></pre>
<p>and everything is fine.</p>
<p>However, when I deploy the following to K8s, it crashes constantly.</p>
<p>Deployment:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: apps
  labels:
    app: my-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: myimage:dev
        imagePullPolicy: Always
        ports:
        - containerPort: 80
</code></pre>
<p>Logs of one of the pods:</p>
<pre><code>node:events:371
throw er; // Unhandled 'error' event
^

Error: listen EACCES: permission denied 0.0.0.0:80
at Server.setupListenHandle [as _listen2] (node:net:1298:21)
at listenInCluster (node:net:1363:12)
at Server.listen (node:net:1450:7)
at Function.listen (/app/node_modules/express/lib/application.js:618:24)
at Object.&lt;anonymous&gt; (/app/index.js:17:5)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1342:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '0.0.0.0',
port: 80
}
</code></pre>
<p>Why my image is able to run successfully on my local machine, and it fails on the Kubernetes?</p>

mnj
<p>Non-root users (non privileged) can't open a listening socket on ports below 1024.</p>
<p>You can find the solution <a href="https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps#give-safe-user-permission-to-use-port-80" rel="nofollow noreferrer">here</a>:</p>
<blockquote>
<p>Remember, we do NOT want to run your applications as the root user, but there is a hitch:  <strong>your safe user does not have permission to use the default HTTP port (80)</strong>. You goal is to be able to publish a website that visitors can use by navigating to an easy to use URL like  <a href="http://example.com/" rel="nofollow noreferrer">http://example.com</a>.</p>
<p>Unfortunately, unless you sign on as root, you’ll normally have to use a URL like  <a href="http://example.com:3000/" rel="nofollow noreferrer">http://example.com:3000</a>  - notice the port number.</p>
<p>A lot of people get stuck here, but the solution is easy. There a few options but this is the one I like. Type the following commands:</p>
</blockquote>
<pre><code>sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
</code></pre>
<p>You can also see <a href="https://stackoverflow.com/questions/60372618/nodejs-listen-eacces-permission-denied-0-0-0-080">this similar question</a>.</p>
