In this guide I show you how I use mkdocs in my Kubernetes cluster.
There are uncountable ways to do something similar, but I think this post can be useful for you.
The main ascpect of my solution is to build the documentation in an init container, and serve the page with nginx. This way the only thing you have to do is rollout the deployment after new version of your mkdocs is released (pushed to your repository).
The following environment variabels in the git initContainer must be set accoring to your Git repository:
GIT_AUTH: true or false. If your git repository uses auth set to true otherwise false.
GIT_URL: URL of your repository. (Example: github.com) Only https is supported. If you need plain http connection you have to modify the run.sh shell script (git clone).
GIT_REPO: You can copy paste this value from the git URL in your browser. Example: https://github.com/jvincze84/jvincze84.github.io --> jvincze84/jvincze84.github.io
GIT_USER: Your git username. Mandatory if you set GIT_AUTH to true.
GIT_PASS: Your git password or token. Mandatory if you set GIT_AUTH to true.
Additionally you may want to use kuberntes secret for storing the git password. In this case you have to add the following lines to the Deployment:
The Deployment uses ephemeral storage (emptyDir: {}) so every time you deploy a new version or rollout the deployment the entire webpage is regenerated and the previous version won't be kept
volumeMounts, mountPath and subPath should not be modified, unless you know what, how and why you do that.
Tip
After you have done with the modification on your docs and pushed back to git, you can rollout the deployment with this command: kubectl rollout restart -n mkdocs deployment read-the-docs. Or simply delete the pod. :)