Cloud Native 8 min read

Why Kubernetes Failover Can't Protect Canal Data: A Real‑World Debate

The article explains how Kubernetes can ensure pod availability for stateless services but fails to preserve critical state for Canal Server, illustrating the need for external coordination tools like Zookeeper or Nacos to achieve true high‑availability for stateful applications.

Architect Practice
Architect Practice
Architect Practice
Why Kubernetes Failover Can't Protect Canal Data: A Real‑World Debate

Background

A DevOps engineer proposed deploying Canal Server in a Kubernetes cluster with Zookeeper for high‑availability. The question arose whether Kubernetes alone could provide failover.

Stateless services in Kubernetes

Typical API services (e.g., user login, product detail) are stateless: each request is independent and any pod can handle it. Kubernetes detects a failed pod, launches a replacement, and routes traffic without user impact.

Stateful nature of Canal Server

Canal Server acts as a MySQL slave, continuously reading the binlog and emitting every database change. Its only critical state is the current binlog position (e.g., mysql-bin.001, position=1000), which indicates how far it has consumed.

Effect of a pure Kubernetes restart

Canal Pod A running:
  Current state → mysql-bin.001, position=1000
  (means the 1000th change has been consumed)

If Pod A crashes, Kubernetes starts Pod B, but Pod B starts with an empty memory and does not know the last consumed position. Three possible outcomes are:

Start from the beginning : Pod B consumes from position=0, causing massive data duplication.

Start from the latest offset : Pod B jumps to the newest position, losing all intermediate changes.

Rely on a local file : The local file disappears after the pod migrates, resulting in the same state loss.

All three outcomes are unacceptable because duplicated data can trigger redundant operations and lost data leads to downstream inconsistency.

How Zookeeper / Nacos solve the problem

Position persistence : Canal periodically writes its current binlog position to Zookeeper or Nacos, allowing a new pod to resume from the exact offset.

Failure detection and leader election : Each Canal instance registers a temporary node. When the leader disappears, other instances instantly detect the session loss and take over.

Unified configuration management : Connection details and filter rules are stored centrally, so configuration changes do not require restarting every instance.

What Kubernetes can and cannot do

Kubernetes guarantees that a Canal process is running (process‑level high availability) but does not guarantee that the business state (the binlog position) is preserved. Both layers are required for true high‑availability.

Kubernetes ensures: a Canal process is running.
Zookeeper/Nacos ensures: the process knows where to continue.

Practical guidance on Alibaba Cloud

In Alibaba Cloud ACK environments, the recommended approach is to use the managed MSE Nacos service instead of self‑deploying Zookeeper. Canal version 1.1.4 and later supports Nacos as both registration and configuration center, eliminating the need to maintain a separate Zookeeper cluster.

Fault‑tolerance workflow

Canal Pod 1 runs and periodically writes its position to Nacos.

Pod 1 crashes.

Nacos detects the session expiration.

Pod 2 reads the last saved position from Nacos.

Pod 2 takes over and resumes consumption from that offset.

Result: Zero data loss and seamless business continuity.

Final takeaway

The decisive question for any service is: “If the process disappears and restarts, can it continue from where it left off?” If the answer is no, the service is stateful and requires an external state‑coordination layer such as Zookeeper or Nacos; Kubernetes alone is insufficient.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

High AvailabilityKubernetesZookeeperNacosCanalStateful Service
Architect Practice
Written by

Architect Practice

Committed to sharing tech and documenting ideas.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.