Best practice for starting a service using docker images in Kubernetes cluster

9/8/2019

What is the best way to start docker container in Kubernetes cluster? Is it better to start the service in the docker container itself or pass the command when creating Kubernetes pod with the command option?

The image I am working with has multiple services so I've tried building many images with just changing the services they run and passing those images to the Kubernetes pod but if I can start the services from the pod itself I'll have to manage only one image.

currently, I have two Dockerfiles one for the main process

FROM node:10
WORKDIR /app
COPY . /app
RUN yarn
CMD ["yarn", "start:app"]
EXPOSE 3000

and another one Dockerfile.worker for my background worker

FROM node:10
WORKDIR /app
COPY . /app
RUN yarn
CMD ["yarn", "start:worker"]

currently, I am managing two images in the same codebase and I was thinking if it is better to have one image and pass the start command from Kubernetes.

-- Mikias Abebe
devops
docker
kubernetes

1 Answer

9/9/2019

So think this is quite opinionated question, but I believe that a docker image should only ever have one process (therefore setting it in the Dockerrfile would be your best bet as it would not need to be configured wherever you ran it) however you do sometimes get the use case where a single docker image could have multiple commands, in this case I would recommend setting the most used command as the default in the Dockerfile and then if need be you can use Kubernetes command flag to overwrite this when you want to start the image with a different command

-- Spazzy757
Source: StackOverflow