<p>My team has a special requirement to delete all pod logs every X hours. This is cause the logs contain some sensitive info - we read and process them with fluentbit, but it's an issue that the logs are still there after.
I couldn't find any normal way to rotate them by time, only recommendations on the docker daemon logging driver that rotates by file size.
Is it possible to create a k8s cronjob to do something like &quot;echo ''&gt; /path/to/logfile&quot; per pod/container? If yes, how?</p>
<p>I'd appreciate any help here.
Thanks!</p>

<p>Kubernetes doesn’t provide built-in log rotation, but this functionality is available in many tools.</p>
<p>According to <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/" rel="noreferrer">Kubernetes Logging Architecture</a>:</p>
<blockquote>
<p>An important consideration in node-level logging is implementing log
rotation, so that logs don't consume all available storage on the
node. Kubernetes is not responsible for rotating logs, but rather a
deployment tool should set up a solution to address that. For example,
in Kubernetes clusters, deployed by the kube-up.sh script, there is a
<a href="https://linux.die.net/man/8/logrotate" rel="noreferrer">logrotate</a> tool configured to run each hour. You can also set up a
container runtime to rotate an application's logs automatically.</p>
</blockquote>
<p>Below are some examples of how the log rotation can be implemented:</p>
<ul>
<li><p><a href="https://vividcode.io/enable-log-rotation-in-kubernetes-cluster/" rel="noreferrer">Enable Log Rotation in Kubernetes Cluster</a></p>
</li>
<li><p><a href="https://github.com/mkilchhofer/logrotate-container" rel="noreferrer">logrotate-container</a></p>
</li>
</ul>
<p>You can use them as a guide.</p>
