> For the complete documentation index, see [llms.txt](https://docs.digit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digit.org/platform/guides/operations-guide/kafka-troubleshooting-guide/how-to-clean-up-kafka-logs.md).

# How to clean up Kafka logs

The following steps illustrates the way to cleanup Kafka logs.

For any logs that appear to be overflowing and consuming disk space, you can use the following steps to clean up the logs from Kafka brokers

**Note: Make sure the team is informed before doing this activity. This activity will delete the Kafka topic data**

### Steps <a href="#instructions" id="instructions"></a>

1. Backup list of log file names and their disk consumption data (optional)

   `kubectl exec -it kafka-v2-0 -- du -h /opt/kafka-data/logs |tee backup_0.logs`

   `kubectl exec -it kafka-v2-1 -- du -h /opt/kafka-data/logs |tee backup_1.logs`

   `kubectl exec -it kafka-v2-2 -- du -h /opt/kafka-data/logs |tee backup_2.logs`
2. Cleanup the logs

   `kubectl exec -it kafka-v2-0 -- rm -rf /opt/kafka-data/logs/* -n kafka-cluster`

   `kubectl exec -it kafka-v2-1 -- rm -rf /opt/kafka-data/logs/* -n kafka-cluster`

   `kubectl exec -it kafka-v2-2 -- rm -rf /opt/kafka-data/logs/* -n kafka-cluster`

3\. If the pod is in crashlookbackoff state, and the storage is full, use the following workaround:

* Make a copy of the pod manifest

  `kubectl get statefulsets kafka-v2 -n kafka-cluster -oyaml > manifest.yaml`
* Scale down the Kafka statefulset replica count to zero

  `kubectl scale statefulsets kafka-v2 -n kafka-cluster --replicas=0`
* Make the following changes to the copy of the statefulsets manifest file
  * Modify the command line from:

```
containers:
- command:
  - sh
  - -exc
  - |
    export KAFKA_BROKER_ID=${HOSTNAME##*-} && \
    export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://${POD_NAME}.kafka-v2-headless.${POD_NAMESPACE}:9092,EXTERNAL://${HOST_IP}:$((31090 + ${KAFKA_BROKER_ID})) && \
    exec /etc/confluent/docker/run
```

To

```
containers:
- command:
  - sh
  - -exc
  - |
    tail -f /dev/null
```

* Apply this statefulsets manifest and scale up statefulsets replica count to 3, the pod should be in a running state now and follow \[step 2].
* Again scale down the Kafka statefulset replica count to zero

  `kubectl scale statefulsets kafka-v2 --replicas=0 -n kafka-cluster`
* Make the following changes to the copy of the statefulsets manifest file
  * Modify the command line from:

```
containers:
- command:
  - sh
  - -exc
  - |
    tail -f /dev/null
```

To

```
containers:
- command:
  - sh
  - -exc
  - |
    export KAFKA_BROKER_ID=${HOSTNAME##*-} && \
    export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://${POD_NAME}.kafka-v2-headless.${POD_NAMESPACE}:9092,EXTERNAL://${HOST_IP}:$((31090 + ${KAFKA_BROKER_ID})) && \
    exec /etc/confluent/docker/run
```

* Apply this statefulsets manifest and scale up statefulsets replica count to 3


---

# 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.digit.org/platform/guides/operations-guide/kafka-troubleshooting-guide/how-to-clean-up-kafka-logs.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.
