简体   繁体   English

nodemon 在 kubernetes 环境中运行时未启动

[英]nodemon not starting when run in kubernetes environment

I am working on containerizing a nodejs app to be running on GKE.我正在容器化一个要在 GKE 上运行的 nodejs 应用程序。 the scripts section of package.json looks like this package.json 的脚本部分看起来像这样

  "scripts": {
    "dev": "npm-run-all --parallel dev:build-server dev:build-client  dev:server",
    "dev:server": "nodemon -L --watch build --exec node build/bundle.js",
    "dev:build-server": "webpack --config webpack.server.js --watch",
    "dev:build-client": "webpack --config webpack.client.js --watch"
  }, 

so when running im using npm run dev to start them all.所以在运行 im 时使用npm run dev来启动它们。

this works perfectly while it is running on VM.这在 VM 上运行时效果很好。 But when run as a container in kubernetes the nodemon process won't start.但是当在 kubernetes 中作为容器运行时,nodemon 进程不会启动。 nor it listens on the port.它也不监听端口。 it gives a 502 status error on browser它在浏览器上给出 502 状态错误

but when you ssh to the pod and try running the command it starts the process.listens on 3001 port but obviously it gives routes not found on browser.但是当您通过 ssh 连接到 pod 并尝试运行该命令时,它会在 3001 端口上启动 process.listens,但显然它提供了在浏览器上找不到的路由。 since they are not linked as expected.因为它们没有按预期链接。

below is the dockerfile下面是dockerfile

FROM node:10.19-stretch
ENV USER="vue" UID="1001"


RUN apt-get update --fix-missing
RUN apt-get install -yq curl
RUN rm /bin/sh && ln -s /bin/bash /bin/sh && \
    mkdir -p /opt/vue && \
    addgroup --system -gid $UID $USER && \
    adduser --system --uid $UID --gid $UID $USER

WORKDIR /opt/vue

COPY dashboard/. /opt/vue/


RUN npm cache clean --force && \
    npm install  && \
    npm cache verify  && \
    chown $USER.$USER -R /opt/vue

USER $USER
EXPOSE 3001
# ENTRYPOINT ["/usr/bin/dumb-init","--"]
# CMD ["npm run dev"]
CMD ["npm", "run", "dev" ]

tried using base images ( node:10.19-stretch,node:10.19.0-alpine3.11 ) some had sugested installing inotify but even that didn't work.尝试使用基本图像( node:10.19-stretch,node:10.19.0-alpine3.11 )有些人建议安装 inotify 但即使这样也不起作用。 what am I missing.我错过了什么。 please help.请帮忙。

UPDATE ---更新 - -

when run either in docker or kubernetes standerout log says this with no errors(enabled verbose output)在 docker 或 kubernetes 中运行时,standerout 日志显示没有错误(启用详细输出)

[nodemon] Looking in package.json for nodemonConfig
  Usage: nodemon [nodemon options] [script.js] [args]

  See "nodemon --help" for more.

[nodemon] exiting

after some peer reviewing and posting this on other networks found the correct answer.经过一些同行评审并将其发布在其他网络上后,找到了正确的答案。

issue behind was obvious.后面的问题很明显。 in the scripts section the all dev:* scripts were running parallel.在脚本部分,所有 dev:* 脚本都并行运行。 so when the two build steps were running the nodemon service was trying to start the service.因此,当两个构建步骤运行时,nodemon 服务正在尝试启动该服务。 and since the build/bundle.json is not there it gives a file not found.并且由于 build/bundle.json 不在那里,它给出了一个未找到的文件。 but the nodemon thinks of it as invalid arguments and gives the command help.但是 nodemon 将其视为无效参数并提供命令帮助。

so what I did was adding the build steps in the docker file by running所以我所做的是通过运行在 docker 文件中添加构建步骤

npm run dev

and then on the CMD adding the然后在 CMD 上添加

npm run prod:server

which actually speeded up the startupt time too.这实际上也加快了启动时间。

here is the dockerfile part that was changed.这是已更改的 dockerfile 部分。

RUN npm cache clean --force && \
    npm install  && \
    npm cache verify  && \
    chown $USER.$USER -R /opt/vue

USER $USER
EXPOSE 3001

CMD ["npm", "run", "prod:server" ]

also I had removed nodemon as its not needed.我也删除了 nodemon 因为它不需要。 since files will not be changed anyway and they are too bulky因为文件无论如何都不会改变,而且它们太庞大了

  "scripts": {
    "dev": "npm-run-all --parallel dev:build-server dev:build-client",
    "prod:server": "node build/bundle.js",
    "dev:build-server": "webpack --config webpack.server.js --watch",
    "dev:build-client": "webpack --config webpack.client.js --watch"
  },

finally.. !!最后.. !! viola.. it worked.中提琴……它奏效了。

Thanks everyone who put their precious time on this.感谢所有投入宝贵时间的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM