---
# 参数资料：
# https://hub.docker.com/_/zookeeper
# https://github.com/31z4/zookeeper-docker/blob/95e63be6a0767ed462db2e5aa779047672cc3b35/3.4.14/Dockerfile
# https://github.com/31z4/zookeeper-docker/blob/master/3.4.14/docker-entrypoint.sh
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: zookeeper
  namespace: zookeeper
spec:
  serviceName: zookeeper
  replicas: 3
  selector:
    matchLabels:
      k8s-app: zookeeper
  template:
    metadata:
      labels:
        k8s-app: zookeeper
    spec:
      containers:
        - name: zookeeper
          image: harbor.freedom.org/docker.io/zookeeper:3.4.14
          command:
            - sh
            - -c
            - /root/generate-myid.sh && zkServer.sh start-foreground #改写command参数，启动服务前生成myid文件。
          ports:
            - name: client
              containerPort: 2181
            - name: server
              containerPort: 2888
            - name: leader-election
              containerPort: 3888
          env:
            - name: TZ
              value: Asia/Shanghai
          resources:
            limits:
              cpu: 2000m
              memory: 2048Mi
            requests:
              cpu: 1000m
              memory: 1024Mi
          volumeMounts:
            - name: zookeeper-data
              mountPath: /data
            - name: zookeeper-conf
              mountPath: /conf
            - name: zookeeper-script
              mountPath: /root
      volumes:
        - name: zookeeper-conf
          configMap:
            name: zookeeper-zoo.cfg
        - name: zookeeper-script              # 在/data目录下创建myid文件，需要挂一个script来生成，不使用ZOO_MY_ID环境变量的方式。
          configMap:
            name: zookeeper-generate-myid.sh
            defaultMode: 0755
  volumeClaimTemplates:
    - metadata:
        name: zookeeper-data
        annotations:
          volume.beta.kubernetes.io/storage-class: storageclass-nfs-infra
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi