KubeBlocks
BlogsEnterprise
⌘K
​
Blogs

Overview
Quickstart
Architecture

Operations

Stop / Start / Restart
Vertical Scaling
Horizontal Scaling
Volume Expansion
Reconfigure
Switchover
Manage Services

Observability

Prometheus Integration
  1. Resource Hierarchy
  2. Containers Inside Each Pod
    1. ClickHouse Data Pods
    2. ClickHouse Keeper Pods (topology: cluster only)
  3. Distributed Coordination via ClickHouse Keeper
  4. Sharding and Replication
  5. Traffic Routing
  6. Automatic Failover
  7. System Accounts

ClickHouse Architecture in KubeBlocks

This page describes how KubeBlocks deploys a ClickHouse cluster on Kubernetes — covering the resource hierarchy, pod internals, distributed coordination via ClickHouse Keeper, and traffic routing.

Application / Client
HTTP  {cluster}-{shardComponentName}:8123
Native  {cluster}-{shardComponentName}:9000
shard name = clickhouse-XXX (3-char random, e.g. clickhouse-x7k)
HTTP/native → all pods (no roleSelector)
Kubernetes Services
{cluster}-clickhouse-XXX
ClusterIP · :8123 HTTP · :9000 native · :8001 metrics
all pods in shard · no roleSelector
one service per shard · name = {cluster}-{shardComponentName}
shard component name assigned at creation (e.g. clickhouse-x7k)
All Replicas
→ all replicas (load balanced)
Pods · Shard Replicas
clickhouse-x7k-0REPLICA
🖱️
clickhouse
:8123 · :9000 · :9004 MySQL · :9005 PG · :9009 · :8001
💾 PVC data-0 · 50Gi
clickhouse-x7k-1REPLICA
🖱️
clickhouse
:8123 · :9000 · :9004 MySQL · :9005 PG · :9009 · :8001
💾 PVC data-1 · 50Gi
clickhouse-x7k-2REPLICA
🖱️
clickhouse
:8123 · :9000 · :9004 MySQL · :9005 PG · :9009 · :8001
💾 PVC data-2 · 50Gi
↔ReplicatedMergeTree via ClickHouse Keeperpart mutations coordinated in CH Keeper (ZK-compatible) · replicas fetch and apply in order
🔗Headless service {cluster}-clickhouse-x7k-headless — stable pod DNS for inter-server replication (:9009) and operator probes; not a client endpoint
Client Traffic
Replica Pod (all equivalent)
Persistent Storage

Resource Hierarchy

KubeBlocks models a ClickHouse cluster using two topologies defined in the ClusterDefinition:

Topology standalone — data shards only, no Keeper:

Cluster  →  Sharding (clickhouse)  →  Component (clickhouse-XXX)  →  InstanceSet  →  Pod × N

Topology cluster — data shards + ClickHouse Keeper:

Cluster  →  Component (ch-keeper)              →  InstanceSet  →  Pod × 3
         →  Sharding (clickhouse)  →  Component (clickhouse-XXX)  →  InstanceSet  →  Pod × N
ResourceRole
ClusterUser-facing declaration — specifies topology, shard count, replicas, storage, and resources
Sharding (clickhouse)KubeBlocks Sharding resource; manages N shard Components in parallel; each shard becomes an independent Component
Component (clickhouse-XXX)One Component per shard; the shard component name is {shardingName}-{3-char random ID} (e.g., clickhouse-x7k) assigned by KubeBlocks at creation time — not deterministic ordinals
Component (ch-keeper)ClickHouse Keeper ensemble (topology: cluster only); ZooKeeper-compatible coordination for replica synchronization and DDL replication
InstanceSetKubeBlocks custom workload (replaces StatefulSet); manages pods with stable identities
PodActual running instance; each pod gets a unique ordinal and its own PVC

Containers Inside Each Pod

ClickHouse Data Pods

Every ClickHouse data pod runs one main application container (plus a copy-tools init container that copies curl into a shared volume at startup):

ContainerPortPurpose
clickhouse8123 (HTTP), 8443 (HTTPS), 9000 (TCP native), 9004 (MySQL wire protocol), 9005 (PostgreSQL wire protocol), 9009 (inter-server HTTP), 9010 (inter-server HTTPS), 9440 (TCP secure), 8001 (metrics)ClickHouse database engine handling queries and replication; exposes Prometheus metrics natively on port 8001 (http-metrics)

Each pod mounts its own PVC for the ClickHouse data directory (/bitnami/clickhouse), providing independent persistent storage per replica.

ClickHouse Keeper Pods (topology: cluster only)

Each Keeper pod runs one container (plus a copy-tools init container that copies nc — netcat — into a shared volume for health-check scripts):

ContainerPortPurpose
clickhouse9181 (ZooKeeper-compatible client), 9234 (Raft internal), 8123 (HTTP), 9000 (TCP), 8001 (metrics)ClickHouse Keeper process — provides ZooKeeper-compatible coordination for replica sync and DDL replication; port 9181 is the client endpoint for data pods

Distributed Coordination via ClickHouse Keeper

ClickHouse uses ClickHouse Keeper (ch-keeper) for distributed coordination across replicas and shards. ClickHouse Keeper is a built-in, ZooKeeper-compatible coordination service deployed as a separate KubeBlocks Component (ch-keeper) within the same Cluster:

ClickHouse Keeper RolePurpose
Replica synchronizationCoordinates data part replication between replicas of the same shard
DDL replicationDistributes schema changes (CREATE, DROP, ALTER) across the cluster
Distributed query coordinationTracks which parts exist on which replicas for query planning
Leader stateMaintains metadata for ReplicatedMergeTree and other replicated table engines

ClickHouse data pods connect to ClickHouse Keeper using the {cluster}-ch-keeper service. The Keeper ensemble follows a Raft-based majority-quorum protocol (typically 3 nodes) to remain available during single-node failures. This component is only present in topology: cluster; in topology: standalone, no Keeper is deployed within the cluster. Without configuring an external ZooKeeper or ClickHouse Keeper, it is not advisable to use ReplicatedMergeTree or other table engines that depend on ZooKeeper/Keeper coordination.

Sharding and Replication

ClickHouse achieves horizontal scale-out through sharding and within-shard replication:

ConceptDescription
ShardA subset of data; different shards hold different rows of the same table
ReplicaA full copy of a shard's data stored on a separate pod; provides redundancy
Distributed tableA virtual table that fans queries out to all shards and aggregates results
ReplicatedMergeTreeTable engine used on each shard replica; ClickHouse Keeper tracks parts across replicas

When a replica fails, ClickHouse Keeper (in topology: cluster) detects the absence of its heartbeat. When the replica recovers, it fetches missing parts from other replicas automatically — no manual intervention required.

Traffic Routing

KubeBlocks creates two services for each ClickHouse shard component. Because cmpd-ch defines no roles: block, the ClusterIP service has no roleSelector and forwards to all pods in the shard:

ServiceTypePortsNotes
{cluster}-{shardComponentName}ClusterIP8123 (HTTP), 9000 (TCP), 8001 (metrics)All pods in the shard; no roleSelector — any replica can serve queries
{cluster}-{shardComponentName}-headlessHeadless—All pods; always created by the workload controller

Each shard's component name is {shardingName}-{3-char random ID} (e.g., clickhouse-x7k, clickhouse-m2p), assigned by KubeBlocks at cluster creation time. The resulting service names follow the same pattern: {cluster}-clickhouse-x7k, {cluster}-clickhouse-x7k-headless. These names are stable after creation but are not predictable before creation unless the cluster CR uses explicit shard IDs via shardTemplates[].shardIDs.

For direct pod addressing (replication traffic, ClickHouse Keeper communication), pods use the headless service DNS:

{pod-name}.{cluster}-{shardComponentName}-headless.{namespace}.svc.cluster.local

Automatic Failover

ClickHouse does not use a primary/replica role distinction at the application level — all replicas within a shard are equivalent and can serve queries. Recovery after a pod failure does not involve a role switch:

  1. A replica pod crashes — the failed pod stops serving queries for its shard
  2. CH Keeper detects the lost connection (topology: cluster only) — remaining replicas continue serving if at least one replica is healthy; Keeper tracks which data parts each replica holds
  3. KubeBlocks restarts the failed pod — the InstanceSet controller schedules a pod restart
  4. Recovered replica reconnects to CH Keeper — the pod re-registers and fetches data parts it missed during downtime from peer replicas automatically
  5. ClusterIP service is unchanged — all replicas are equivalent; no endpoint update is needed; the recovered pod resumes receiving traffic once it passes its readiness check
NOTE

Steps 2 and 4 require topology: cluster (CH Keeper deployed). In topology: standalone, no Keeper is present — inter-replica part synchronization is not available unless an external ZooKeeper or Keeper is configured.

System Accounts

KubeBlocks automatically manages the following ClickHouse system account. Passwords are auto-generated and stored in a Secret named {cluster}-{component}-account-{name}.

AccountRolePurpose
adminAdmin (superuser)ClickHouse administrative account used for cluster setup, DDL operations, and inter-replica communication

© 2026 KUBEBLOCKS INC