You can run your script in another sidecar of your pod.
- Define a empty directory
volume
- Mount this
volume
as your content directory
- Also mount this directory to sidecar, so that it can access and able to monitor.
Example:
apiVersion: v1
kind: Pod
metadata:
name: monitor-by-sidecar
spec:
restartPolicy: Never
volumes: # empty directory volume
- name: shared-data
emptyDir: {}
containers:
- name: container-which-produce-content # This container is main application which generate contect. Suppose in /usr/share/nginx/html directory
image: debian
volumeMounts:
- name: shared-data
mountPath: /usr/share/nginx/html
command: ["/bin/bash", "-c"]
args:
- while true;
do
echo "hello world";
echo "----------------" > /usr/share/nginx/html/index.html;
cat /usr/share/nginx/html/index.html;
done
- name: container-which-run-script-to-monitor # this container will run your monitor scripts. this container mount main application's volume in /pod-data directory and run required scripts.
image: debian
volumeMounts:
- name: shared-data
mountPath: /pod-data
command: ["/bin/sh", "-c"]
args:
- while true;
do
echo "hello";
sleep 10;
ls -la /pod-data/;
cat /pod-data/index.html;
done
Example Description
- First container(named container-which-produce-content) is main application, which mount a
emptyDir
volume in /usr/share/nginx/html
. In this directory main application will generate data.
- Second container(named container-which-run-script-to-monitor) will mount same
emptyDir
volume (named shared-data which also mounted by main application in /usr/share/nginx/html
dir) in /pod-data
directory. This /pod-data
contains whole data which main application generated in /usr/share/nginx/html
directory. You can then run your scripts on this directory.