Instana

Instana

The community for performance and observability professionals to learn, to share ideas, and to connect with others.

 View Only

Migrate Zookeeper to Clickhouse-Keeper on Instana Self-Hosted Custom Edition

By Oleg Samoylov posted 09/16/26 07:00 PM

  
In previous Instana versions it was recommended to use zookeeper for clickhouse. Today, the preferable way is to use clickhouse-keeper which is lighter, faster and represents a solid solution under the single product. This article explains how to switch from zookeeper to clickhouse-keeper without loosing data. The article sources procedure from clickhouse documentation and IBM Instana blogs mentioned in the end of the page. The procedure has been tested on Power OCP.
In the procedure we assume that:
- clickhouse operator is already installed;
- clickhouse namespace is instana-clickhouse;
- zookeeper namespace is instana-clickhouse while operator is in instana-zookeeper;
- image registry secret is instana-registry;
if those values differ from assumed please change them before applying every command.

In short the procedure is:
- spin up clickhouse-keeper
- copy snapshots from zookeeper to clickhouse-keeper
- reconfigure Instana backend to use clickhouse-keeper
- verify clickhouse with clickhouse keeper
- remove zookeeper
While the procedure seemed to be working without service interruption we recommend to schedule maintenance window.

Step 1 - Install clickhouse-keeper

First, install clickhouse-keeper. We will use one node cluster for the sake of simplicity and will schedule two more nodes in the end of the procedure.
For OCP we need to configure security context constraint and add clickhousekeeper or ensure it is in SCC:
cat << EOF > clickhouse-scc.yaml
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
metadata:
  name: clickhouse-scc
runAsUser:
  type: MustRunAs
  uid: 1001
seLinuxContext:
  type: RunAsAny
fsGroup:
  type: RunAsAny
allowHostDirVolumePlugin: false
allowHostNetwork: true
allowHostPorts: true
allowPrivilegedContainer: false
allowHostIPC: true
allowHostPID: true
readOnlyRootFilesystem: false
users:
  - system:serviceaccount:instana-clickhouse:clickhouse-operator
  - system:serviceaccount:instana-clickhouse:clickhouse-operator-ibm-clickhouse-operator
  - system:serviceaccount:instana-clickhouse:clickhouse
  - system:serviceaccount:instana-clickhouse:clickhousekeeper
EOF
oc apply -f clickhouse-scc.yaml

And create the service account:
oc create serviceaccount clickhousekeeper -n instana-clickhouse

Now, provision one node cluster clickhouse-keeper, use documentation for details. Before applying:
- set the same images which used by clickhouse pod;
- set 1 replica for the time of migration;
- if it is OCP comment out securityContext as below, otherwise uncomment the section;
- update your storageClassName (we were using nfs-client);
cat << EOF > clickhouse-keeper.yaml
apiVersion: "clickhouse-keeper.altinity.com/v1"
kind: "ClickHouseKeeperInstallation"
metadata:
  name: clickhouse-keeper
  namespace: instana-clickhouse
spec:
  configuration:
    clusters:
      - name: "local"
        layout:
          replicasCount: 1
    settings:
      logger/level: "information"
      logger/console: "true"
      listen_host: "0.0.0.0"
      keeper_server/snapshot_storage_path: /var/lib/clickhouse-keeper/coordination/snapshots/store
      keeper_server/log_storage_path: /var/lib/clickhouse-keeper/coordination/logs/store
      keeper_server/storage_path: /var/lib/clickhouse-keeper/
      keeper_server/tcp_port: "2181"
      keeper_server/four_letter_word_white_list: "*"
      keeper_server/coordination_settings/raft_logs_level: "information"
      keeper_server/raft_configuration/server/port: "9444"
      prometheus/endpoint: "/metrics"
      prometheus/port: "7000"
      prometheus/metrics: "true"
      prometheus/events: "true"
      prometheus/asynchronous_metrics: "true"
      prometheus/status_info: "false"
      zookeeper/node/host: "localhost"
      zookeeper/node/port: "9181"
  templates:
    podTemplates:
      - name: clickhouse-keeper
        spec:
          # Add the following Affinity snippet to schedule each pod on a different node. 
          #affinity:
          #  podAntiAffinity:
          #    requiredDuringSchedulingIgnoredDuringExecution:
          #      - labelSelector:
          #          matchLabels:
          #            app: clickhouse-keeper
          #        topologyKey: "kubernetes.io/hostname"
          serviceAccountName: clickhousekeeper
          containers:
            - name: clickhouse-keeper
              imagePullPolicy: IfNotPresent
              image: artifact-public.instana.io/clickhouse-openssl:25.8.13.73-10-lts-ibm
              command:
                - clickhouse-keeper
                - --config-file=/etc/clickhouse-keeper/keeper_config.xml
              resources:
                requests:
                  memory: "1Gi"
          imagePullSecrets:
            - name: instana-registry
              ### for Kubernetes cluster (for OCP use SCC)
              #  securityContext:
              #    fsGroup: 0
              #    runAsGroup: 0
              #    runAsUser: 1001
              ########
          initContainers:
            - name: server-id-injector
              imagePullPolicy: IfNotPresent
              image: artifact-public.instana.io/clickhouse-openssl:25.8.13.73-10-lts-ibm
    volumeClaimTemplates:
      - name: log-storage-path
        spec:
          storageClassName: nfs-client
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 50Gi
      - name: snapshot-storage-path
        spec:
          storageClassName: nfs-client
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 50Gi
    serviceTemplates: []
EOF
oc apply -f clickhouse-keeper.yaml

as a result you should see a clickhouse-keeper pod up and ready:
oc get po clickhouse-keeper-0 -n instana-clickhouse
NAME                           READY   STATUS  RESTARTS AGE
clickhouse-keeper-0 1/1        Running 0                12s

Step 2 - Stop merges and scaledown zookeeper

At the step we need to stop load on clickhouse. Ideally would be best to stop Instana to avoid buffers overflow during migration:
oc -n instana-core patch core instana-core --type=merge -p '{"spec":{"operationMode": "maintenance"}}'

and make clickhouse to stop merges to prevent snapshots updates in zookeeper, for that set username and password from clickhouse manifest:
CHIUSER=clickhouse-user
CHIPASS=<CLICKHOUSE_PASSWORD>
oc exec chi-instana-local-0-0-0 -n instana-clickhouse -- clickhouse-client --user $CHIUSER --password $CHIPASS -q "SYSTEM STOP MERGES;"

Now let's scale down zookeeper cluster to 1 node to ensure we're dealing with leader:
## get name of zookeeper cluster
oc get zk -n instana-clickhouse

## scale down zookeeper to 1 node
oc -n instana-clickhouse patch zk instana-zookeeper --type=merge -p '{"spec":{"replicas": 1}}'

Clickhouse documentation recommends to restart leader to force ZooKeeper to write a consistent snapshot to disk before conversion.
oc delete po/instana-zookeeper-0 -n instana-clickhouse

Scale down zookeeper operator to 0:
oc scale deploy/zookeeper-operator -n instana-zookeeper --replicas=0



Step 3 - Copy clickhouse-keeper-converter to zookeeper pod

By default zookeeper pod doesn't have clickhouse-keeper-converter so we will copy it from clickhouse-keeper pod:
oc exec clickhouse-keeper-0 -c clickhouse-keeper -n instana-clickhouse -- base64 /usr/bin/clickhouse-keeper-converter > clickhouse-keeper-converter.base64

base64 -d clickhouse-keeper-converter.base64 > clickhouse-keeper-converter

oc get pods

oc cp clickhouse-keeper-converter instana-clickhouse/instana-zookeeper-0:/tmp

Step 4 - Run clickhouse-keeper-convertor and export snapshot

The following commands should be executed from Zookeeper leader pod:
oc exec instana-zookeeper-0 -n instana-clickhouse -- chmod 755 /tmp/clickhouse-keeper-converter

oc exec instana-zookeeper-0 -n instana-clickhouse -- mkdir -p /tmp/keeper-snapshots

oc exec instana-zookeeper-0 -n instana-clickhouse -- /tmp/clickhouse-keeper-converter \
--zookeeper-logs-dir /data/version-2 \
--zookeeper-snapshots-dir /data/version-2 \
--output-dir /tmp/keeper-snapshots

We expect the following outout:
Totally have 5 snapshots, will use latest
Deserializing storage snapshot /data/version-2/snapshot.400000006
Magic deserialized, looks OK
Sessions and timeouts deserialized
ACLs deserialized
Deserializing data from snapshot
Deserialized nodes from snapshot: 1000
Deserialized nodes from snapshot: 2000
Deserialized nodes from snapshot: 3000
Finished, snapshot ZXID 17179869190
Totally have 4 logs
Deserializing log /data/version-2/log.400000001
Header looks OK
Finished /data/version-2/log.400000001 deserialization, totally read 6 records
Snapshot serialized to path:"/tmp/keeper-snapshots/snapshot_17179869190.bin.zstd"

write down the snapshot file name on the last line of the output in our example it is /tmp/keeper-snapshots/snapshot_17179869190.bin.zstd.

Step 5 - Copy the snapshot file to clickhouse keeper pod

Download the snapshot from zookeeper pod to bastion node, ensure you use your file names:
oc cp instana-clickhouse/instana-zookeeper-0:/tmp/keeper-snapshots/snapshot_17179869190.bin.zstd snapshot_17179869190.bin.zstd

We do not need zookeeper pod anymore, let's scale it down, we previously scaled down zookeeper operator and now will scale down statefulset:
oc scale sts/instana-zookeeper -n instana-clickhouse --replicas=0
We still have PVC/PV and will be able to scale it up just in case.
Since clickhouse image doesn't have `tar` OCP will complain during copy of the file to the pod. As a workaround we will encode the file to only use text characters using base64 and upload it from output to the target pod and unencode it
## Encode the file
base64 snapshot_17179869190.bin.zstd > snapshot_17179869190.bin.zstd.base64

## Copy the file to pod
oc exec -i clickhouse-keeper-0 -- sh -c 'cat > /var/lib/clickhouse-keeper/coordination/snapshots/store/snapshot_17179869190.bin.zstd.base64' < snapshot_17179869190.bin.zstd.base64

## Decode the snapshot file
oc exec -i clickhouse-keeper-0 -- sh -c 'base64 -d /var/lib/clickhouse-keeper/coordination/snapshots/store/snapshot_17179869190.bin.zstd.base64 > /var/lib/clickhouse-keeper/coordination/snapshots/store/snapshot_17179869190.bin.zstd'

## Check current snapshots and delete all old snapshots. The folder should only contain one file that we copied
oc exec -i clickhouse-keeper-0 -- ls -la /var/lib/clickhouse-keeper/coordination/snapshots/store

## Delete all files except the one snapshot we copied
oc exec -i clickhouse-keeper-0 -- rm -f /var/lib/clickhouse-keeper/coordination/snapshots/store/snapshot_17179869190.bin.zstd.base64

the output should only include one snapshot file:
# oc exec -i clickhouse-keeper-0 -- ls -la /var/lib/clickhouse-keeper/coordination/snapshots/store
Defaulted container "clickhouse-keeper" out of: clickhouse-keeper, server-id-injector (init)
total 160
drwxr-x---. 2 1000780000 root 107 Sep 16 21:43 .
drwxrwxrwx. 3 root root 19 Sep 16 09:33 ..
-rw-r--r--. 1 1000780000 root 77288 Sep 16 21:38 snapshot_17179869190.bin.zstd

Step 6 - Restart clickhouse-keeper pod and reconfigure clickhouse

We need to restart the clickhouse-keeper pod so it used the new snapshot
oc delete po/clickhouse-keeper-0 -n instana-clickhouse

Edit clickhouse manifest:
oc edit chi -n instana-clickhouse
and change zookeeper service to clickhouse-keeper service `clickhouse-keeper-headless.instana-clickhouse` as host in `configuration` section this way:
apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"
spec:
  configuration:
    zookeeper:
      nodes:
        - host: clickhouse-keeper-headless.instana-clickhouse
this will trigger nodes of clickhouse to restart one after another.

Step 7 - Enable merges start Instana and verify

Once all clickhouse pods are up and running let's check system.zookeeper table by the following command (if you are in the same session, then you may still have the username and password defined):
CHIUSER=clickhouse-user
CHIPASS=<CLICKHOUSE_PASSWORD>
oc exec chi-instana-local-0-0-0 -n instana-clickhouse -- clickhouse-client --user $CHIUSER --password $CHIPASS -q "SYSTEM START MERGES;"
Scale up clickhouse keeper to 3 replicas:
oc -n instana-clickhouse patch chk clickhouse-keeper -n instana-clickhouse --type=merge -p '{"spec":{"configuration": {"clusters": [{"name": "local", "layout": {"replicasCount": 3}}]}}}'
Start Instana backend:
oc -n instana-core patch core instana-core --type=merge -p '{"spec":{"operationMode": "normal"}}'

And verify if new calls are coming to instana and visible in UI. Look after it for few minutes, check logs of Clickhouse and clickhouse-keeper pods for any errors

Step 8 - Uninstall zookeeper

## Get name of zookeeper cluster
oc get zk -n instana-clickhouse

## Delete zookeeper cluster
oc delete zk instana-zookeeper -n instana-clickhouse

## Delete PVC
oc get pvc -n instana-clickhouse
oc delete pvc data-instana-zookeeper-0 -n instana-clickhouse

## Uninstall zookeeper operator
helm list -n instana-zookeeper
helm uninstall zookeeper-operator -n instana-zookeeper
oc delete ns instana-zookeeper

---
Relevant documentation:


#Administration
#Documentation
#Migration
#Self-Hosted
#Database

0 comments
27 views

Permalink