Nodejs Skaffold local development to prod process

3/7/2019

New to container and 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'

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

The dockerfile they give uses nodemon. Wouldn't this same container be used in prod? Wouldn't it be bad to be running nodemon in prod?

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?

-- JonathanW
kubernetes
node.js
skaffold

1 Answer

8/29/2019

You are absolutely right. Using nodemon in a production container is not recommended. 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
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/

2. Single Dockerfile + Dev Overrides
If you do not want to manage multiple Dockerfiles, you could use a dev tool that supports dev overrides. DevSpace (https://github.com/devspace-cloud/devspace) for example differentiates between devspace deploy and devspace dev which applies certain overrides, e.g. overriding the entrypoint of the image. 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.

-- LukasGentele
Source: StackOverflow