apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kafka
  namespace: kafka
spec:
  selector:
    matchLabels:
      app: kafka
  serviceName: "broker"
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: kafka
    spec:
      terminationGracePeriodSeconds: 30
      initContainers:
        - name: init-config
          image: solsson/kafka-initutils:lastest@sha256:c8582b9df3b3ca9d804e2d914994411fb9b2d94353c4d5476f0a63cf75e59eb0
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          command: ["/bin/bash", "/etc/kafka-configmap/init.sh"]
          volumeMounts:
            - name: configmap
              mountPath: /etc/kafka-configmap
            - name: config
              mountPath: /etc/kafka
            - name: extensions
              mountPath: /opt/kafka/libs/extensions
      containers:
        - name: broker
          image: solsson/kafka:2.4.0@sha256:17f35e6dc3b5687107e0dae4cc0f3fc30d6613724e7b75fc1ed4d1a6f0744965
          env:
            - name: CLASSPATH
              value: /opt/kafka/libs/extensions/*
            - name: KAFKA_LOG4J_OPTS
              value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
            - name: JMX_PORT
              value: "5555"
          ports:
            - name: inside
              containerPort: 9092
            - name: outside
              containerPort: 9094
            - name: jmx
              containerPort: 5555
          command:
            - ./bin/kafka-server-start.sh
            - /etc/kafka/server.properties
          lifecycle:
            preStop:
              exec:
                command:
                  [
                    "sh",
                    "-ce",
                    "kill -s TERM 1; while $(kill -0 1 2>/dev/null); do sleep 1; done",
                  ]
          resources:
            requests:
              cpu: 100m
              memory: 100Mi
            limits:
              # This limit was intentionally set low as a reminder that
              # the entire Yolean/kubernetes-kafka is meant to be tweaked
              # before you run production workloads
              memory: 600Mi
          readinessProbe:
            tcpSocket:
              port: 9092
            timeoutSeconds: 1
          volumeMounts:
            - name: config
              mountPath: /etc/kafka
            - name: kafka-data
              mountPath: /var/lib/kafka/data
            - name: extensions
              mountPath: /opt/kafka/libs/extensions
      volumes:
        - name: configmap
          configMap:
            name: broker-config
        - name: config
          emptyDir: {}
        - name: extensions
          emptyDir: {}
        - name: kafka-data
          persistentVolumeClaim:
            claimName: kafka-persistence-volumn-claim
