Use templates
Templates let you declare pod shape, storage and Service shape once and reference them from instances. They come in two forms:
- Inline templates, under
spec.templatesof aClickHouseInstallation. - Shared templates, in a
ClickHouseInstallationTemplate(CHIT) that instances pull in withspec.useTemplates.
The mechanism is the same in both cases; a CHIT is only a way to keep one definition in one place.
TOC
Template kindsInline pod and volume templatesShared templates with a CHITThe log container escape hatchChanging a templateTemplate kinds
Selectors are set under spec.defaults.templates to apply to the whole instance, and can be overridden at cluster, shard or replica level.
volumeClaimTemplate (singular) also appears in the schema and is deprecated. Use dataVolumeClaimTemplate and logVolumeClaimTemplate.
Inline pod and volume templates
Points that matter:
- The server container must be named
clickhouse. A differently named container is an extra sidecar, not the server, and your resources and security context will not apply to the server. - Omit
imagein the pod template. With no image set, the operator uses the operand image it was configured with at install time, which is the version the release was validated against. Pinning your own image opts you out of that. reclaimPolicy: Retainon a volume claim template keeps the claim when the StatefulSet is deleted. The default isDelete.podDistributionexpresses spreading rules — for exampleShardAntiAffinitykeeps replicas of different shards off the same node — without hand-writing affinity terms.
Shared templates with a CHIT
Define the template once:
Reference it from an instance:
useTemplates entries take a name, an optional namespace, and an optional useType which may be empty or merge. Templates are applied in the order listed, and anything set directly on the instance wins over what a template provides. Check the result on the live object — the reconciled spec after defaulting and template merging is published in the instance's status, and that is the fastest way to confirm a template was picked up.
Templates can also be applied automatically to every instance, by marking the CHIT with spec.templating.policy: auto. Use this sparingly: it changes instances that do not mention the template at all.
Template files loaded from the operator's own template directory must end in .yaml or .json, and are read in sorted order. Files with any other extension are ignored.
The log container escape hatch
When you set logVolumeClaimTemplate, the operator appends a container named clickhouse-log to the pod. Its generated security context sets a user id and nothing more, which a namespace enforcing the Pod Security Admission restricted profile will reject.
Declare that container yourself in the pod template and the operator will reuse yours rather than generating one. It only fills in the image if you left it unset:
The container name must match exactly, or you get both your sidecar and the operator's generated one.
Changing a template
Editing a template referenced by running instances triggers a rolling reconcile of those instances. Hosts are updated one at a time: the operator excludes a host from the cluster, updates its configuration and StatefulSet, waits for it to come back, then includes it again. A change that cannot succeed — an image that does not exist, a memory limit too small to start the server — will therefore stall on the first host rather than breaking every host at once.
ClickHouse is a registered trademark of ClickHouse, Inc. https://clickhouse.com
Alauda is an independent vendor. This product is not affiliated with, endorsed by, or sponsored by ClickHouse, Inc. All trademarks are the property of their respective owners and are used here for identification purposes only.