<p>I have a container running inside a pod and I want to be able to monitor its content every week. I want to write a Kube cronjob for it. Is there a best way to do this?</p>

<p>At the moment I am doing this by running a script in my local machine that does <code>kubectl exec my-container</code> and monitors the content of the directory in that container.</p>

Sudesh Banskota
<p><code>kubectl exec my-container</code> sounds perfectly fine to me. You might want to look at <a href="https://stackoverflow.com/questions/42642170/kubernetes-how-to-run-kubectl-commands-inside-a-container">this</a> if you want to run <code>kubectl</code> in a pod (Kubernetes CronJob).</p>

<p>There are other ways but depending on what you are trying to do in the long term it might be an overkill. For example:</p>

<ul>
<li><p>You can set up a <a href="https://www.fluentd.org/" rel="nofollow noreferrer">Fluentd</a> or <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/#using-a-sidecar-container-with-the-logging-agent" rel="nofollow noreferrer">tail/grep sidecar</a> (or <code>ls</code>, if you are using a binary file?) to send the content or part of the content of that file to an Elasticsearch cluster. </p></li>
<li><p>You can set up <a href="https://prometheus.io/" rel="nofollow noreferrer">Prometheus</a> in <a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Ckubernetes_sd_config%3E" rel="nofollow noreferrer">Kubernetes</a> to scrape metrics on the pod mounted filesystems. You will probably have to use a custom exporter in the pod or something else that exports files in mount points in the pod. <a href="https://github.com/giantswarm/kubernetes-prometheus/blob/master/manifests/prometheus/node-directory-size-metrics/daemonset.yaml" rel="nofollow noreferrer">This is a similar example</a>.</p></li>
</ul>
