ZooKeeper 高可用集群部署
配置说明
- 副本数: 3(生产环境高可用)
- 持久化: 数据目录 10Gi + 日志目录 10Gi
- 反亲和性: hard(Pod 分散在不同节点)
- 资源: 500m CPU / 1Gi Memory(可根据实际调整)
部署
# 执行部署脚本
./run.sh
连接地址
dyck-zk-cluster.tools.svc.cluster.local:2181
测试连接
kubectl run zk-client --rm -it --image d.ajunyunwei.xyz/bitnami/zookeeper:3.9.3-debian-12-r21 --namespace tools -- bash
zkCli.sh -server dyck-zk-cluster-zookeeper.tools.svc.cluster.local:2181
常用命令
# 查看状态
kubectl get pods,svc,pvc -n tools -l app.kubernetes.io/name=zookeeper
# 查看日志
kubectl logs -n tools -l app.kubernetes.io/name=zookeeper -f
# 卸载
helm uninstall dyck-zk-cluster -n tools
values.yaml
# ============================================
# ZooKeeper 生产环境高可用配置
# K8s 版本: 1.28
# ============================================
# 全局配置
global:
imageRegistry: "reg-hub.gzeport.com"
imagePullSecrets:
- gzeport
storageClass: "k8s-data"
# 允许使用自定义镜像仓库
security:
allowInsecureImages: true
# 副本数:生产环境建议 3 或 5 个节点(奇数)
replicaCount: 3
# 镜像配置
image:
repository: library/bitnami/zookeeper
tag: 3.9.3-debian-12-r8
pullPolicy: IfNotPresent
# 时区配置
extraEnvVars:
- name: TZ
value: Asia/Shanghai
# ============================================
# 认证配置(生产环境强烈建议启用)
# ============================================
auth:
client:
enabled: false # 如需启用客户端认证,设置为 true 并配置用户密码
# clientUser: "zkclient"
# clientPassword: "your-secure-password"
# serverUsers: "admin,user1"
# serverPasswords: "admin-pass,user1-pass"
quorum:
enabled: false # 如需启用服务器间认证,设置为 true
# ============================================
# ZooKeeper 核心参数优化
# ============================================
# 心跳时间(毫秒)
tickTime: 2000
# 初始化连接超时(tickTime 的倍数)
initLimit: 10
# 同步超时(tickTime 的倍数)
syncLimit: 5
# 最大客户端连接数
maxClientCnxns: 60
# 最大会话超时(毫秒)
maxSessionTimeout: 40000
# JVM 堆内存大小(MB)
heapSize: 1024
# 允许的四字命令
fourlwCommandsWhitelist: srvr, mntr, ruok, stat, conf, cons, wchs, wchp
# 自动清理配置
autopurge:
snapRetainCount: 10 # 保留最近 10 个快照
purgeInterval: 1 # 每小时清理一次
# 日志级别
logLevel: INFO
# ============================================
# 持久化存储配置
# ============================================
persistence:
enabled: true
storageClass: "k8s-data"
accessModes:
- ReadWriteOnce
size: 10Gi # 数据目录大小
# 数据日志目录配置(独立存储提升性能)
dataLogDir:
size: 10Gi # 日志目录大小,建议与数据目录相同或更大
# ============================================
# 资源配置(根据实际负载调整)
# ============================================
resources:
requests:
cpu: 250m
memory: 512Mi
limits:
cpu: 500m
memory: 1.2Gi
# ============================================
# 高可用配置
# ============================================
# Pod 反亲和性:hard 模式确保 Pod 分散在不同节点
podAntiAffinityPreset: hard
# Pod 管理策略:Parallel 加速启动
podManagementPolicy: Parallel
# Pod 中断预算:确保至少 2 个节点可用
pdb:
create: true
minAvailable: 2 # 3 节点集群至少保持 2 个可用
# ============================================
# 健康检查配置
# ============================================
livenessProbe:
enabled: true
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
enabled: true
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
startupProbe:
enabled: true
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 30 # 启动最多等待 300 秒
# ============================================
# 服务配置
# ============================================
service:
type: ClusterIP
ports:
client: 2181
tls: 3181
follower: 2888
election: 3888
sessionAffinity: ClientIP # 客户端会话保持
# ============================================
# 监控配置
# ============================================
metrics:
enabled: false # 如需 Prometheus 监控,设置为 true
run.sh
#!/bin/bash
helm search repo bitnami/zookeeper -l
helm search repo bitnami/zookeeper --version 13.8.7
# 0. 创建 tools 命名空间
echo "0. 创建 tools 命名空间..."
#kubectl create namespace tools --dry-run=client -o yaml | kubectl apply -f -
# 1. 拉取 Chart(如果不存在)
if [ ! -f "../zookeeper-13.8.7.tgz" ]; then
echo "1. 拉取 Helm Chart..."
helm pull oci://d.ajunyunwei.xyz/bitnamicharts/zookeeper --version 13.8.7
mv zookeeper-13.8.7.tgz ../
fi
# 2. 部署 ZooKeeper
echo "2. 部署 ZooKeeper Cluster..."
helm install dyck-zk-cluster ../zookeeper-13.8.7.tgz -n tools -f values.yaml
helm upgrade dyck-zk-cluster ../zookeeper-13.8.7.tgz -n tools -f values.yaml
zkServer.sh status
zkCli.sh -server dyck-zk-cluster-zookeeper.tools.svc.cluster.local:2181