clickhouse

by apecloud

Helm chartv1.2.0-alpha.1App 25.9.7Verified publisher

ClickHouse is an open-source column-oriented OLAP database management system. Use it to boost your database performance while providing linear scalability and hardware efficiency.

About this chart

ClickHouse

ClickHouse is an open-source column-oriented OLAP database management system. Use it to boost your database performance while providing linear scalability and hardware efficiency.

There are two key components in the ClickHouse cluster:

  • ClickHouse Server: The ClickHouse server is responsible for processing queries and managing data storage.
  • ClickHouse Keeper: The ClickHouse Keeper is responsible for monitoring the health of the ClickHouse server and performing failover operations when necessary, alternative to the Zookeeper.

Features In KubeBlocks

Lifecycle Management

ClickHouse Server

TopologyHorizontal scalingVertical scalingExpand volumeRestartStop/StartConfigureExposeSwitchover
standalone/clusterYesYesYesYesYesYesYesN/A

ClickHouse Keeper

TopologyHorizontal scalingVertical scalingExpand volumeRestartStop/StartConfigureExposeSwitchover
clusterYesYesYesYesYesYesN/AYes

Backup and Restore

FeatureMethodDescription
Full Backupclickhouse-backupuses clickhouse-backup tool to perform full backups of ClickHouse data
Incremental Backupclickhouse-backupuses clickhouse-backup tool to perform incremental backups based on previous backup

Versions

Major VersionsDescription
2222.3.18, 22.3.20, 22.6.1, 22.8.21, 22.9.4
2424.7.2, 24.8.3, 24.12.2
2525.4.4, 25.9.7

Prerequisites

  • Kubernetes cluster >= v1.21

  • kubectl installed, refer to K8s Install Tools

  • Helm, refer to Installing Helm

  • KubeBlocks installed and running, refer to Install Kubeblocks

  • ClickHouse Addon Enabled, refer to Install Addons

  • Create K8s Namespace demo, to keep resources created in this tutorial isolated:

    kubectl create ns demo
    

Examples

Create

Standalone Mode

Create a ClickHouse cluster with only ClickHouse server:

# cat examples/clickhouse/cluster-standalone.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: clickhouse-standalone
  namespace: demo
spec:
  # Specifies the name of the ClusterDef to use when creating a Cluster.
  clusterDef: clickhouse
  # Specifies the clickhouse cluster topology defined in ClusterDefinition.Spec.topologies, support standalone, cluster
  # - `standalone`: single clickhouse instance
  # - `cluster`: clickhouse with ClickHouse Keeper as coordinator
  topology: standalone
  # Specifies the behavior when a Cluster is deleted.
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # standalone topology also uses shardings in ClusterDefinition
  shardings:
    - name: clickhouse
      shards: 1
      template:
        name: clickhouse
        replicas: 1
        systemAccounts:
          - name: admin
            secretRef:
              name: udf-account-info
              namespace: demo
        resources:
          limits:
            cpu: '0.5'
            memory: 1Gi
          requests:
            cpu: '0.5'
            memory: 1Gi
        volumeClaimTemplates:
          - name: data
            spec:
              accessModes:
                - ReadWriteOnce
              resources:
                requests:
                  storage: 20Gi
---
apiVersion: v1
kind: Secret
metadata:
  name: udf-account-info
  namespace: demo
type: Opaque
data:
  password: cGFzc3dvcmQxMjM=  # 'password123' in base64

kubectl apply -f examples/clickhouse/cluster-standalone.yaml

It will create only one ClickHouse server pod with the default configuration. This example includes a predefined secret udf-account-info with password password123.

To connect to the ClickHouse server, you can use the following command:

clickhouse-client --host <clickhouse-endpoint> --port 9000 --user admin --password

[!NOTE] The password is defined in the secret udf-account-info or you can find it in secrets matching pattern <clusterName>-*-account-admin.

e.g. you can get the password by the following command:

# Get the secret name for standalone cluster
SECRET_NAME=$(kubectl get secrets -n demo -o name | grep clickhouse-standalone | grep account-admin)

# Get username and password
kubectl get $SECRET_NAME -n demo -o jsonpath='{.data.username}' | base64 -d && echo
kubectl get $SECRET_NAME -n demo -o jsonpath='{.data.password}' | base64 -d && echo

# Or from the predefined secret (if used)
kubectl get secrets udf-account-info -n demo -o jsonpath='{.data.password}' | base64 -d && echo

Cluster Mode

Create a ClickHouse cluster with ClickHouse servers and ch-keeper. The default cluster configuration includes sharding with 2 shards, each shard having 2 replicas:

# cat examples/clickhouse/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: clickhouse-cluster
  namespace: demo
spec:
  # Specifies the name of the ClusterDef to use when creating a Cluster.
  clusterDef: clickhouse
  # Specifies the clickhouse cluster topology defined in ClusterDefinition.Spec.topologies.
  # - `standalone`: single clickhouse instance
  # - `cluster`: clickhouse with ClickHouse Keeper as coordinator
  topology: cluster
  # Specifies the behavior when a Cluster is deleted.
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # Specifies a list of ClusterComponentSpec objects used to define the individual components that make up a Cluster. This field allows for detailed configuration of each component within the Cluster.
  # Note: `shardingSpecs` and `componentSpecs` cannot both be empty; at least one must be defined to configure a cluster.
  # ClusterComponentSpec defines the specifications for a Component in a Cluster.
  componentSpecs:
    - name: ch-keeper
      componentDef: clickhouse-keeper-1
      replicas: 1
      resources:
        limits:
          cpu: '0.5'
          memory: 1Gi
        requests:
          cpu: '0.5'
          memory: 1Gi
      systemAccounts:
        - name: admin
          secretRef:
            name: udf-account-info
            namespace: demo
      volumeClaimTemplates:
        - name: data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
  shardings:
    - name: clickhouse
      shards: 2 # with 2 shard
      template:
        name: clickhouse  # each shard is a clickhouse component, with 2 replicas
        componentDef: clickhouse-1
        replicas: 2
        systemAccounts:
          - name: admin # name of the system account
            secretRef:
              name: udf-account-info
              namespace: demo
        resources:
          limits:
            cpu: "1"
            memory: 2Gi
          requests:
            cpu: "1"
            memory: 2Gi
        volumeClaimTemplates:
          - name: data
            spec:
              accessModes:
                - ReadWriteOnce
              resources:
                requests:
                  storage: 20Gi
---
apiVersion: v1
kind: Secret
metadata:
  name: udf-account-info
  namespace: demo  # optional
type: Opaque
data:
  password: cGFzc3dvcmQxMjM=  # 'password123' in base64
kubectl apply -f examples/clickhouse/cluster.yaml

This example creates a cluster with:

  • 1 ClickHouse Keeper instance for coordination (ch-keeper component using clickhouse-keeper-1 ComponentDef)
  • 2 shards with 2 replicas each (total 4 ClickHouse server instances using clickhouse-1 ComponentDef)
  • Shows how to override the default accounts' password using a predefined secret

Option 1. override the rule passwordConfig to generate password

# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  componentSpecs:
    - name: ch-keeper
      replicas: 1
      # Overrides system accounts defined in referenced ComponentDefinition.
      systemAccounts:
        - name: admin # name of the system account
          passwordConfig: # config rule to generate  password
            length: 10
            numDigits: 5
            numSymbols: 0
            letterCase: MixedCases
            seed: clickhouse-cluster

Option 2. specify the secret for the account

# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  componentSpecs:
    - name: ch-keeper
      replicas: 1
      # Overrides system accounts defined in referenced ComponentDefinition.
      systemAccounts:
        - name: admin # name of the system account
          secretRef:
            name: udf-account-info
            namespace: demo
  shardings:
    - name: clickhouse
      shards: 2
      template:
        name: clickhouse
        replicas: 2
        systemAccounts:
          - name: admin
            secretRef:
              name: udf-account-info
              namespace: demo

The secret udf-account-info is automatically created with the cluster and contains:

apiVersion: v1
kind: Secret
metadata:
  name: udf-account-info
  namespace: demo
type: Opaque
data:
  password: cGFzc3dvcmQxMjM=  # 'password123' in base64

Cluster Mode with TLS Enabled

To create one ClickHouse server pod with the default configuration and TLS enabled.

# cat examples/clickhouse/cluster-tls.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: clickhouse-tls
  namespace: demo
spec:
  # Specifies the name of the ClusterDef to use when creating a Cluster.
  clusterDef: clickhouse
  # Specifies the clickhouse cluster topology defined in ClusterDefinition.Spec.topologies.
  # - `standalone`: single clickhouse instance
  # - `cluster`: clickhouse with ClickHouse Keeper as coordinator
  topology: cluster
  # Specifies the behavior when a Cluster is deleted.
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # Specifies a list of ClusterComponentSpec objects used to define the individual components that make up a Cluster. This field allows for detailed configuration of each component within the Cluster.
  # Note: `shardingSpecs` and `componentSpecs` cannot both be empty; at least one must be defined to configure a cluster.
  # ClusterComponentSpec defines the specifications for a Component in a Cluster.
  componentSpecs:
    - name: ch-keeper
      componentDef: clickhouse-keeper-1
      replicas: 1
      resources:
        limits:
          cpu: '0.5'
          memory: 1Gi
        requests:
          cpu: '0.5'
          memory: 1Gi
      systemAccounts:
        - name: admin
          secretRef:
            name: udf-tls-account-info
            namespace: demo
      volumeClaimTemplates:
        - name: data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
      tls: true   # set TLS to true for keeper
      issuer:     # if TLS is True, this filed is required.
        name: UserProvided  # set Issuer to UserProvided, P.S. KubeBlocks Issuer is unable for sharding typology.
        secretRef:
          name: clickhouse-cluster-tls
          namespace: demo
          ca: ca.crt
          cert: tls.crt
          key: tls.key
  shardings:
    - name: clickhouse
      shards: 1
      template:
        name: clickhouse
        componentDef: clickhouse-1
        replicas: 2
        systemAccounts:
          - name: admin
            secretRef:
              name: udf-tls-account-info
              namespace: demo
        resources:
          limits:
            cpu: '1'
            memory: 2Gi
          requests:
            cpu: '1'
            memor

Deploy clickhouse with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has clickhouse on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartclickhouse is pinned at v1.2.0-alpha.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply