Skip to content
stackgenhqPublic

About

Cloud-adaptive ClickHouse node bootstrapper and lifecycle manager for cloud VMs (AWS EC2 & Azure VMSS), with Packer golden images and Terraform cluster modules.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

chinit — ClickHouse Node Bootstrapper for Cloud VMs

chinit prepares a ClickHouse server to join its cluster on cloud VMs — automatically, reliably, and without a pile of fragile boot scripts.

When you run ClickHouse on virtual machines instead of Kubernetes, every new server has work to do before it becomes a functioning cluster member: detect which cloud and role it belongs to, fetch its configuration, claim its identity, prepare its disks, join the cluster, and run ongoing maintenance throughout its lifecycle. Doing this with cloud-init shell scripts works at first, until a node gets replaced by a spot interruption or scale-in event and the scripts race the cluster into an inconsistent state.

chinit replaces those scripts with a single static binary that runs the same tested logic on every node and cloud:

instance launches → chinit boot → node is a healthy cluster member (~2-3 min)

CI GitHub release Go version License Go Report Card

What It Does

  • Identifies the node: Detects the cloud provider (AWS or Azure, with a provider registry for additional clouds), reads instance metadata, and determines the node's role (writer, reader, keeper, or backup) from a declarative spec.
  • Fetches configuration safely: Downloads a versioned configuration bundle from object storage and verifies its SHA-256 digest before applying anything.
  • Prepares the machine: Mounts and formats disks by filesystem label, applies OS-level tuning for ClickHouse, and installs validated configuration files.
  • Claims a stable identity: Assigns a deterministic identity (via a lease table or static IP offset) so a database node keeps the same hostname and DNS record even when the underlying VM is replaced.
  • Joins the cluster: Creates schemas, syncs replicas, and registers with peer nodes.
  • Runs ongoing maintenance: Executes recurring background tasks (schema sync, replica sync, lease renewal, health checks, disk autoscaling, backups, and spot interruption draining) as systemd timers and services calling chinit subcommands.
  • Drains cleanly on shutdown: Releases its identity lease, removes DNS records, and drops replica registrations through a single systemd shutdown hook.

From first boot to termination, the entire lifecycle is driven by one binary and one YAML spec per role.

Where It Fits

ClickHouse on Kubernetes is well served by operators (Altinity's operator and the official ClickHouse operator). This project targets stateful ClickHouse fleets on cloud VMs — EC2 Auto Scaling Groups and Azure VM Scale Sets — where you want direct NVMe/EBS storage access, spot instance economics, kernel-level tuning, and no Kubernetes control plane in the middle.

The companion Packer templates in images/ pre-bake ClickHouse, chinit, backup tools, and OS settings into a VM image for AWS and Azure, reducing node bootstrap time from 8–12 minutes to 2–3 minutes.

Key Features

  • Single static binary: No external agents or runtime dependencies; requires only a ~1.5 KB user-data wrapper to launch a node.
  • Cloud-adaptive: Built-in support for AWS and Azure via a clean provider interface.
  • Checksum-verified config bundles: Pulls configuration from S3 or Azure Blob Storage and enforces SHA-256 verification.
  • Declarative node specs (chinit.yaml): Typed and validated configuration per node role.
  • Convergent, resumable boot: Probes actual machine state before each step, records progress in /var/lib/chinit/state.json, and safely resumes interrupted boots.
  • Stable node identity: Supports both static IP-offset mapping and lease-claimed ordinals (DynamoDB on AWS, Table Storage on Azure) for auto-scaling groups.
  • Graceful spot & shutdown draining: Drains replication queues, drops replicas, and releases leases on spot notices or OS shutdown.
  • Keeper quorum protection: Verifies ClickHouse Keeper (mntr) quorum health before rolling or stopping keeper nodes.
  • Built-in maintenance subcommands: Installed as simple one-line systemd units and timers.
  • Pre-baked golden images: Ready-to-use Packer definitions for AWS AMIs and Azure Compute Gallery images.

Getting Started

Try It Locally with Docker Compose (Copy & Paste)

Want to see chinit bootstrap a 3-node ClickHouse + Keeper cluster (keeper-0, writer-0, reader-0) with full systemd timer parity on your laptop before touching AWS or Azure?

Our GitHub Actions workflow publishes a prebuilt multi-arch (linux/amd64, linux/arm64) node image to ghcr.io/stackgenhq/chinit-node:latest with the default configuration bundle, secrets, and per-role specs baked in. Drop this compose.yaml into any empty directory and run docker compose up -d --wait:

x-chinit-node: &chinit-node
  image: ghcr.io/stackgenhq/chinit-node:latest
  privileged: true
  cgroup: host
  stop_signal: SIGRTMIN+3
  stop_grace_period: 30s
  tmpfs:
    - /run
    - /run/lock
  ulimits:
    nofile:
      soft: 262144
      hard: 262144

services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:0.118.0
    command:
      - |
        --config=yaml:
        receivers:
          otlp:
            protocols:
              http:
                endpoint: 0.0.0.0:4318
        processors:
          batch: {}
        exporters:
          debug:
            verbosity: detailed
        service:
          pipelines:
            logs:
              receivers: [otlp]
              processors: [batch]
              exporters: [debug]
            metrics:
              receivers: [otlp]
              processors: [batch]
              exporters: [debug]
            traces:
              receivers: [otlp]
              processors: [batch]
              exporters: [debug]
    ports:
      - "4318:4318"
    networks:
      chnet:
        ipv4_address: 10.142.0.5

  keeper-0:
    <<: *chinit-node
    hostname: keeper-0
    environment:
      CHINIT_CLOUD: compose
      CHINIT_ROLE: keeper
      CHINIT_REGION: local
      CHINIT_PRIVATE_IP: 10.142.0.20
      CHINIT_INSTANCE_ID: compose-keeper-0
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
      - ch-leases:/var/lib/chinit-cluster
      - keeper-0-data:/var/lib/clickhouse-keeper
      - keeper-0-ch:/var/lib/clickhouse
    networks:
      chnet:
        ipv4_address: 10.142.0.20
        aliases:
          - keeper-0
          - keeper-0.ch.local
    healthcheck:
      test: ["CMD-SHELL", "test -f /var/lib/cloud/instance/boot-finished && systemctl is-active --quiet clickhouse-keeper"]
      interval: 5s
      timeout: 5s
      retries: 24
      start_period: 15s

  writer-0:
    <<: *chinit-node
    hostname: writer-node-0
    depends_on:
      otel-collector:
        condition: service_started
      keeper-0:
        condition: service_healthy
    environment:
      CHINIT_CLOUD: compose
      CHINIT_ROLE: writer
      CHINIT_REGION: local
      CHINIT_PRIVATE_IP: 10.142.0.10
      CHINIT_INSTANCE_ID: compose-writer-0
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
      - ch-leases:/var/lib/chinit-cluster
      - writer-0-data:/var/lib/clickhouse
    ports:
      - "8123:8123"
      - "9000:9000"
      - "9150:9150"
    networks:
      chnet:
        ipv4_address: 10.142.0.10
    healthcheck:
      test: ["CMD-SHELL", "test -f /var/lib/cloud/instance/boot-finished && curl -sf http://localhost:8123/ping"]
      interval: 5s
      timeout: 5s
      retries: 30
      start_period: 20s

  reader-0:
    <<: *chinit-node
    hostname: reader-node-0
    depends_on:
      otel-collector:
        condition: service_started
      keeper-0:
        condition: service_healthy
    environment:
      CHINIT_CLOUD: compose
      CHINIT_ROLE: reader
      CHINIT_REGION: local
      CHINIT_PRIVATE_IP: 10.142.0.30
      CHINIT_INSTANCE_ID: compose-reader-0
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
      - ch-leases:/var/lib/chinit-cluster
      - reader-0-data:/var/lib/clickhouse
    ports:
      - "18123:8123"
      - "19150:9150"
    networks:
      chnet:
        ipv4_address: 10.142.0.30
    healthcheck:
      test: ["CMD-SHELL", "test -f /var/lib/cloud/instance/boot-finished && curl -sf http://localhost:8123/ping"]
      interval: 5s
      timeout: 5s
      retries: 30
      start_period: 20s

networks:
  chnet:
    driver: bridge
    ipam:
      config:
        - subnet: 10.142.0.0/24

volumes:
  ch-leases:
  keeper-0-data:
  keeper-0-ch:
  writer-0-data:
  reader-0-data:

Boot the cluster, inspect fleet health, and verify ReplicatedMergeTree replication from writer-0 to reader-0:

docker compose up -d --wait

# Inspect settled leases, node health, and active systemd maintenance timers
docker compose exec writer-0 chinit fleet-status
docker compose exec writer-0 systemctl list-timers 'chinit-*' --no-pager

# Write a row on writer-0 and read it back from reader-0
docker compose exec writer-0 clickhouse-client --user admin --password compose-admin-pass \
  --query "INSERT INTO default.events (source, message) VALUES ('compose', 'hello chinit')"
docker compose exec reader-0 clickhouse-client --user admin --password compose-admin-pass \
  --query "SELECT * FROM default.events"

# Tear down when finished
docker compose down -v

See deploy/compose/README.md for custom bundle/spec mounts and the end-to-end Ginkgo acceptance suite.

Deploy on AWS or Azure with Terraform

The quickest way to deploy a full cloud cluster is with the Terraform modules, which provision the lease table, private DNS zone, secrets, instance IAM/RBAC roles, SHA-verified configuration bundle, and the four node roles (writer, reader, keeper, and optional backup):

module "clickhouse" {
  source = "github.com/stackgenhq/chinit//terraform/aws" # or .../terraform/azure

  cluster_name  = "demo"
  golden_ami_id = "ami-…" # built from images/aws (or a gallery image ID on Azure)
  dns_zone_name = "clickhouse.internal"
  subnet_cidr   = "10.42.0.0/24"
}

See terraform/ for full module documentation and examples.

To install the chinit binary directly on a Linux host:

CHINIT_VERSION=v0.1.0
curl -fsSL -o chinit \
  "https://github.com/stackgenhq/chinit/releases/download/${CHINIT_VERSION}/chinit-linux-arm64"
curl -fsSL "https://github.com/stackgenhq/chinit/releases/download/${CHINIT_VERSION}/chinit-SHA256SUMS" \
  | grep linux-arm64 | sed 's|chinit-linux-arm64|chinit|' | sha256sum -c -
sudo install -m 0755 chinit /usr/local/bin/chinit

Then run chinit boot -spec /var/lib/clickhouse-bootstrap/chinit.yaml. See the Operator's Guide for full details on the spec format, boot pipeline, and maintenance subcommands, and images/BOOT.md for a walkthrough of the boot sequence.

Documentation

Using chinit

Building Images & Contributing

  • Golden Images — Packer templates for AWS and Azure
  • Architecture — Internal package layout, boot engine, identity model, and conformance tests
  • Contributing Guide — Development workflow and pull request guidelines

Community & Support

Requirements

  • Linux VMs on AWS or Azure (arm64 or amd64)
  • ClickHouse 24.8+ recommended (tested with 25.12 and 26.x)
  • Object storage bucket/container (AWS S3 or Azure Blob Storage) for the configuration bundle

Releases

  • Pushing a v0.* tag triggers CI to build and publish static binaries (linux/darwin, arm64/amd64) along with chinit-SHA256SUMS via GoReleaser.
  • Release asset names (chinit-<os>-<arch> and chinit-SHA256SUMS) are stable so golden-image builds and bootstrap wrappers can pin and verify them before installation.
  • Multi-arch Docker Compose node images (linux/amd64 and linux/arm64) are built and published to GitHub Container Registry at ghcr.io/stackgenhq/chinit-node:latest (and versioned tags ghcr.io/stackgenhq/chinit-node:v0.*) via .github/workflows/publish-compose-image.yaml.

License

Copyright (C) 2026 StackGen, Inc. All rights reserved.

chinit is licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.

This project was originally extracted from a fork of the Altinity Kubernetes Operator for ClickHouse (Apache-2.0); extracted portions are Copyright (C) 2019 Altinity Ltd and/or its affiliates. Third-party Go dependency attributions are listed in THIRD_PARTY_NOTICES.md.

About

Cloud-adaptive ClickHouse node bootstrapper and lifecycle manager for cloud VMs (AWS EC2 & Azure VMSS), with Packer golden images and Terraform cluster modules.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages