- Learn
- ClickHouse
- ClickHouse Operator for Kubernetes
ClickHouse Operator for Kubernetes
Deploy ClickHouse on Kubernetes with the official operator.
The ClickHouse Operator automates deploying and managing ClickHouse clusters on Kubernetes. Instead of writing StatefulSets, Services, and ConfigMaps by hand, you define a ClickHouseInstallation custom resource and the operator handles the rest.
There are two operators available:
- Official ClickHouse Operator (by ClickHouse Inc.) is newer and under active development
- Altinity Operator is the more mature option with wider production adoption
Both are open source under Apache 2.0. This guide covers both, with a focus on the Altinity Operator since it has a longer track record.
Installing the Altinity Operator
With Helm
With kubectl
Verify the operator is running:
You should see the operator pod in a Running state.
Deploying a basic cluster
Create a file called clickhouse-cluster.yaml:
Apply it:
The operator creates the StatefulSet, Service, ConfigMap, and PersistentVolumeClaim automatically. Within a minute or two, your ClickHouse instance is ready.
Check the status:
Connecting to the cluster
The operator creates a Service for each cluster. Find it with:
For port-forwarding during development:
Port 9000 is the native TCP protocol. Port 8123 is the HTTP interface. You can connect with the clickhouse-client CLI, any PostgreSQL-compatible driver (via port 9004 if enabled), or a database management tool like DB Pro.
Multi-shard, multi-replica setup
For production, you typically want multiple shards (for horizontal scaling) and replicas (for high availability):
This creates a 2-shard, 2-replica cluster (4 pods total). Each shard holds a portion of your data. Each replica is a copy within that shard.
Replication requires ClickHouse Keeper (or ZooKeeper). Deploy ClickHouse Keeper separately or use the operator's built-in support.
Deploying ClickHouse Keeper
ClickHouse Keeper replaces ZooKeeper for coordinating replicated tables. It's lighter weight and maintained by the ClickHouse team.
Always deploy an odd number of Keeper nodes (3 or 5) for proper quorum.
Configuration management
ClickHouse settings
Add settings under spec.configuration.settings:
The operator applies these to the ClickHouse config files and restarts pods if needed.
User management
Define users in the spec:
Generate the SHA256 hash:
Custom config files
For advanced configuration, mount additional config files:
Scaling
Adding shards
Update shardsCount in the spec and apply:
The operator adds new pods without disrupting existing ones. Data doesn't redistribute automatically. You need to rebalance using ALTER TABLE ... MOVE PARTITION or by setting up a distributed table that includes the new shards.
Adding replicas
Update replicasCount and apply. New replicas clone data from existing replicas in the same shard. This happens automatically through ClickHouse's replication protocol.
Vertical scaling
Change the resource requests/limits in the pod template and apply. The operator performs a rolling restart, updating one pod at a time.
Upgrades
To upgrade ClickHouse, change the image tag in the pod template:
Apply the change. The operator performs a rolling upgrade, one pod at a time, waiting for each pod to become healthy before proceeding.
For major version upgrades, check the ClickHouse release notes for breaking changes. Test the upgrade in a staging environment first.
Monitoring
Prometheus metrics
ClickHouse exposes Prometheus metrics on port 9363 by default. Add a ServiceMonitor if you're using the Prometheus Operator:
Key metrics to watch
ClickHouseMetrics_Query: Active queriesClickHouseMetrics_Merge: Active mergesClickHouseAsyncMetrics_MaxPartCountForPartition: Parts per partition (high values indicate merge pressure)ClickHouseProfileEvents_InsertedRows: Insert throughputClickHouseMetrics_MemoryTracking: Memory usage
Backup and restore
The Altinity Operator integrates with clickhouse-backup, a tool for creating and restoring backups to S3 or GCS.
Add a backup sidecar to your pod template:
Create a backup:
Production checklist
Before running ClickHouse in production on Kubernetes:
Storage:
- Use
gp3orio2EBS volumes on AWS (notgp2) - Size volumes with 20-30% headroom for merges
- Set
allowVolumeExpansion: trueon your StorageClass
Resources:
- Set both requests and limits for CPU and memory
- ClickHouse benefits from memory. Allocate at least 8 GB per node for production workloads
- Use dedicated node pools for ClickHouse to avoid noisy neighbors
Networking:
- Use
topologySpreadConstraintsor pod anti-affinity to spread replicas across availability zones - Configure NetworkPolicies to restrict access to ClickHouse ports
Reliability:
- Deploy ClickHouse Keeper with 3 or 5 nodes across zones
- Use PodDisruptionBudgets to prevent too many pods going down during maintenance
- Test failover by killing pods and verifying replicas take over
Security:
- Use SHA256 password hashes, not plaintext
- Restrict user access by IP range
- Enable TLS for client connections
Official ClickHouse Operator
The official operator (by ClickHouse Inc.) was released in 2025 and uses different CRDs:
Installation requires cert-manager:
The official operator is catching up in features. For new deployments, evaluate both operators. For existing production clusters, the Altinity Operator remains the safer choice due to its longer track record.
Quick reference
| Task | Command |
|---|---|
| Install operator (Helm) | helm install clickhouse-operator altinity/altinity-clickhouse-operator |
| Deploy cluster | kubectl apply -f clickhouse-cluster.yaml |
| Check status | kubectl get chi -n clickhouse |
| Port-forward | kubectl port-forward svc/clickhouse-my-cluster 9000:9000 8123:8123 |
| Scale shards | Edit shardsCount and kubectl apply |
| Upgrade | Edit image tag and kubectl apply |
| View logs | kubectl logs chi-my-cluster-default-0-0-0 -n clickhouse |
| Create backup | kubectl exec ... -- clickhouse-backup create <name> |