Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 2.71 KB

File metadata and controls

57 lines (41 loc) · 2.71 KB

Sidecar

This example demonstrates a simple Sidecar defined in web-app.yml:

  • The main container is an httpd daemon that serves HTML files from within its directory /var/www/html. This directory is mounted from a volume named git.

  • The sidecar container is a stock image containing a git CLI tool. It also mounts the volume git in 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 the environment variable SOURCE_REPO accordingly.

The sidecar actually does nothing else then do a git pull every 60 seconds in the cloned Git repository:

git clone $(SOURCE_REPO) .
while true; do
  sleep 60
  git pull
done

For your convenience, a nodePort service is exposed so that you can access the HTML pages from the outside.

This example uses the sample repository https://github.com/mdn/beginner-html-site-scripted, but for experimenting with it, you should either fork this repository or use any other repo you have to write and push access to. To point to this directory, update the GIT_REPO variable in web-app.yml.

You can run this example on any Kubernetes installation; however, for exposing the Service, we assume for now that you are using minikube. Checkout INSTALL for more installation options.

Apply the resource descriptor with the Pod and Service definition:

kubectl apply -f web-app.yml
  • When all images are pulled, and the pods are running, open your browser with the web pages

minikube service web-app

If you want to test whether the pages are updated, clone the repository configured in GIT_REPO in a local directory, make some changes, git commit and git push (assuming that you have changed the GIT_REPO URL to a repo that you can write to). You should see the changes automatically propagating to your web application.

You can also tune the update interval in the sidecar command definition, currently set to one minute.