是的,Kubernetes(K8s)上部署的Zookeeper可以实现高可用性。下面是在Kubernetes上实现高可用Zookeeper集群的关键点和步骤:
zookeeper-deployment.yaml
文件,内容类似:apiVersion: apps/v1
kind: Deployment
metadata:
name: zookeepers
spec:
replicas: 3
selector:
matchLabels:
app: zookeeper
template:
metadata:
labels:
app: zookeeper
spec:
containers:
- name: zookeeper
image: wurstmeister/zookeeper:3.9.2
ports:
- containerPort: 2181
接着,为持久化数据创建一个zookeeper-statefulset.yaml
:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: zookeepers
spec:
serviceName: zookeeper
replicas: 3
selector:
matchLabels:
app: zookeeper
template:
metadata:
labels:
app: zookeeper
spec:
containers:
- name: zookeeper
image: wurstmeister/zookeeper:3.9.2
envFrom:
- secretRef:
name: zookeeper-secret
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
emptyDir: {}
---
apiVersion: v1
kind: Secret
metadata:
name: zookeeper-secret
type: Secret
data:
config: "<base64-encoded-zk-config>"
这里假设你已经有了一个包含ZooKeeper配置的secret(config
),需要替换 <base64-encoded-zk-config>
。
zookeeper-secret
的密钥中。kubectl apply -f zookeeper-deployment.yaml
kubectl apply -f zookeeper-statefulset.yaml
kubectl get pods -l app=zookeeper
kubectl exec -it <pod-name> -- /usr/bin/zkCli.sh -server localhost:2181
通过上述步骤和配置,可以在Kubernetes上实现一个高可用的Zookeeper集群,确保服务的持续可用性。