This examples shows a useful example for a Sidecar in web-app.yml:
-
The main container is a httpd daemon who serves HTML file from within its directory
/var/www/html. This directory is mounted from a volume namedgit. -
The sidecar container is a stock image containing a
gitCLI tool. It also mounts the volumegitin a directory and executes a command to pull a git repository periodically into this directory.
The effect is, that as soon as something changes in the Git repository, the HTML files that the HTTP daemon serves get updated.
You can choose the Git repository by setting then environment variable GIT_REPO accordingly.
Also not the trick with watch to perform a periodic polling loop without requiring a shell script (as it would be needed for a for loop):
sh -c "git clone $(GIT_REPO) . && watch -n 600 git pull"For you convenience a nodePort service is exposed so that you can access the HTML pages from the outside
-
Start minikube
-
Apply the resource descriptor
kubectl -f web-app.yml-
When all images are pulled and the pods are running, open your browser with the web pages
minikube service web-appIf you want to test whether the pages are really updated, change GIT_REPO in web-app.yml to a git repo which is under your control and then change files after the pods has been started.
You can also tune the update interval in the sidecar command definition, which is currently set to 10 minutes.