zookeeper
by apecloud
Apache ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
About this chart
Zookeeper
Apache Zookeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
Features In KubeBlocks
Lifecycle Management
| Horizontalscaling | Vertical scaling | Expandvolume | Restart | Stop/Start | Configure | Expose | Switchover |
|---|---|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes | Yes | No |
Backup and Restore
| Feature | Method | Description |
|---|---|---|
| Full Backup | zoocreeper | uses zoocreeper tool to create a backup |
Versions
| Versions |
|---|
| 3.6.4,3.7.2,3.8.4,3.8.6,3.9.2,3.9.4,3.9.5 |
Prerequisites
-
Kubernetes cluster >= v1.21
-
kubectlinstalled, refer to K8s Install Tools -
Helm, refer to Installing Helm
-
KubeBlocks installed and running, refer to Install Kubeblocks
-
Zookeeper Addon Enabled, refer to Install Addons
-
Create K8s Namespace
demo, to keep resources created in this tutorial isolated:kubectl create ns demo
Examples
Create
Create a zookeeper cluster with three replicas, one leader replica and two follower replicas:
# cat examples/zookeeper/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: zookeeper-cluster
namespace: demo
spec:
# Specifies the behavior when a Cluster is deleted.
# Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9)
# - `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
componentSpecs:
- name: zookeeper
componentDef: zookeeper
# ServiceVersion specifies the version of the Service expected to be
# provisioned by this Component.
# Valid options are: [3.6.4,3.7.2,3.8.4,3.8.6,3.9.2,3.9.4,3.9.5]
serviceVersion: "3.9.2"
# Update `replicas` to your need.
replicas: 3
# Specifies the resources required by the Component.
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
# Specifies a list of PersistentVolumeClaim templates that define the storage
# requirements for the Component.
volumeClaimTemplates:
# Refers to the name of a volumeMount defined in
# `componentDefinition.spec.runtime.containers[*].volumeMounts
- name: data
spec:
# The name of the StorageClass required by the claim.
# If not specified, the StorageClass annotated with
# `storageclass.kubernetes.io/is-default-class=true` will be used by default
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# Set the storage size as needed
storage: 20Gi
# Refers to the name of a volumeMount defined in
# `componentDefinition.spec.runtime.containers[*].volumeMounts
- name: snapshot-log
spec:
# The name of the StorageClass required by the claim.
# If not specified, the StorageClass annotated with
# `storageclass.kubernetes.io/is-default-class=true` will be used by default
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
kubectl apply -f examples/zookeeper/cluster.yaml
Horizontal scaling
The Zookeeper component supports 1 to 6 replicas. Pods whose ordinal is 0,
1, or 2 are rendered and joined as voting participant members; ordinals
3 and above are rendered and joined as non-voting observer members.
[!NOTE] For clusters created with older chart revisions that marked
zookeeper-dynamic-configas externally managed, verify the live Component no longer carries a Component-level external config override before relying on this chart's generated dynamic config during horizontal scaling. If such an override remains, remove that stale override or recreate the Component through the upgraded chart before treating horizontal scaling as validated.
Scale-out
Horizontal scaling out cluster by adding ONE more OBSERVER replica:
# cat examples/zookeeper/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zk-scale-out
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: zookeeper-cluster
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
- componentName: zookeeper
# Specifies the replica changes for scaling out components
scaleOut:
# Specifies the replica changes for the component.
# add two more replicas: 3 -> 5 (always keep an odd number for quorum)
replicaChanges: 2
kubectl apply -f examples/zookeeper/scale-out.yaml
And you can check the progress of the scaling operation with following command:
kubectl describe -n demo ops zk-scale-out
[!WARNING] As defined, Zookeeper Cluster will be restarted on horizontal scaling. To make sure all config are loaded properly.
After scaling, cluster server list in Zookeeper configuration file zoo.cfg will be updated :
# cluster server list
server.0 = zookeeper-cluster-zookeeper-0.zookeeper-cluster-zookeeper-headless.demo.svc.cluster.local:2888:3888:participant
server.1
= zookeeper-cluster-zookeeper-1.zookeeper-cluster-zookeeper-headless.demo.svc.cluster.local:2888:3888:participant
server.2
= zookeeper-cluster-zookeeper-2.zookeeper-cluster-zookeeper-headless.demo.svc.cluster.local:2888:3888:participant
server.3
= zookeeper-cluster-zookeeper-3.zookeeper-cluster-zookeeper-headless.demo.svc.cluster.local:2888:3888:observer
Information for server.3 is added on scaling out.
Scale-in
Horizontal scaling in cluster by deleting ONE replica:
# cat examples/zookeeper/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zk-scale-in
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: zookeeper-cluster
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
- componentName: zookeeper
# Specifies the replica changes for scaling out components
scaleIn:
# Specifies the replica changes for the component.
# remove two replicas: 5 -> 3 (always keep an odd number for quorum)
replicaChanges: 2
kubectl apply -f examples/zookeeper/scale-in.yaml
Scale-in/out using Cluster API
Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: zookeeper
componentDef: zookeeper
replicas: 3 # Update `replicas` to 1 for scaling in, and to 3 for scaling out
Vertical scaling
Vertical scaling up or down specified components requests and limits cpu or memory resource in the cluster
# cat examples/zookeeper/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zookeeper-verticalscaling
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: zookeeper-cluster
type: VerticalScaling
# Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
verticalScaling:
- componentName: zookeeper
# VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
requests:
cpu: '1'
memory: 1Gi
limits:
cpu: '1'
memory: 1Gi
kubectl apply -f examples/zookeeper/verticalscale.yaml
Scale-up/down using Cluster API
Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: zookeeper
componentDef: zookeeper
replicas: 3
resources:
requests:
cpu: "1" # Update the resources to your need.
memory: "2Gi" # Update the resources to your need.
limits:
cpu: "2" # Update the resources to your need.
memory: "4Gi" # Update the resources to your need.
Expand volume
[!NOTE] Make sure the storage class you use supports volume expansion.
Check the storage class with following command:
kubectl get storageclass
If the ALLOWVOLUMEEXPANSION column is true, the storage class supports volume expansion.
To increase size of volume storage with the specified components in the cluster
Increase size of volume storage with the specified components in the cluster
# cat examples/zookeeper/volumeexpand.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zookeeper-volumeexpansion
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: zookeeper-cluster
type: VolumeExpansion
# Lists VolumeExpansion objects, each specifying a component and its corresponding volumeClaimTemplates that requires storage expansion.
volumeExpansion:
# Specifies the name of the Component.
- componentName: zookeeper
# volumeClaimTemplates specifies the storage size and volumeClaimTemplate name.
volumeClaimTemplates:
- name: data
storage: 30Gi
kubectl apply -f examples/zookeeper/volumeexpand.yaml
Volume expansion using Cluster API
Alternatively, you may update the spec.componentSpecs.volumeClaimTemplates.spec.resources.requests.storage field to the desired size.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: zookeeper
componentDef: zookeeper
replicas: 3
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# specify new size, and make sure it is larger than the current size
storage: 30Gi
volumeClaimTemplates:
- name: snapshot-log
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# specify new size, and make sure it is larger than the current size
storage: 20Gi
Restart
Restart the specified components in the cluster
# cat examples/zookeeper/restart.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zookeeper-restart
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: zookeeper-cluster
type: Restart
# Lists Components to be restarted. ComponentOps specifies the Component to be operated on.
restart:
# Specifies the name of the Component.
- componentName: zookeeper
kubectl apply -f examples/zookeeper/restart.yaml
Stop
Stop the cluster will release all the pods of the cluster, but the storage will be retained. It is useful when you want to save the cost of the cluster.
# cat examples/zookeeper/stop.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zookeeper-stop
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: zookeeper-cluster
type: Stop
kubectl apply -f examples/zookeeper/stop.yaml
Stop using Cluster API
Alternatively, you may stop the cluster by setting the spec.componentSpecs.stop field to true.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: zookeeper
componentDef: zookeeper
stop: true # set stop `true` to stop the component
replicas: 3
Start
Start the stopped cluster
# cat examples/zookeeper/start.yaml
apiVersion: operations.kubeblocks.
Deploy zookeeper with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has zookeeper 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartzookeeper is pinned at v1.2.0-alpha.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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