gpt4 book ai didi

javascript - GKE 错误 : listen EACCES: permission denied on any port

转载 作者:行者123 更新时间:2023-12-02 12:09:53 24 4
gpt4 key购买 nike

我正在尝试在 GKE 上启动我的 Express.js 应用程序,但是无论我指定哪个端口,我总是会收到如下错误:

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.<anonymous> (/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)
我尝试了多个端口(8080、8000、3000)。我已将用户设置为 root在 Docker 镜像中。
这是我的设置:
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
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
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
const port = process.env.API_PORT || 3000
app.listen(port, () => console.log("Listening on " + port))
我在试图解决这个问题时完全不知所措,任何帮助将不胜感激。

最佳答案

看起来它不能只绑定(bind)到 3000港口。它可以是以下任何一种:

  • 不绑定(bind)到 0.0.0.0 .你可以试试:
    app.listen('3000','0.0.0.0',()=>{
    console.log("server is listening on 3000 port");
    })
  • 您在容器中以非特权用户身份运行。看看您是否可以启动一个测试 pod 并在它启动后运行该命令。
      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
    command: [ "/bin/bash", "-c", "--" ] 👈
    args: [ "while true; do sleep 30; done;" ] 👈
    ports:
    - containerPort: 3000
    name: api
    然后你可以连接到 pod 并尝试启动你的应用程序
    kubectl exec -it <pod-name> bash

  • ✌️

    关于javascript - GKE 错误 : listen EACCES: permission denied on any port,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64073138/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com