# Kafka to Kafka Replicator

The K2K application is designed to facilitate seamless data replication between Kafka clusters while also replicating topic metadata. This capability ensures consistency across different environments or data centers. K2K supports a range of use cases including disaster recovery, data migration, and cross-datacenter data replication. By preserving both data and metadata, K2K enables a robust and efficient solution for maintaining synchronized Kafka clusters. To learn more concepts see [Overview](/latest/k2k/readme.md).

Lenses streamlines K2K application management by simplifying creation and deployment, leading to faster and more efficient workflows. With self-service capabilities through [Kafka Connections](/latest/user-guide/using/share-and-replicate-data/kafka-connections.md), users gain autonomy, improving productivity. Observability is enhanced through detailed throughput metrics, providing insights for optimized performance. Comprehensive governance is maintained with IAM policies, ensuring security and compliance.

### Creating a K2K application

Select the `Apps` option from the left sidebar, either open the listing for `K2K Replicators` and click `Create K2K Replicator`, or click `+` from the node in the tree panel. Then

{% stepper %}
{% step %}

#### Name and metadata

Add a name and metadata
{% endstep %}

{% step %}

#### Select source, target and deployment environment

Source is where the source target is, target, the environment to write to, and deployment environment is where the application is to be deployed

{% hint style="info" %}
Deployment environment should be as close to the target as possible, prefereably in the target environment. See [Kafka Connections](/latest/user-guide/using/share-and-replicate-data/kafka-connections.md)
{% endhint %}
{% endstep %}

{% step %}

### Select topics

Select one or more topics to replicate
{% endstep %}

{% step %}

### Optional add topic mapping

Decide how you want to map the topics on the target cluster

{% endstep %}

{% step %}

### Optional set replication options

These settings allow you to control what is replicated, for example message headers and timestamps and auto creation settings on the target.
{% endstep %}
{% endstepper %}

### Configuration Reference

This table outlines the complete set of fields for the K2K resource, which is utilized to define and configure a Kafka-to-Kafka application. The configuration is divided into two sections:

* **status**: Reflects the most recently observed state; it is read-only.
* **spec**: Depicts the intended state of the K2K application.

| Field                                         | Description                                                                                 |                  Type | Default | Required |
| --------------------------------------------- | ------------------------------------------------------------------------------------------- | --------------------: | ------- | -------- |
| `spec.sourceKafkaLRN`                         | Sets the source KafkaConnection LRN to read from.                                           |              `string` | (none)  | Yes      |
| `spec.targetKafkaLRN`                         | Sets the target KafkaConnection LRN to write to.                                            |              `string` | (none)  | Yes      |
| `spec.topics`                                 | Sets the topic(s) to replicate.                                                             | `array` (of `string`) | (none)  | Yes      |
| `spec.deploymentNamespaceLRN`                 | Defines the Kubernetes namespace to deploy to.                                              |              `string` | (none)  | Yes      |
| `spec.kubernetes`                             | Defines Kubernetes deployment overrides. (Ref: `K8sDeploymentOverrides`)                    |              `object` | (none)  | No       |
| `spec.replicator`                             | Provides additional control knobs for the K2K replicator.                                   |              `object` | (none)  | No       |
| `spec.paused`                                 | Halts replication by scaling down to zero pods.                                             |             `boolean` | `false` | No       |
| `spec.replicator.schemaMapping`               | Enables schema replication.                                                                 |             `boolean` | `false` | No       |
| `spec.replicator.exactlyOnce`                 | Enables exactly-once processing.                                                            |             `boolean` | `false` | No       |
| `spec.replicator.autoCreateTopics`            | Enables auto creation of topics.                                                            |             `boolean` | `false` | No       |
| `spec.replicator.autoCreateControlTopics`     | Enables auto creation of control topics.                                                    |             `boolean` | `false` | No       |
| `spec.replicator.keepRecordCreationTimestamp` | Enables preserving record timestamps.                                                       |             `boolean` | `false` | No       |
| `status.updatedAt`                            | Contains the time instant this object was updated.                                          |  `string` (date-time) | (none)  | Yes      |
| `status.state`                                | The high-level state of the application. (Ref: `K2KAppState`)                               |              `string` | (none)  | Yes      |
| `status.statusLastTransitionAt`               | Contains the time instant the status was changed.                                           |  `string` (date-time) | (none)  | Yes      |
| `status.statusMessage`                        | Is a human-readable message indicating details about the last transition.                   |              `string` | (none)  | Yes      |
| `status.observedGeneration`                   | Reflects the generation of the `spec` that this `status` corresponds to.                    |             `integer` | (none)  | Yes      |
| `status.deployment`                           | Provides information about the Kubernetes deployment.                                       |              `object` | (none)  | Yes      |
| `status.kafka`                                | Provides information about the Kafka-related status.                                        |              `object` | (none)  | Yes      |
| `status.deployment.inSync`                    | Indicates if the deployed resources match the desired state.                                |             `boolean` | (none)  | Yes      |
| `status.deployment.managedResources`          | A list of resources managed by the deployment. (Ref: `KubernetesDeploymentStatusResource`)  |               `array` | (none)  | Yes      |
| `status.deployment.pods`                      | The status of the individual pods in the deployment. (Ref: `KubernetesDeploymentStatusPod`) |               `array` | (none)  | Yes      |
| `status.kafka.consumerGroup`                  | Holds the name of the consumer group that this K2KApp uses.                                 |              `string` | (none)  | Yes      |


---

# Agent Instructions: 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:

```
GET https://docs.lenses.io/latest/user-guide/using/share-and-replicate-data/kafka-to-kafka-replicator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
