apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: zk-ss
  namespace: kafka
  labels:
    app: zk
    component: kafka
spec:
  selector:
    matchLabels:
      app: zk
      component: kafka
  serviceName: zk-svc
  replicas: 3
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: OrderedReady
  volumeClaimTemplates:
  - metadata:
      name: zk-data
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi
  template:
    metadata:
      labels:
        app: zk
        component: kafka
    spec: 
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                    - zk
                  - key: "component"
                    operator: In
                    values:
                    - kafka
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: kafka-zookeeper
        imagePullPolicy: Always
        image: "confluentinc/cp-zookeeper:6.2.0"
        resources:
          requests:
            memory: "1Gi"
            cpu: "0.5"
        ports:
        - containerPort: 2181
          name: client
        env:
        - name: ZOOKEEPER_CLIENT_PORT
          value: "2181"
        - name: ZOOKEEPER_TICK_TIME
          value: "2000"
        readinessProbe:
          exec:
            command:
            - sh
            - -c
            - "echo stat | nc 127.0.0.1 2181"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - "echo stat | nc 127.0.0.1 2181"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        volumeMounts:
        - name: zk-data
          mountPath: /var/lib/zookeeper
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
