yaml
复制代码
# https://github.com/bitnami/containers/blob/main/bitnami
# 1. zk-cluster的无头svc
---
kind: Service
apiVersion: v1
metadata:
name: zk-cluster-headless
namespace: hgjg-common
labels:
app: zk-cluster-headless
annotations:
kubesphere.io/creator: admin
spec:
ports:
- name: client
protocol: TCP
port: 2181
targetPort: 2181
- name: server
protocol: TCP
port: 2888
targetPort: 2888
- name: leader-election
protocol: TCP
port: 3888
targetPort: 3888
- name: adminserver
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: zk-cluster
clusterIP: 10.233.13.70
clusterIPs:
- 10.233.13.70
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
# 2. zk的StatefulSet
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: zk-cluster
namespace: hgjg-common
labels:
app: zk-cluster
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{"kubesphere.io/creator":"admin","kubesphere.io/description":"zookeeper集群"},"labels":{"app":"zk-cluster"},"name":"zk-cluster","namespace":"hgjg-common"},"spec":{"persistentVolumeClaimRetentionPolicy":{"whenDeleted":"Retain","whenScaled":"Retain"},"podManagementPolicy":"OrderedReady","replicas":3,"revisionHistoryLimit":10,"selector":{"matchLabels":{"app":"zk-cluster"}},"serviceName":"zk-cluster-headless","template":{"metadata":{"annotations":{"cni.projectcalico.org/ipv4pools":"[\"default-ipv4-ippool\"]","kubesphere.io/creator":"admin","kubesphere.io/imagepullsecrets":"{\"container-o7sjfa\":\"register-addr\"}","kubesphere.io/restartedAt":"2025-01-13T05:11:56.755Z","logging.kubesphere.io/logsidecar-config":"{}"},"creationTimestamp":null,"labels":{"app":"zk-cluster"}},"spec":{"affinity":{"podAntiAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"podAffinityTerm":{"labelSelector":{"matchExpressions":[{"key":"app","operator":"In","values":["zk-cluster"]}]},"topologyKey":"kubernetes.io/hostname"},"weight":100}]}},"containers":[{"command":["sh","-c","export
ZOO_SERVER_ID=$((${HOSTNAME##*-}+1))\nexport
ZOO_SERVERS='zk-cluster-sts-0.zk-cluster-headless:2888:3888,zk-cluster-sts-1.zk-cluster-headless:2888:3888,zk-cluster-sts-2.zk-cluster-headless:2888:3888'\nexec
/opt/bitnami/scripts/zookeeper/entrypoint.sh
/opt/bitnami/scripts/zookeeper/run.sh\n"],"env":[{"name":"TZ","value":"Asia/Shanghai"},{"name":"ALLOW_ANONYMOUS_LOGIN","value":"yes"},{"name":"JVMFLAGS","value":"-Xmx1g"}],"image":"registry.flow.cn/library/bitnami_zookeeper:3.8.4","imagePullPolicy":"Always","livenessProbe":{"failureThreshold":3,"httpGet":{"path":"/commands/ruok","port":"adminserver","scheme":"HTTP"},"initialDelaySeconds":10,"periodSeconds":5,"successThreshold":1,"timeoutSeconds":1},"name":"container-o7sjfa","ports":[{"containerPort":2181,"name":"client","protocol":"TCP"},{"containerPort":2888,"name":"server","protocol":"TCP"},{"containerPort":3888,"name":"leader-election","protocol":"TCP"},{"containerPort":8080,"name":"adminserver","protocol":"TCP"}],"readinessProbe":{"failureThreshold":3,"httpGet":{"path":"/commands/ruok","port":"adminserver","scheme":"HTTP"},"initialDelaySeconds":10,"periodSeconds":5,"successThreshold":1,"timeoutSeconds":1},"resources":{"limits":{"cpu":"1","memory":"1536Mi"},"requests":{"cpu":"500m","memory":"512Mi"}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","volumeMounts":[{"mountPath":"/bitnami/zookeeper","name":"zk-cluster-pvc"}]}],"dnsPolicy":"ClusterFirst","imagePullSecrets":[{"name":"register-addr"}],"restartPolicy":"Always","schedulerName":"default-scheduler","securityContext":{},"serviceAccount":"default","serviceAccountName":"default","terminationGracePeriodSeconds":30}},"updateStrategy":{"rollingUpdate":{"partition":0},"type":"RollingUpdate"},"volumeClaimTemplates":[{"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"creationTimestamp":null,"name":"zk-cluster-pvc","namespace":"hgjg-common"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}},"storageClassName":"local","volumeMode":"Filesystem"},"status":{"phase":"Pending"}}]}}
kubesphere.io/creator: admin
kubesphere.io/description: zookeeper集群
spec:
replicas: 3
selector:
matchLabels:
app: zk-cluster
template:
metadata:
creationTimestamp: null
labels:
app: zk-cluster
annotations:
cni.projectcalico.org/ipv4pools: '["default-ipv4-ippool"]'
kubesphere.io/creator: admin
kubesphere.io/imagepullsecrets: '{"container-o7sjfa":"register-addr"}'
kubesphere.io/restartedAt: '2025-01-13T05:11:56.755Z'
logging.kubesphere.io/logsidecar-config: '{}'
spec:
containers:
- name: container-o7sjfa
image: 'registry.flow.cn/library/bitnami_zookeeper:3.8.4'
command:
- sh
- '-c'
- >
export ZOO_SERVER_ID=$((${HOSTNAME##*-}+1))
export
ZOO_SERVERS='zk-cluster-0.zk-cluster-headless:2888:3888,zk-cluster-1.zk-cluster-headless:2888:3888,zk-cluster-2.zk-cluster-headless:2888:3888'
exec /opt/bitnami/scripts/zookeeper/entrypoint.sh
/opt/bitnami/scripts/zookeeper/run.sh
ports:
- name: client
containerPort: 2181
protocol: TCP
- name: server
containerPort: 2888
protocol: TCP
- name: leader-election
containerPort: 3888
protocol: TCP
# 可选zk的http接口
- name: adminserver
containerPort: 8080
protocol: TCP
env:
- name: TZ
value: Asia/Shanghai
# 允许匿名登录
- name: ALLOW_ANONYMOUS_LOGIN
value: 'yes'
# zk的堆内存设置,这里是1g
- name: JVMFLAGS
value: "-Xms1g -Xmx1g"
resources:
limits:
cpu: '1'
memory: 1536Mi # 要比上面VMFLAGS变量设置的要高,避免OOM
requests:
cpu: 500m
memory: 512Mi
volumeMounts:
- name: zk-cluster-pvc
- # 镜像默认zk的数据目录
mountPath: /bitnami/zookeeper
# https://github.com/bitnami/containers/blob/main/bitnami/zookeeper/3.8/debian-12/Dockerfile
# ZOO_SERVER_ID: 基于主机名截取id然后+1作为zk实例的id
# ZOO_SERVERS: 实例列表
# 探针
livenessProbe:
httpGet:
path: /commands/ruok
port: adminserver
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /commands/ruok
port: adminserver
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
imagePullSecrets:
- name: register-addr
# 反亲和的软策略,尽量不要调度到同一个node
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- zk-cluster
topologyKey: kubernetes.io/hostname
schedulerName: default-scheduler
volumeClaimTemplates:
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: zk-cluster-pvc
namespace: hgjg-common
creationTimestamp: null
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: local
volumeMode: Filesystem
status:
phase: Pending
serviceName: zk-cluster-headless
podManagementPolicy: OrderedReady
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 0
revisionHistoryLimit: 10
persistentVolumeClaimRetentionPolicy:
whenDeleted: Retain
whenScaled: Retain