<p>I'm attempting to start my Express.js application on GKE, however no matter which port I specify, I always get an error like so:</p>
<pre><code>Error: listen EACCES: permission denied tcp://10.3.253.94:3000
    at Server.setupListenHandle [as _listen2] (net.js:1296:21)
    at listenInCluster (net.js:1361:12)
    at Server.listen (net.js:1458:5)
    at Function.listen (/srv/node_modules/express/lib/application.js:618:24)
    at Object.&lt;anonymous&gt; (/srv/src/index.js:42:5)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
</code></pre>
<p>I've tried multiple ports (8080, 8000, 3000). I've set the user to <code>root</code> in the Docker image.</p>
<p>Here's my setup:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: api
  name: api
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      containers:
        - image: gcr.io/ellioseven-kbp/journal-api:1.0.14
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
          name: api
</code></pre>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: api
  name: api
  namespace: default
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: 3000
  selector:
    app: api
  type: NodePort
</code></pre>
<pre><code>FROM node:12-alpine
ENV PATH /srv/node_modules/.bin:$PATH
ENV API_PORT 3000
ENV REDIS_HOST redis
COPY . /srv
WORKDIR /srv
ENV PATH /srv/node_modules/.bin:$PATH
RUN yarn install
CMD yarn start
EXPOSE 3000
USER root
</code></pre>
<pre><code>const port = process.env.API_PORT || 3000
app.listen(port, () =&gt; console.log(&quot;Listening on &quot; + port))
</code></pre>
<p>I'm at a complete loss trying to solve this, any help would be greatly appreciated.</p>

ellioseven
<p>Your issue is on <a href="https://github.com/kubernetes/kubernetes/issues/18219" rel="nofollow noreferrer">environment variable conflicting with the service name</a>.</p>
<p><a href="https://v1-16.docs.kubernetes.io/docs/concepts/containers/container-environment-variables/#cluster-information" rel="nofollow noreferrer">According to Kubernetes docs</a></p>
<blockquote>
<p>For a service named <code>foo</code> that maps to a Container named <code>bar</code>, the
following variables are defined:</p>
<pre class="lang-sh prettyprint-override"><code>FOO_SERVICE_HOST=&lt;the host the service is running on&gt;
FOO_SERVICE_PORT=&lt;the port the service is running on&gt;
</code></pre>
</blockquote>
<p>Change either the service name or the environment variable</p>
<p>For e.g. use <code>API_PORT_NUMBER</code> instead of <code>API_PORT</code></p>
