一、基础环境
Servers: 10.9.9.68/69/70
集群: Kubernetes
docker镜像: http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/zookeeper-3.4.10.img
二、环境部署
2.1 构建镜像
Dockerfile 【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/Dockerfile】
start.sh【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/start.sh】
start.sh【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/status.sh】
FROM centos
COPY zookeeper-3.4.10 /opt/zookeeper-3.4.10
COPY start.sh /
COPY status.sh /
RUN mkdir /var/log/zookeeper
RUN yum -y install java nmap-ncat
RUN ln -s /opt/zookeeper-3.4.10 /opt/zookeeper
RUN useradd zookeeper && chown -R zookeeper. /opt/zookeeper-3.4.10 /opt/zookeeper /sta* /var/log/zookeeper
2.2 Servieless-ZK-HS
zookeeper-svc-hs.yaml【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/zookeeper-svc-hs.yaml】注:ZK 节点集群通信
apiVersion: v1
kind: Service
metadata:
name: zookeeper-hs
namespace: dolphin-dev
labels:
app: zookeeper
spec:
ports:
- port: 2888
name: server - port: 3888
name: leader-election
clusterIP: None
selector:
app: zookeeper
2.3 Servieless-ZK-CS
zookeeper-svc-cs.yaml【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/zookeeper-svc-cs.yaml】注:ZK 集群连接服务,kafka-->
apiVersion: v1
kind: Service
metadata:
name: zookeeper-cs
namespace: dolphin-dev
labels:
app: zookeeper
spec:
ports:
- port: 2181
name: client
clusterIP: None
selector:
app: zookeeper
2.4 PodDisruptionBudget
zookeeper-pdb.yaml【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/zookeeper-pdb.yaml】注:ZK 集群连接服务,kafka-->args
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: zookeeper-pdb
namespace: dolphin-dev
spec:
selector:
matchLabels:
app: zookeeper
maxUnavailable: 1
2.4 StatefulSet
zookeeper-sft.yaml【http://10.65.4.2:8111/packages/kafka-k8s/zookeeper/zookeeper-sft.yaml】
注:ZK 单点:【replicas: 1】/【args:--servers=1】
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: zookeeper
namespace: dolphin-dev
spec:
serviceName: zookeeper-hs
replicas: 2
updateStrategy:
type: RollingUpdate
podManagementPolicy: Parallel
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: zookeeper
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- zookeeper
topologyKey: "kubernetes.io/hostname"
containers:
- name: kubernetes-zookeeper
imagePullPolicy: IfNotPresent
image: "10.65.4.2:5000/zookeeper_3.4.10:20190122"
resources:
requests:
memory: "1Gi"
cpu: "0.5"
ports:
- containerPort: 2181
name: client
- containerPort: 2888
name: server
- containerPort: 3888
name: leader-election
command:
- sh
- -c
- "/start.sh
--servers=2
--data_dir=/var/lib/zookeeper/data
--data_log_dir=/var/lib/zookeeper/data/log
--conf_dir=/opt/zookeeper/conf
--client_port=2181
--election_port=3888
--server_port=2888
--tick_time=2000
--init_limit=10
--sync_limit=5
--heap=512M
--max_client_cnxns=60
--snap_retain_count=3
--purge_interval=12
--max_session_timeout=40000
--min_session_timeout=4000
--log_level=INFO"
readinessProbe:
exec:
command:
- sh
- -c
- "/status.sh 2181"
initialDelaySeconds: 10
timeoutSeconds: 5
livenessProbe:
exec:
command:
- sh
- -c
- "/status.sh 2181"
initialDelaySeconds: 10
timeoutSeconds: 5
volumeMounts:
- name: zookeeper
mountPath: /var/lib/zookeeper
securityContext:
runAsUser: 1000
fsGroup: 1000
volumeClaimTemplates:
- metadata:
name: zookeeper
namespace: dolphin-dev
annotations:
volume.beta.kubernetes.io/storage-class: "nfs-recycle-local"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于