> For the complete documentation index, see [llms.txt](https://docs.lenses.io/latest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lenses.io/latest/k2k/runbooks/cluster-migration.md). Agents can also search and read this documentation through its [MCP server](https://docs.lenses.io/latest/~gitbook/mcp).

# Cluster migration

Gradual cluster migration procedure with K2K.

This runbook covers moving workloads from a source Kafka cluster to a target cluster while both remain in service. For the business context, see [Use cases](https://docs.lenses.io/latest/k2k/use-cases.md#cluster-migration).

## Prerequisites

* Pipeline with both source and sink replication stages — see [Topic selection and data routing](https://docs.lenses.io/latest/k2k/configuration-reference/topic-selection-and-data-routing.md)
* K2K replicator copying selected topics from old to new cluster
* [Offset mapping](https://docs.lenses.io/latest/k2k/configuration-reference/offset-mapping.md) enabled with both applications running if applications switch one at a time without reprocessing
* [Schema migration](https://docs.lenses.io/latest/k2k/configuration-reference/schema-migration.md) enabled where applications depend on Schema Registry
* Application inventory listing consumer groups to migrate
* [Validation checklist](https://docs.lenses.io/latest/k2k/runbooks/validation-checklist.md) completed for the pipeline

## Migration phases

### Phase 1: Establish replication

1. Deploy K2K with the pipeline covering all topics needed for migration.
2. Verify replication lag is stable — see [Observability](https://docs.lenses.io/latest/k2k/configuration-reference/observability.md).
3. Confirm schemas are available on the target Schema Registry if required.

### Phase 2: Migrate applications one at a time

For each application:

1. **Pause the application** on the source cluster (stop consumers and producers).
2. **Wait for lag to reach zero** on the topics that application uses.
3. **Verify offset mapping** for the application's consumer group:

```shell
k2k-tool describe -f my_pipeline.yml
```

4. **Reconfigure the application** to use the target cluster bootstrap servers.
5. **Start the application** on the target cluster and validate behavior.
6. **Resume the next application** on the source cluster if others are still running.

{% hint style="warning" %}
When `features.offsetMapping` is `enabled`, deploy and run both `k2k` and `k2k-offset-mapping`. Enabling the feature in the pipeline file does not translate consumer offsets by itself.
{% endhint %}

### Phase 3: Migrate producers

After all consumers are on the target cluster:

1. Redirect producers to the target cluster.
2. Allow K2K to replicate any remaining records from the source.
3. Confirm no active consumers remain on the source cluster.

### Phase 4: Decommission

1. Stop K2K replicator and offset mapper.
2. Remove the pipeline deployment (Helm uninstall or stop Docker containers).
3. Decommission the source Kafka cluster after a retention period that satisfies your compliance requirements.

## Consumer group validation

Before each application cutover, confirm:

| Check                                       | How                                                     |
| ------------------------------------------- | ------------------------------------------------------- |
| Group is matched by `groups.consumerGroups` | Pipeline regex covers the group name                    |
| Target offset is current                    | `k2k-tool describe` shows committed ≈ last              |
| Schemas exist on target                     | Consume a sample record with the target Schema Registry |

## Handling applications without offset mapping

If offset mapping is not enabled, applications deployed on the target cluster start with fresh consumer groups. This is acceptable when applications can tolerate reprocessing or when data is consumed only from the target going forward. See [Deployment](https://docs.lenses.io/latest/k2k/deployment.md#replicator-only).

## Bidirectional replication during migration

If both clusters must accept writes during migration, consider [Bidirectional replication](https://docs.lenses.io/latest/k2k/configuration-reference/bidirectional-replication.md) with one pipeline per direction. Plan loop prevention headers and topic routing carefully.

## Troubleshooting during migration

| Issue                               | Action                                                                                                                       |
| ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Application reprocesses old records | Check offset mapping; verify group name matches regex                                                                        |
| Schema incompatibility on target    | Review [Schema migration](https://docs.lenses.io/latest/k2k/configuration-reference/schema-migration.md) mappings            |
| Lag never reaches zero              | Scale replicator — see [Horizontal scaling](https://docs.lenses.io/latest/k2k/configuration-reference/horizontal-scaling.md) |

See [Troubleshooting](https://docs.lenses.io/latest/k2k/configuration-reference/troubleshooting.md) for additional runtime diagnostics.


---

# 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.lenses.io/latest/k2k/runbooks/cluster-migration.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.
