Skip to content

Commit dde4ebe

Browse files
Feature/extra config, init scripts (#18)
* adds extra config value for misc. config options for ClickHouse * adds options for an init scripts configmap, updates docs
1 parent 05402b6 commit dde4ebe

File tree

6 files changed

+115
-12
lines changed

6 files changed

+115
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ helm install clickhouse-operator clickhouse-operator/altinity-clickhouse-operato
2727
## Helm Charts
2828

2929
- **[clickhouse](./charts/clickhouse/)**: All-in-one chart to deploy a ClickHouse cluster (and optionally Keeper and the Altinity Operator)
30-
- **[clickhouse](./charts/clickhouse-eks/)**: An EKS-specific chart for high-availability ClickHouse clusters.
30+
- **[clickhouse-eks](./charts/clickhouse-eks/)**: An EKS-specific chart for high-availability ClickHouse clusters.
3131

3232
### Deprecated Charts
3333

charts/clickhouse/README.md

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
2-
31
# clickhouse
42

53
![Version: 0.2.1](https://img.shields.io/badge/Version-0.2.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 24.3.12.76](https://img.shields.io/badge/AppVersion-24.3.12.76-informational?style=flat-square)
64

75
A Helm chart for creating a ClickHouse® Cluster with the Altinity Operator for ClickHouse
86

7+
## Features
8+
9+
- Single-node or multi-node ClickHouse clusters
10+
- Sharding and replication
11+
- ClickHouse Keeper integration
12+
- Persistent storage configuration
13+
- Init scripts
14+
915
## Requirements
1016

1117
| Repository | Name | Version |
@@ -29,15 +35,23 @@ helm install release-name altinity/clickhouse --namespace clickhouse --create-na
2935
# get latest repository versions
3036
helm repo update
3137

32-
# upgrade to a newer version using the release name (`ch`)
33-
helm upgrade ch kubernetes-blueprints-for-clickhouse/clickhouse --namespace clickhouse
38+
# upgrade to a newer version using the release name (`clickhouse`)
39+
helm upgrade clickhouse altinity/clickhouse --namespace clickhouse
3440
```
3541

3642
## Uninstalling the Chart
3743

3844
```sh
39-
# uninstall using the release name (`ch`)
40-
helm uninstall ch --namespace clickhouse
45+
# uninstall using the release name (`clickhouse`)
46+
helm uninstall clickhouse --namespace clickhouse
47+
```
48+
49+
**Note:** If you installed the Altinity Operator with this chart, your ClickHouse Installations will hang because the Operator will be deleted before their finalizers complete. To resolve this you must manually edit each `chi` resource and remove the finalizer.
50+
51+
PVCs created by this helm chart will not be automatically deleted and must be deleted manually. An easy way to do this is to delete the namespace:
52+
53+
```sh
54+
kubectl delete namespace clickhouse
4155
```
4256

4357
> This command removes all the Kubernetes components associated with the chart and deletes the release.
@@ -49,11 +63,50 @@ helm uninstall ch --namespace clickhouse
4963
kubectl get pods --namespace clickhouse
5064

5165
# pick any of your available pods and connect through the clickhouse-client
52-
kubectl exec -it chi-eks-dev-0-0-0 --namespace clickhouse -- clickhouse-client
66+
kubectl exec -it chi-clickhouse-0-0-0 --namespace clickhouse -- clickhouse-client
5367
```
5468

5569
> Use `kubectl port forward` to access your ClickHouse cluster from outside: `kubectl port-forward service clickhouse-eks 9000:9000 & clickhouse-client`
5670
71+
## Using Init Scripts with ConfigMap
72+
73+
The chart allows mounting a ConfigMap containing initialization scripts that will be executed during the ClickHouse container startup.
74+
75+
### How to use:
76+
77+
1. Create a ConfigMap containing your initialization scripts:
78+
79+
```bash
80+
kubectl create configmap my-init-scripts --from-file=01_create_database.sh --from-file=02_create_tables.sh
81+
```
82+
83+
2. Enable the initScripts feature in your Helm values:
84+
85+
```yaml
86+
clickhouse:
87+
initScripts:
88+
enabled: true
89+
configMapName: my-init-scripts
90+
alwaysRun: true # Set to true to always run scripts on container restart
91+
```
92+
93+
The scripts will be mounted at `/docker-entrypoint-initdb.d/` in the ClickHouse container and executed in alphabetical order during startup.
94+
95+
### Example Script Format
96+
97+
```bash
98+
#!/bin/bash
99+
set -e
100+
clickhouse client -n <<-EOSQL
101+
CREATE DATABASE IF NOT EXISTS my_database;
102+
CREATE TABLE IF NOT EXISTS my_database.my_table (
103+
id UInt64,
104+
data String
105+
) ENGINE = MergeTree()
106+
ORDER BY id;
107+
EOSQL
108+
```
109+
57110
## Values
58111

59112
| Key | Type | Default | Description |
@@ -62,9 +115,13 @@ kubectl exec -it chi-eks-dev-0-0-0 --namespace clickhouse -- clickhouse-client
62115
| clickhouse.defaultUser.allowExternalAccess | bool | `false` | Allow the default user to access ClickHouse from any IP. If set, will override `hostIP` to always be `0.0.0.0/0`. |
63116
| clickhouse.defaultUser.hostIP | string | `"127.0.0.1/32"` | |
64117
| clickhouse.defaultUser.password | string | `""` | |
118+
| clickhouse.extraConfig | string | `<clickhouse>\n</clickhouse>` | Miscellaneous config for ClickHouse in XML format |
65119
| clickhouse.image.pullPolicy | string | `"IfNotPresent"` | |
66120
| clickhouse.image.repository | string | `"altinity/clickhouse-server"` | |
67121
| clickhouse.image.tag | string | `"24.3.12.76.altinitystable"` | Override the image tag for a specific version |
122+
| clickhouse.initScripts.enabled | bool | `false` | Enable init scripts ConfigMap |
123+
| clickhouse.initScripts.configMapName | string | `""` | Name of ConfigMap with init scripts |
124+
| clickhouse.initScripts.alwaysRun | bool | `true` | Always run init scripts on startup |
68125
| clickhouse.keeper | object | `{"host":"","port":2181}` | Keeper connection settings for ClickHouse instances. |
69126
| clickhouse.keeper.host | string | `""` | Specify a keeper host. Should be left empty if `clickhouse-keeper.enabled` is `true`. Will override the defaults set from `clickhouse-keeper.enabled`. |
70127
| clickhouse.keeper.port | int | `2181` | Override the default keeper port |

charts/clickhouse/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,24 @@ Pod Template Base
8989
livenessProbe:
9090
{{- toYaml . | nindent 16 }}
9191
{{- end }}
92+
{{- if .Values.clickhouse.initScripts.enabled }}
93+
env:
94+
{{- if .Values.clickhouse.initScripts.alwaysRun }}
95+
- name: CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS
96+
value: "true"
97+
{{- end }}
98+
volumeMounts:
99+
- name: init-scripts-configmap
100+
mountPath: /docker-entrypoint-initdb.d
101+
{{- end }}
92102
resources:
93103
{{- toYaml .Values.clickhouse.resources | nindent 16 }}
104+
{{- if .Values.clickhouse.initScripts.enabled }}
105+
volumes:
106+
- name: init-scripts-configmap
107+
configMap:
108+
name: {{ .Values.clickhouse.initScripts.configMapName }}
109+
{{- end }}
94110
{{- with .Values.clickhouse.nodeSelector }}
95111
nodeSelector:
96112
{{- toYaml . | nindent 12 }}

charts/clickhouse/templates/chi.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ spec:
6565
- host: {{ $keeper_host }}
6666
port: {{ .Values.clickhouse.keeper.port }}
6767
{{- end }}
68-
{{- $extra_config := tpl (include "clickhouse.extra_config" . ) . -}}
69-
{{- if not (empty $extra_config) }}
68+
{{- $extraConfig := tpl (include "clickhouse.extraConfig" . ) . -}}
69+
{{- if not (empty $extraConfig) }}
7070
files:
7171
config.d/extra_config.xml: |
72-
{{- tpl $extra_config . | nindent 10 }}
72+
{{- tpl $extraConfig . | nindent 10 }}
7373
{{- end }}
7474

7575
{{ include "validate.clickhouse.keeper" . }}

charts/clickhouse/values.schema.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,27 @@
202202
},
203203
"extraConfig": {
204204
"type": "string",
205-
"description": "Additional XML config for ClickHouse."
205+
"description": "Miscellaneous config for ClickHouse in XML format."
206+
},
207+
"initScripts": {
208+
"type": "object",
209+
"description": "Configuration for init scripts via ConfigMap.",
210+
"properties": {
211+
"enabled": {
212+
"type": "boolean",
213+
"description": "Enable init scripts feature.",
214+
"default": false
215+
},
216+
"configMapName": {
217+
"type": "string",
218+
"description": "Name of an existing ConfigMap containing init scripts to be mounted at /docker-entrypoint-initdb.d/."
219+
},
220+
"alwaysRun": {
221+
"type": "boolean",
222+
"description": "Set to true to always run init scripts on container startup.",
223+
"default": true
224+
}
225+
}
206226
}
207227
}
208228
},

charts/clickhouse/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ clickhouse:
104104
<clickhouse>
105105
</clickhouse>
106106
107+
# -- Init scripts ConfigMap configuration
108+
initScripts:
109+
# -- Set to true to enable init scripts feature
110+
enabled: false
111+
# -- Name of an existing ConfigMap containing init scripts
112+
# The scripts will be mounted at /docker-entrypoint-initdb.d/
113+
configMapName: ""
114+
# -- Set to true to always run init scripts on container startup
115+
alwaysRun: true
116+
107117
# CHK parameters
108118
keeper:
109119
# -- Whether to enable Keeper.

0 commit comments

Comments
 (0)