Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way I can edit file in the container and restart it?

Tags:

kubernetes

Is there any way I can exec into the container, then edit some code (ex: add some log, edit come configuration file, etc) and restart the container to see what happens?

I tried to search for this but found nothing helpful.

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

like image 672
Tanapat Sainak Avatar asked Feb 21 '18 04:02

Tanapat Sainak


2 Answers

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.

like image 126
Radek 'Goblin' Pieczonka Avatar answered Oct 22 '22 07:10

Radek 'Goblin' Pieczonka


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?

like image 45
Graham Dumpleton Avatar answered Oct 22 '22 06:10

Graham Dumpleton