> 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

### 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
