chinit
Pronounced “c-h-init” — short for ClickHouse init. Think cloud-init, but for the entire ClickHouse node lifecycle.
Operator-grade lifecycle management for ClickHouse on cloud VMs — without Kubernetes, external control planes, or fragile bash scripts.
Running ClickHouse directly on cloud virtual machines (AWS EC2 Auto Scaling Groups or Azure Virtual Machine Scale Sets) gives you raw NVMe and EBS throughput, Spot-instance economics, full kernel control, and zero container orchestration overhead.
There is just one catch: ClickHouse is deeply stateful, while cloud Auto Scaling Groups treat VMs as disposable cattle.
chinit bridges that gap. It is a single static Go binary that turns a newly launched cloud VM into a deterministic, self-healing ClickHouse cluster member in ~2–3 minutes — and keeps the cluster consistent through Spot interruptions, scale-out bursts, rolling upgrades, and abrupt instance terminations.
flowchart LR
A["VM Launches<br/>(EC2 ASG / Azure VMSS)"] --> B["~1.5 KB Wrapper<br/>fetches chinit.yaml"]
B --> C["chinit boot<br/>convergent Go pipeline"]
C --> D["Claim Lease · Mount Disks<br/>Verify SHA-256 Bundle"]
D --> E["Render Configs · Start Server<br/>Sync Schema · Wire Timers"]
E --> F["Self-Healing Member<br/>in ~2–3 min"]
style A fill:#f1f5f9,stroke:#94a3b8
style B fill:#eff6ff,stroke:#3b82f6
style C fill:#2563eb,stroke:#1d4ed8,color:#fff
style D fill:#eff6ff,stroke:#3b82f6
style E fill:#eff6ff,stroke:#3b82f6
style F fill:#dcfce7,stroke:#16a34a
What Problem Is chinit Trying to Solve?
Almost every team running ClickHouse on VMs starts the same way: a cloud-init shell script in Terraform user_data that formats a disk, templates a few XML files with sed, and starts clickhouse-server.
That script works great on day one — when four fresh VMs boot together on an empty VPC. It falls apart at 2:00 AM six weeks later when the cloud starts churning instances underneath a live cluster:
1. The Identity Trap
ClickHouse Keeper tracks replicas by stable logical names (reader-2), but Auto Scaling Groups hand every replacement VM a random hostname (ip-10-0-1-147). Render config before claiming a stable identity and the node either refuses to replicate or pollutes Keeper with orphan replica paths.
2. The Silent Termination Trap
Spot preemptions and EC2/VMSS health-check kills frequently bypass external lifecycle hooks. Dead nodes leave behind held ordinal slots, stale DNS A records, and ghost entries in remote_servers that stall distributed queries across the fleet.
3. The Day-2 Drift Trap
Bootstrapping is only 10% of a database node's life. Over months, disks fill up, replication queues get wedged on missing parts, peers miss DDL while rebooting, and rolling out a new AMI risks taking down the last healthy writer or breaking Keeper Raft quorum.
chinit replaces that entire tangle of shell scripts, cron jobs, and ad-hoc Lambda hooks with one compiled, conformance-tested binary and one declarative YAML spec per role:
flowchart TB
SPEC["chinit.yaml (per role)<br/>writer · reader · keeper · backup"]
subgraph BOOT["1. Convergent Boot (chinit boot)"]
direction LR
B1["Claim Lease Identity<br/>+ Verify Bundle SHA-256"] --> B2["Mount Disks by LABEL<br/>+ Tune Kernel & Fetch Secrets"] --> B3["Render Operator-Grade XML<br/>+ Register Shutdown Drain"] --> B4["Start ClickHouse<br/>+ Apply Schema"]
end
subgraph DAY2["2. Continuous Day-2 Convergence (systemd timers)"]
direction LR
J1["lease-renew (5m)<br/>heals DNS · /etc/hosts · remote_servers"] --> J2["schema-sync · replica-sync<br/>queue-heal · disk-autoscale"] --> J3["fleet-converge & task-poll<br/>safe rolling updates"]
end
subgraph EXIT["3. Unified Teardown (systemd shutdown + spot-watch)"]
D1["Stop Queues → Drop Replica on Peer → Delete DNS → Release Lease"]
end
SPEC --> BOOT
BOOT --> DAY2
DAY2 --> EXIT
style SPEC fill:#fefce8,stroke:#ca8a04
style BOOT fill:#eff6ff,stroke:#3b82f6
style DAY2 fill:#f0fdf4,stroke:#16a34a
style EXIT fill:#fef2f2,stroke:#dc2626
How chinit Accomplishes This
Stable Stateful Identity Inside Disposable Auto Scaling Groups
Writers and readers in Auto Scaling Groups claim a numbered ordinal lease (writer-0, reader-3, …) from DynamoDB or Azure Table Storage using atomic conditional writes before a single ClickHouse XML file is rendered. When a Spot reader is reclaimed, its replacement claims the freed reader-3 slot, updates Private DNS, and picks up replication seamlessly. Keepers and the dedicated backup node use deterministic IP-offset identities so Raft quorum endpoints never move.
In-Process Operator Config Rendering — Without Running Kubernetes
Under the hood, chinit embeds the battle-tested configuration rendering engine from the Altinity Kubernetes Operator for ClickHouse directly in-process. You write clean chi.yaml and keeper.yaml topology definitions, and chinit generates validated, permissioned config.d/ and users.d/ XML files locally on each VM — no Kubernetes API server required.
Self-Healing Convergence Every 5 Minutes
Distributed systems fail when they rely solely on one-shot edge triggers (“run this script when an instance launches or terminates”). Every 5 minutes, chinit lease-renew treats the live lease table as the single source of truth and reconciles /etc/hosts, Private DNS A records, and ClickHouse remote_servers XML. Even if a VM loses power instantaneously (kill -9 at the hypervisor), its lease expires and every surviving peer heals its routing tables automatically.
Zero-Control-Plane Fleet Coordination
Need to roll out a new ClickHouse version or configuration change across 20 VMs without dropping queries? chinit coordinates rolling updates directly through epoch-fenced compare-and-swap rows in the shared lease table — enforcing cluster disruption budgets (min_healthy_writers, min_healthy_readers) and ClickHouse Keeper Raft quorum checks (mntr) before touching a single node.
Why Not Shell Scripts or Kubernetes?
| Capability | Cloud-init Bash Scripts | chinit on Cloud VMs |
Kubernetes + Operator |
|---|---|---|---|
| Consistent logic across roles & clouds | Per-role scripts drift quickly | Single static binary; role is YAML data | Yes |
| Identity under Spot / ASG churn | Prone to hostname & Keeper races | Atomic lease claims + self-healing DNS | StatefulSet pod identity |
| Spot & health-check termination cleanup | Lifecycle hooks miss abrupt kills | Unified systemd shutdown drain + 5m GC |
Pod eviction hooks |
| Direct NVMe, EBS, & kernel control | Full hardware control | Full hardware control (THP, sysctl, labels) | Constrained by node/CRI |
| Extra control plane to run & pay for | None | None (uses S3/Blob + DynamoDB/Table) | Kubernetes cluster + CNI + CSI |
| Offline automated testing | Almost impossible without live VMs | Unit + cross-cloud conformance test suites | Kind / E2E clusters |
chinit gives you Kubernetes-operator-grade lifecycle safety with zero control-plane tax.
What’s Inside the Repository
| Path | What It Provides |
|---|---|
cmd/chinit + pkg/chinit |
The chinit Go binary, convergent boot engine, maintenance subcommands, AWS, Azure & Compose adapters, and conformance test suite |
deploy/compose |
Multi-node local Docker Compose cluster (keeper-0, writer-0, reader-0, otel-collector) running real systemd units using ghcr.io/stackgenhq/chinit-node |
images/aws & images/azure |
Packer definitions that pre-bake Ubuntu 24.04, ClickHouse, chinit, clickhouse-backup, and monitoring agents into Golden AMIs and Azure Gallery Images |
terraform/aws & terraform/azure |
Turnkey Terraform modules that provision the lease table, Private DNS zone, KMS/Key Vault secrets, SHA-256 verified config bundle, and node fleets |
.github/workflows |
Automated CI, GoReleaser multi-arch static binary releases, GHCR Compose image publishing, and golden image build pipelines |
Get Started in Minutes — Three Fast Paths
Path A — Run a 3-node cluster locally with Docker Compose (Copy & Paste). Save the standalone compose.yaml in the Quickstart and boot a full systemd-managed keeper-0 + writer-0 + reader-0 cluster on your laptop using our prebuilt ghcr.io/stackgenhq/chinit-node:latest image:
docker compose up -d --wait
docker compose exec writer-0 chinit fleet-status
Path B — Launch a cloud VM immediately. Prebuilt, public golden AMIs are published in us-west-2 (both Altinity Antalya 26.8 LTS with CAS ami-04292dd0d9281579e and upstream ClickHouse 26.8 LTS ami-0075eb79e447956ca), so you can evaluate chinit from any AWS account without waiting for a Packer build:
aws ec2 run-instances --region us-west-2 \
--image-id ami-04292dd0d9281579e \
--instance-type c8g.large \
--user-data file://wrapper.sh
The images ship with Ubuntu 24.04 (arm64), ClickHouse 26.8 LTS (26.8.34.20001.altinityantalya or 26.8.36.3), chinit 0.2.6, clickhouse-backup, and observability agents pre-installed. See Installation for multi-region copy instructions or building custom images in your own account.
Path C — Deploy a full cloud cluster. The Terraform modules provision everything — lease table, Private DNS zone, secrets, SHA-256-verified config bundle, IAM/RBAC, and all four node roles — in one apply:
module "clickhouse" {
source = "github.com/stackgenhq/chinit//terraform/aws"
cluster_name = "demo"
golden_ami_id = "ami-…" # or a copied public AMI
dns_zone_name = "clickhouse.internal"
subnet_cidr = "10.42.0.0/24"
}
Explore the Documentation
Quickstart →
Walk from a blank VM to a bootstrapped, self-maintaining ClickHouse node in five concrete steps.
Installation & Golden Images →
Verify release binaries, bake 2-minute boot images with Packer, and wire IAM/RBAC permissions.
Deploy with Terraform →
Provision a complete cluster — compute, identity, DNS, secrets — with the turnkey AWS or Azure modules.
The Boot Process →
Follow the 26-step convergent pipeline, parallel Phase 1 execution, and step-ordering invariants.
Day-2 Maintenance & Draining →
See how chinit heals replication queues, autoscales disks, drains Spot nodes, and rolls fleets.
The Spec (chinit.yaml) →
Complete reference for roles, lease ceilings, secrets, disruption budgets, telemetry, and hooks.
CLI Reference →
Every subcommand, flag, schedule, and structured exit code in the chinit binary.
Operator's Guide →
Day-2 operational runbook: in-place config refreshes, cordoning, storage-loss recovery, and debugging.
Architecture & Internals →
Hexagonal package boundaries, retry policies, CR slot mapping, and the provider conformance suite.
License
Licensed under the Apache License, Version 2.0. Configuration rendering adapters incorporate code derived from the Altinity Kubernetes Operator for ClickHouse (Apache-2.0) — see NOTICE.