If you are using Minikube or Docker for Mac/Windows to run your Kubernetes deployments locally, I have developed a tool to restart containers automatically when their images are rebuilt: Check out freshpod on GitHub!

Normally, when you do a docker build to build a new image, you have to manually restart Pods running on your Kubernetes node to use the new image. freshpod detects you rebuilt an image and restarts the Kubernetes Pods that are running that image:

freshpod workflow

Here’s a demo of live refactoring an application and have it restart automatically on Minikube:

freshpod on Minikube

freshpod is already in Minikube as an add-on thanks to a user who found about it before I even told anyone:

$ minikube addons enable freshpod

freshpod on “Docker for Mac/Windows”

Since Docker for Mac/Windows now offers local Kubernetes support, it is very much like Minikube. You can take the manifest file used by Minikube and apply it directly to Kubernetes on Docker:

kubectl apply -f https://github.com/kubernetes/minikube/raw/master/deploy/addons/freshpod/freshpod-rc.yaml

DIY: Rebuild containers when files change

You can use entr(1) to run a command when files on your computer change.

This command will build a new image when any of the *.py files in the current directory changes:

$ find . -name '*.py' | entr docker build -t myapp .

On top of this, if you have freshpod installed, you can automatically have local Kubernetes Pods restart automatically when the source code changes!

freshpod is a small project that does one simple task. If you have any big ideas for it, let’s discuss!