> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/operations/deployment/deployment-guide/automating-cache-cleanup-on-k8s-cluster-nodes-with-cron-job.md).

# Automating Cache Cleanup on K8s Cluster Nodes with Cron Job

This document explains how to set up a cron job to clear the cache on ubuntu systems.

### Overview

Linux caches data in memory to improve performance, but over time, excessive caching can lead to high memory usage. To free up RAM, we can follow the below procedure.

### Procedure

To optimize memory usage on RKE2 cluster nodes, a cron job can be scheduled to periodically clear the RAM cache using the following command.

```bash
sync; echo 3 > /proc/sys/vm/drop_caches
```

* [ ] Use `sync` to ensure all data is written to disk.
* [ ] `echo 3` Clears **page cache, dentries, and inodes**.

### Steps to add the cron job

1. Open the crontab file for editing as a **root user**.\
   `crontab -e`
2. Add the following line to schedule the cache clearing every week.\
   `0 0 * * 6 sync; echo 3 > /proc/sys/vm/drop_caches`
3. Save and exit the editor.
4. Check if the cron job is added successfully.\
   `crontab -l`

This cron job will run every week on saturday 12am, ensuring that RAM cache is cleared periodically to optimize memory usage on RKE2 nodes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/operations/deployment/deployment-guide/automating-cache-cleanup-on-k8s-cluster-nodes-with-cron-job.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
