Is there anyway I can edit file on the container and restart it?

2/21/2018

Is there anyway I can exec to the container, then edit some code (ex: add some log, edit come configuration file) and restart the container to see what happen?

I try searched about this but I have seen none.

The point is I want to do a quick debug, not to do a full cluster deploy.

-- Tanapat Sainak
kubernetes

4 Answers

2/21/2018

You could put any configuration in a configmap then just apply that, obviously assuming what reads the configmap would re-read it.

-- Steven Goodliff
Source: StackOverflow

2/21/2018

Some programs (like ie. nginx) support configuration reload without restarting their process, with these you can just kubectl exec change config and send a signal to master process (ie. kubectl exec <nginx_pod> kill -HUP 1). It is a feature of the software though, so many will not take that into account.

Containers are immutable by design, so they restart with a clean state each time. That said, with no simple way of doing this, there are hackish ways to achieve it.

One I can think of involves modifying the image on the node that will then restart the container. If you can ssh into the node and access docker directly, you can identify the container with a modified file and commit these changes with docker commit under the same tag. At that point your local container with that tag has your changes baked in so if you restart it (not reschedule, as it could start on different node), it will come up with your changes (assuming you do not use pullPolicy: always).

Again, not the way it's meant to be used, but achievable.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

2/21/2018

Any changes to the local container file system will be lost if you restart the pod You would need to work out whether the application stack you are using can perform an internal restart without actually exiting.

What language/application stack are you using?

-- Graham Dumpleton
Source: StackOverflow

2/21/2018

You should at least consider an hostPath volume, in order to share local files on your host with your Kubernetes instance, in order to be able to do that kind of test.

After that, it is up to your application running within your pod to detect the file change, and restart if needed (ie, this is not specific to Kubernetes at all)

-- VonC
Source: StackOverflow