How to start stopped container using kubernetes?

7/1/2019

Business requirement is following:

  1. Stop running container
  2. Modify environment (Ex.Change value of DEBUG_LEVEL environment variable)
  3. Start container

This is easily achievable using docker CLI

docker create/docker stop/docker start

How to do it using kubernetes?

Additional info: We are migrating from Cloud Foundry to Kubernetes. In CF, you deploy application, stop application, set environment variable, start application. The same functionality is needed. For those who are not aware of CF application. It is like docker container with single running (micro)service.

-- zdenko.s
docker
kubernetes

3 Answers

7/1/2019

There is also another possibility :

  1. Define container environment variables using configmap data
  2. Let Kubernetes react upon ConfigMap changes. It does not trigger restart of Pods by default, unless you change Pod spec somehow.
    Here is an article, that describes how to achieve it using SHA-256 hash generated of our ConfigMap.
-- Nepomucen
Source: StackOverflow

7/1/2019

Let's say you are creating a pod/deployment/statefulset using the following command.

kubectl apply -f blueprint.yaml

blueprint.yaml is the YAML file which contains the blueprint of your pod/deployment/statefulset object.

Method 1 - If you specify the environment variables in the YAML file

Then you can change the blueprint.yaml to modify the value of environment variable, . https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/

Then execute same command again to apply the changes.

Method 2 - If you specify the environment variables in the dockerfile

You should build your docker image with a new tag. Then change the docker image tag in the blueprint.yaml file and execute the same command again to apply the changes.

Method 3

You can also delete and create the pod/deployment/statefulset again.

kubectl delete -f blueprint.yaml
kubectl apply -f blueprint.yaml
-- SRF
Source: StackOverflow

7/1/2019

Typically, you would run your application as a Deployment or as a StatefulSet. In this case, just change the value of the environment variable in the template and reapply the Deployment (or StatefulSet). Kubernetes will do the rest for you.

click here to refer the documentation

-- Henry
Source: StackOverflow