apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kafka-broker
spec:
  serviceName: kafka-broker
  replicas: 3
  selector:
    matchLabels:
      app: kafka-broker
  template:
    metadata:
      labels:
        app: kafka-broker
    spec:
      containers:
      - name: kafka-broker
        image: confluentinc/cp-enterprise-kafka:5.3.1
        command:
        - /bin/bash
        args:
        - -c
        - export KAFKA_BROKER_ID=$((${HOSTNAME##*-}+1)) && export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://${HOSTNAME}.kafka-broker:9092 && /etc/confluent/docker/run
        ports:
        - containerPort: 9092
          name: host
        env:
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: zookeeper-0.zookeeper:2181,zookeeper-1.zookeeper:2181,zookeeper-2.zookeeper:2181
        # - name: KAFKA_ADVERTISED_LISTENERS
        #   value: PLAINTEXT://kafka-broker:9092,
        # - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
        #   value: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
        # - name: KAFKA_METRIC_REPORTERS
        #   value: io.confluent.metrics.reporter.ConfluentMetricsReporter
        # - name: CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS
        #   value: broker:9092
        # - name: CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT
        #   value: zookeeper:${ZOOKEEPER_PORT}
        # - name: CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS
        #   value: "1"
        # - name: CONFLUENT_METRICS_ENABLE
        #   value: "true"
        # - name: CONFLUENT_SUPPORT_CUSTOMER_ID
        #   value: anonymous
        volumeMounts:
        - name: data
          mountPath: /var/lib/kafka/data
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
