Explore Shadow Linking for Disaster Recovery
Shadow linking is a built-in disaster recovery mechanism that continuously replicates topics, consumer group offsets, and Schema Registry data from a source cluster to a shadow cluster running on Kubernetes. This lab demonstrates how shadow linking works and how you can use it to fail over to a shadow cluster.
In this lab, you deploy two single-node Redpanda clusters on Kubernetes and configure a shadow link between them. You then explore basic topic shadowing, Schema Registry shadowing, and consumer group failover.
What gets deployed
The setup script installs the following components:
-
cert-manager (namespace:
cert-manager): Manages TLS certificates -
Redpanda Operator (namespace:
rp-operator): Manages Redpanda cluster lifecycle -
Source cluster (namespace:
source): Primary cluster where you write data -
Shadow cluster (namespace:
shadow): Replication target cluster -
ShadowLink resource: Defines the replication relationship between clusters
The shadow link configuration mirrors all topics using wildcard filtering, replicates consumer group offsets, and synchronizes the Schema Registry, all at 5-second intervals.
Run the lab
-
Clone this repository:
git clone https://github.com/redpanda-data/redpanda-labs.git cd redpanda-labs/kubernetes/shadow-linking -
Create a local Kubernetes cluster using kind:
kind create cluster --name redpanda-shadow -
Run the setup script to deploy both clusters and configure shadow linking:
./setup.shThe script installs cert-manager, deploys the Redpanda Operator, creates the source and shadow clusters, configures the shadow link, sets up port forwarding for local access, and creates rpk profiles for both clusters.
-
Verify both clusters are healthy:
rpk --profile source cluster health rpk --profile shadow cluster health
Explore basic topic shadowing
This section shows how topics and messages automatically replicate from the source to the shadow cluster.
-
Create a topic on the source cluster:
rpk --profile source topic create basic -p1 -r1 -
Produce a message to the source cluster:
echo "Hello, world" | rpk --profile source topic produce basic -
Wait a few seconds for replication, then list topics on the shadow cluster:
rpk --profile shadow topic listYou should see the
basictopic appear on the shadow cluster. -
Consume messages from both clusters to verify data replication:
rpk --profile source topic consume basic -n1 rpk --profile shadow topic consume basic -n1The same message appears on both clusters.
Explore Schema Registry shadowing
This section shows how Avro schemas registered on the source cluster replicate to the shadow cluster, allowing shadow-side message deserialization.
-
Register an Avro schema on the source cluster:
rpk --profile source registry schema create syslog-value --schema resources/syslog.avsc --type avro -
Create a topic for schema-encoded messages:
rpk --profile source topic create syslog -p1 -r1 -
Produce Avro-encoded syslog records to the source cluster:
cat resources/syslogs.json | rpk --profile source topic produce syslog --schema-id=topic -
Wait a few seconds, then list schemas on both clusters:
rpk --profile source registry subject list rpk --profile shadow registry subject listThe
syslog-valueschema appears on both clusters. -
Consume decoded messages from the shadow cluster using the replicated schema:
rpk --profile shadow topic consume syslog -n1 --use-schema-registry -f'%v\n' | jqThe shadow cluster can deserialize messages using the replicated schema.
Explore consumer group failover
This section shows how consumer group offsets replicate to the shadow cluster, allowing consumers to resume from their exact position after a failover.
-
Create a topic on the source cluster:
rpk --profile source topic create foo -p1 -r1 -
Produce records and consume them on the source cluster:
seq 0 2 | rpk --profile source topic produce foo rpk --profile source topic consume foo -n3 -g consumer-group-fooThis creates a consumer group and processes the messages.
-
View consumer group offsets on both clusters:
rpk --profile source group describe consumer-group-foo rpk --profile shadow group describe consumer-group-fooThe consumer group and its offsets are replicated to the shadow cluster.
-
Trigger a failover to the shadow cluster:
rpk --profile shadow shadow failover shadow-link --all --no-confirm rpk --profile shadow shadow status shadow-linkThis command promotes the shadow cluster to become writable.
-
Produce more records and consume on the shadow cluster:
seq 3 5 | rpk --profile shadow topic produce foo rpk --profile shadow topic consume foo -n3 -g consumer-group-fooThe consumer resumes from the last committed offset (3) and consumes the new messages.
Clean up
To stop port forwarding, terminate the background processes:
kill $(cat local-port-forward.pid)
To delete the kind cluster and all resources:
kind delete cluster --name redpanda-shadow