简体   繁体   English

Nodejs Skaffold本地开发到生产过程

[英]Nodejs Skaffold local development to prod process

New to container and kubernetes. 容器和kubernetes的新功能。

I'm trying to set thing up so we have the parity of the local development all the way through prod. 我正在尝试进行设置,以便我们在生产过程中始终与本地开发保持一致。

Skaffold seems to be a good way to do this but I'm confused by a few small pieces of the examples and 'ideal workflow' Skaffold似乎是执行此操作的好方法,但我对一些小示例和“理想的工作流程”感到困惑

Referencing https://github.com/GoogleContainerTools/skaffold/tree/master/examples/nodejs 引用https://github.com/GoogleContainerTools/skaffold/tree/master/examples/nodejs

The dockerfile they give uses nodemon. 他们提供的dockerfile使用nodemon。 Wouldn't this same container be used in prod? 不会在产品中使用相同的容器吗? Wouldn't it be bad to be running nodemon in prod? 在产品中运行nodemon会很糟糕吗?

How do I set up a kubernetes local development environment with live file sync and use the same resources (in order to have idempotency) for production? 如何使用实时文件同步设置kubernetes本地开发环境,并使用相同的资源(以具有幂等性)进行生产?

You are absolutely right. 你是绝对正确的。 Using nodemon in a production container is not recommended. 不建议在生产容器中使用nodemon。 Instead, you generally want different images or different entrypoints for dev vs staging vs production. 相反,您通常需要不同的映像或不同的入口点来进行开发,登台和生产。 There are two options to solve this: 有两种解决方法:

1. Multiple Dockerfiles 1.多个Dockerfile
You can configure profiles in Skaffold and tell Skaffold to use a different Dockerfile during the build step: https://skaffold.dev/docs/how-tos/profiles/ 您可以在Skaffold中配置配置文件,并在构建步骤中告诉Skaffold使用其他Dockerfile: https ://skaffold.dev/docs/how-tos/profiles/

2. Single Dockerfile + Dev Overrides 2.单个Dockerfile +开发覆盖
If you do not want to manage multiple Dockerfiles, you could use a dev tool that supports dev overrides. 如果您不想管理多个Dockerfile,则可以使用支持dev覆盖的dev工具。 DevSpace ( https://github.com/devspace-cloud/devspace ) for example differentiates between devspace deploy and devspace dev which applies certain overrides, eg overriding the entrypoint of the image. 例如,DevSpace( https://github.com/devspace-cloud/devspace )区分devspace deploydevspace dev ,后者会应用某些替代,例如,替代映像的入口点。 In this case you could specify 2 npm scrips in your package.json and start dev mode with the entrypoint npm start dev and the production mode using npm start . 在这种情况下,您可以在package.json中指定2个npm脚本,并使用入口点npm start dev和使用npm start的生产模式npm start dev模式。

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

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