---
title: "Declare mirror topics on a cluster link"
description: "Declare Confluent mirror topics with KafkaMirrorTopic, create them with apply, catch paused or failed mirrors with verify, and import existing ones."
url: https://monedula.dev/flock/docs/gitops/how-to/declare-mirror-topics/
---

A `KafkaMirrorTopic` declares a mirror topic on the destination cluster of an existing Confluent cluster link. `apply` creates the mirror, `verify` reports when it stops replicating, and `import` brings existing mirrors into Git. The link itself stays yours: monedula-gitops never creates, pauses or deletes a link, and never pauses, resumes, promotes, fails over or deletes a mirror.

## Before you start

- monedula-gitops 1.1.0 or later.
- A destination cluster on Confluent Server or Confluent Cloud with its Kafka REST v3 API reachable, and a cluster link on that destination. Apache Kafka has no cluster linking.
- A principal for Kafka REST that may read the destination's links and mirror topics and create mirror topics there. `doctor` checks the reads; the create permission shows up at the first `apply`.

## Steps

### 1. Point the cluster config at Kafka REST

Mirror topics are created and read through Kafka REST, so the destination `KafkaCluster` needs a `rest` block next to its `bootstrapServers`:

```yaml
apiVersion: gitops.monedula.dev/v1alpha1
kind: KafkaCluster
metadata:
  name: dest
spec:
  bootstrapServers: localhost:29092
  rest:
    endpoint: http://localhost:8090/kafka
```

- `endpoint` is the base URL without `/v3`. On Confluent Server it usually ends in `/kafka`.
- `auth` has the same shape as `authorization.mds.auth`: `type: basic` with a `username` and `password`, `type: bearer` with a `token`, or `type: mtls`. `tls` takes the same settings as the Kafka connection. Credentials are read with `valueFrom`, like the rest of the cluster config.
- `clusterId` is optional on Confluent Platform, where the API is asked for it. Set it on Confluent Cloud. Either way, monedula-gitops checks that it equals the cluster ID the brokers report, and refuses to use mirror state from a REST API that serves a different cluster.

Once a cluster has `rest`, `diff`, `apply` and `verify` also read Kafka REST for every `KafkaTopic` on it, so that a `KafkaTopic` never changes a mirror (step 6). When Kafka REST cannot be read, they stop with exit code 2 instead of guessing.

### 2. Check the link with doctor

```bash
monedula-gitops doctor --cluster-config-file ./clusters/dest.yaml
```

The `rest`, `rest-cluster-binding` and `rest-mirrors` checks pass, and each link on the cluster gets a `link:<name>` line with its state and prefix, for example `link:src-to-dest`. A link with `auto.create.mirror.topics.enable=true` is a warning, because it can create mirrors that no manifest declares. [Check connectivity with doctor](/flock/docs/gitops/how-to/check-connectivity-with-doctor/) lists every check.

### 3. Declare the mirror

```yaml
apiVersion: gitops.monedula.dev/v1alpha1
kind: KafkaMirrorTopic
metadata:
  name: orders-mirror
spec:
  clusterRef:
    name: dest
  linkName: src-to-dest
  sourceTopicName: orders
```

- `clusterRef` names the destination cluster, where the link lives, and `sourceTopicName` the topic on the source cluster.
- `topicName` is the name on the destination and defaults to `sourceTopicName`. When the link has a `cluster.link.prefix`, it must be set explicitly to the prefix followed by the source name, such as `dr.orders`.
- `replicationFactor` is used only when the mirror is created. A different value on an existing mirror is reported as `UnsupportedReplicationFactorChange` and never changed.
- `config` sets topic configs that are local to the mirror. A key that the link syncs from the source, through its `topic.config.sync.include` setting, is rejected; so is any key when the link does not report that setting, because then nobody can tell who owns it.
- There is no `partitions` field: a mirror follows the source's partitions.
- `reconciliation.mode` works as on other kinds. `deletionPolicy` accepts only `Orphan`: removing the manifest, or deleting the resource in Kubernetes, always leaves the mirror topic in place.
- `clusterRef`, `linkName`, `sourceTopicName` and the destination name cannot change. A topic name belongs to one resource per cluster: a `KafkaTopic` and a `KafkaMirrorTopic` with the same name are a duplicate, which `validate` rejects.

### 4. Create it with apply

```bash
monedula-gitops apply -f ./manifests --cluster-config-file ./clusters/dest.yaml
```

The plan shows `CreateMirrorTopic`. `apply` creates the mirror only when the destination topic does not exist yet, the link is `ACTIVE` and the name fits the link's prefix; otherwise the plan shows `Rejected` with the reason, for example `topic exists and is not a mirror` when a normal topic already has that name, and `apply` exits 2. A changed local config shows as `UpdateMirrorTopicConfig`.

### 5. Watch its health with verify

```bash
monedula-gitops verify -f ./manifests --cluster-config-file ./clusters/dest.yaml
```

`verify` exits 0 while the mirror is `ACTIVE`. It reports, and never repairs:

| Finding | Mirror status | `verify` |
| --- | --- | --- |
| `MirrorTopicUnhealthy` | `PAUSED`, `LINK_PAUSED`, `FAILED`, `LINK_FAILED`, `SOURCE_UNAVAILABLE` | exits 1 |
| `MirrorTopicStopping` | `PENDING_STOPPED`, the mirror is being promoted or failed over | exits 1 |
| `MirrorTopicPromoted` | `STOPPED`, the topic is now a normal, writable topic | exits 1 |
| `MirrorTopicProgressing` | `PENDING_MIRROR`, `PENDING_SYNCHRONIZE` and the restore states | exits 0, informational |
| `StateReadError` | unknown, or Kafka REST could not be read | exits 2 |

A mirror paused outside Git, for example with `kafka-mirrors --pause`, fails `verify` with `MirrorTopicUnhealthy` and the status `PAUSED`, and passes again once it is resumed. As with other kinds, `ObserveOnly` findings are shown without failing the run.

The operator re-checks every `KafkaMirrorTopic` at each resync, shows the live status in the `Mirror` column of `kubectl get kafkamirrortopic`, and reports `MirrorTopicStalled` when a transitional status stays unchanged for longer than `mirrorStallThreshold`, 30 minutes by default ([Configure the Kubernetes operator](/flock/docs/gitops/how-to/configure-the-operator/#reconciliation)). A `KafkaMirrorTopic` on a cluster without `rest` gets the condition `ValidationFailed` with the reason `RESTNotConfigured`.

### 6. Keep KafkaTopic away from mirrors

On a cluster with `rest`, a `KafkaTopic` whose topic is a live or stopping mirror is `Rejected` with `manage it with KafkaMirrorTopic`: no config change, no new partitions and no ACL created or pruned on that literal topic. A promoted mirror, `STOPPED` with its topic still there, is a normal topic again and can be managed by a `KafkaTopic`. Without `rest`, a `KafkaTopic` cannot tell a mirror from a normal topic, and `doctor` says so.

On the operator, a `KafkaTopic` with `deletionPolicy: Delete` never deletes a topic that is a mirror ([Delete topics from Kubernetes](/flock/docs/gitops/how-to/delete-topics-from-kubernetes/#4-release-a-topic-whose-cleanup-cannot-run)).

### 7. Import existing mirrors

With `rest` in the cluster config, [`import cluster`](/flock/docs/gitops/how-to/import-an-existing-cluster/) writes each mirror as a `KafkaMirrorTopic` with its link, source topic and replication factor, and never also as a `KafkaTopic`. Its summary warns, and marks the import partial, when it leaves something for you to review:

- `MirrorConfigNotImported`: the mirror has configs set that the link does not sync. They may be local or may come from the source, so add the local ones to `config` yourself.
- `ExternallyManagedOrAmbiguousACLs`: the link syncs ACLs, or its `acl.sync.enable` cannot be read, so the ACLs on the mirror are not imported. With ACL sync off, they are imported as a `KafkaAccessPolicy`.
- `MirrorImportDeferred`: a mirror is `PENDING_STOPPED`. Run the import again once it finishes.
- `MirrorStaleEntry`: Kafka REST still lists a stopped mirror whose topic no longer exists.

`MirrorUnhealthy` warns about a mirror that is imported but not `ACTIVE`, without making the import partial.

## Check it worked

```bash
monedula-gitops verify -f ./manifests --cluster-config-file ./clusters/dest.yaml   # exits 0
```

`verify` exits 0, and records produced to `orders` on the source cluster can be consumed from `orders` on the destination.

## Related

- The [KafkaMirrorTopic reference](/flock/docs/gitops/reference/resources/kafka-mirror-topic/) lists every field, and the [KafkaCluster reference](/flock/docs/gitops/reference/resources/kafka-cluster/) the `rest` block.
- Runnable version: [scenarios/26-mirror-topic](https://github.com/monedula-dev/monedula-gitops/tree/main/scenarios/26-mirror-topic), two Confluent Server clusters joined by a cluster link.