Docs / Self-healing on Kubernetes

Self-healing on Kubernetes

KalDB is Kubernetes native. Pods are stateless, Kubernetes health checks restart or reschedule failed ones, and KalDB moves their work to healthy nodes on its own, with no shard rebalancing and no manual recovery.

KalDB is Kubernetes native. Every component runs as a stateless pod: Kafka and S3 hold the data, so a pod can be restarted, rescheduled, or lose its Kubernetes node without affecting any other node. Kubernetes health checks catch a failed pod and replace it, and KalDB moves that pod’s work to healthy nodes on its own. No shards are rebalanced, and nobody has to step in.

How KalDB heals itself when nodes failIndexers pull from Kafka and upload snapshots to S3. Cache nodes serve snapshots to query nodes, which answer AI agents through a Kubernetes Service. A cache node fails its health check, drops out of searches, and its snapshots are reassigned to free cache slots and loaded from S3 while Kubernetes replaces the pod. An indexer crashes, is restarted, and resumes from its last offset in S3. A query node fails and the remaining query node takes the traffic. The cluster ends fully healthy with no operator action.Kafkapartitionslogs wait hereIndexer 1pullingIndexer 2pullingrestarted · replayingS3every snapshot, stored onceCache 1S1S2Cache 2Cache 2 · failedCache 2 · replacedS3S4Cache 3S3S4Query 1Query 2Query 2 · failedQuery 2 · replacedvia k8s ServiceAI agentsKubernetes · health checksEvery pod passes its /health probe.Metrics and alerts work as usual.cache-2 fails. Pod is replaced.Its registration expires: no searches.S3, S4 reassigned to Cache 3.New cache-2 rejoins as spare slots.indexer-2 crashed and restarted.Resumes from its last offset in S3.query-2 fails. Pod is replaced.Query 1 takes all the traffic.Every pod is healthy again.Operator actions: 0
Cluster Healthy. Every snapshot is in S3 and assigned to a cache node. Cache 2 is down. Searches skip it; other nodes are unaffected. S3 and S4 are back in cache on Cache 3. Nothing was copied between nodes. Indexer 2 is replaying from Kafka. No logs lost. Query 2 is down. Searches keep working through Query 1. Fully healed, with no one paged.

The problem

In Elasticsearch and OpenSearch, every data node owns the shards on its disk. When a node fails, the cluster turns yellow or red. The master promotes replicas, then copies whole shards to other nodes to restore the replica count. That copying competes with ingest and searches for disk and network, can take hours on a large cluster, and often needs an operator to throttle it, reroute stuck shards, or bring a node back by hand.

So node failures turn into incidents. Teams keep someone on call to babysit recoveries, avoid restarting nodes, and schedule upgrades for quiet hours.

How it works

KalDB nodes don’t own data. Kafka holds logs that aren’t indexed yet, S3 holds every indexed snapshot, and the metadata store records which node is doing what. A failed node only loses work in progress, and there is always another place to get the data from.

Detection uses the same tools for every component. Each node serves a /health endpoint for Kubernetes liveness and readiness probes, alongside its usual Prometheus metrics. Each node also keeps a session with the metadata store. If that session expires, the node exits so that Kubernetes restarts it cleanly instead of leaving it half-connected.

  • Cache node. A cache node’s search registration and cache slots are ephemeral records, so they disappear as soon as the node is gone. Query nodes stop sending it searches right away. The cluster manager watches cache slots, sees that the node’s snapshots have no slot anymore, and within seconds assigns them to free slots on other cache nodes, which load them from S3. A periodic sweep catches anything a change event missed. The replacement pod rejoins with empty slots.
  • Indexer. Kubernetes restarts the indexer, which looks up the last offset for its partition that is already in S3 and replays the rest from Kafka. If it is far behind, it skips to the newest logs and hands the gap to recovery nodes. See Pull-based ingestion and Fresh logs first.
  • Recovery node. Recovery tasks are stored durably, and a recovery node’s claim on a task is ephemeral. If the node dies mid-task, its claim disappears, and the cluster manager hands the task to another free recovery node.
  • Query node. Query nodes hold no data. Kubernetes takes a failed one out of the Service and replaces it, and the other query nodes take the traffic. A node that fails in the middle of a search makes that search return partial results on time, with the failed node reported, instead of hanging.
  • Cluster manager. The manager isn’t in the write or search path, so indexing and searches keep running while it restarts. Its services run on a schedule against the metadata store, so a restarted manager picks up whatever assignments are waiting. See Metadata without a master.

Why it matters

  • Far less on-call load. A failed node is a pod restart, not an incident. Nobody has to rebalance shards, reroute replicas, or nurse a cluster back to green.
  • Failures stay local. One node going down only affects the work that node was doing. Other nodes keep indexing and searching as normal.
  • Recovery reads from S3, not from peers. Replacing a cache node never copies data between nodes, so recovery doesn’t slow down the rest of the cluster.
  • Safe to restart anything. Node upgrades, Kubernetes node drains, and spot instance reclaims are routine, so you can roll out changes during the day.

Trade-offs

  • A failed cache node’s data is briefly unavailable. With one replica set, a cache node’s snapshots can’t be searched until they’re reassigned and loaded from S3, usually within seconds to minutes depending on size. Run more than one replica set if searches must never miss data during a failure.
  • Restarted indexers replay before they’re current. Logs that were only in the crashed indexer’s active chunk are searchable again once the replacement replays them from Kafka.
  • Assignments wait while the manager is down. New snapshots aren’t assigned to cache and recovery tasks aren’t handed out until the manager is back. Run it under Kubernetes so it restarts on its own.
  • The metadata store must stay healthy. Nodes exit when their metadata session expires. Run ZooKeeper or etcd with enough members to survive a node loss.

Deploying on Kubernetes

KalDB deploys like any stateless service. Every role (preprocessor, indexer, query, cache, recovery, and manager) runs from the same container image, and each pod picks its role with the NODE_ROLES environment variable. Define one Deployment per role and a plain kubectl apply brings up the cluster, with each tier deployed and sized on its own.

  • No state in the pods. Logs are durable in Kafka, indexed data is in S3, and metadata is in ZooKeeper or etcd. Indexers and cache nodes use local disk only as a cache, so it can be fast instance storage or an emptyDir instead of a persistent volume.
  • Health checks and metrics on every pod. Every KalDB server exposes /health for Kubernetes liveness and readiness probes, and /metrics for Prometheus, alongside your usual dashboards and alerts.
  • Node restarts stay local. When a Kubernetes node is drained or restarted, its pods shut down cleanly and are rescheduled elsewhere. A new indexer resumes from Kafka and a new cache pod reloads its snapshots from S3. Pods on other nodes keep running, and no shards are relocated.
  • Each role scales on its own. The cache tier autoscales on hpa_cache_demand_factor_<replicaSet>, targeting 1.0. Recovery pods scale on CPU, and query pods on query load. See Recommendations.

Related