Documentation can be found here (project22) and here (project23)
For the nginx-sidecar
pod file, I demonstrate how to mount volumes from my local machine onto the node container and the sidecar pattern.
Volumes can not be mounted directly from local machine to container. To achieve this, we first have to mount our local machine volume onto the minikube cluster like so
minikube mount /path/on/local/machine:/path/on/vm
In my case, my local machine volume is named local-vol
on my Desktop, and the path on the minikube vm (docker, I used docker as a driver) as specified in the hostPath.path
in the nginx-sidecar
file is /vm-vol
. Hence, to mount the local volume onto the minikube vm, I use
minikube mount ~/local-vol:/vm-vol
When my pod starts, the vm-vol
path on my minikube vm will be mounted into the containers, as the app-container
container writes to it's /var/log
dir, it gets propagated to the /vm-vol
dir on the minikube cluster, and that gets propagated to my local machine's local-vol
dir.
We have two containers, app-container
container, and log-exporter-sidecar
container. The main container is only concerned with generating logs and nothing else, but what good are the logs if we can't view them, that's where the pattern comes in. The helper container has nginx running, and can serve us our log file via http.
The pattern is demonstrated thus;
- We have our main
app-container
container, writing to a log file, which is propagated to thevm-vol
volume - The nginx
log-exporter-sidecar
container also mounts, thevm-vol
volume, hence it has access to what is being written there by the main container. - A port-forward is performed, which exposes the nginx service to our local machine
- Using curl we can then access the app.log file content being served by nginx (browser attempts a download)
https://betterprogramming.pub/understanding-kubernetes-multi-container-pod-patterns-577f74690aee