apiVersion: v1
kind: Pod
metadata:
  name: kafka
  labels:
    app.kubernetes.io/name: kafka
spec:
  containers:
    - name: kafka
      image: quay.io/strimzi/kafka:latest-kafka-2.8.1
      imagePullPolicy: IfNotPresent
      command:
        - /bin/sh
        - -c
        - "export CLUSTER_ID=$(bin/kafka-storage.sh random-uuid) && bin/kafka-storage.sh format -t $CLUSTER_ID -c config/kraft/server.properties --ignore-formatted && bin/kafka-server-start.sh config/kraft/server.properties --override advertised.listeners=${KAFKA_ADVERTISED_LISTENERS} --override listener.security.protocol.map=${KAFKA_LISTENER_SECURITY_PROTOCOL_MAP} --override listeners=${KAFKA_LISTENERS} --override inter.broker.listener.name=${KAFKA_INTER_BROKER_LISTENER_NAME}"
      env:
        - name: LOG_DIR
          value: /tmp/logs
        - name: KAFKA_LISTENERS
          value: LISTENER_INTERNAL://:9092,LISTENER_EXTERNAL://:9091,CONTROLLER://:9093
        - name: KAFKA_ADVERTISED_LISTENERS
          value: LISTENER_INTERNAL://kafka:9092,LISTENER_EXTERNAL://kafka.127.0.0.1.nip.io:9091
        - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
          value: LISTENER_INTERNAL:PLAINTEXT,LISTENER_EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT
        - name: KAFKA_INTER_BROKER_LISTENER_NAME
          value: LISTENER_INTERNAL
      ports:
        - name: external
          containerPort: 9091
          hostPort: 9091
        - name: internal
          containerPort: 9092
        - name: controller
          containerPort: 9093
      startupProbe:
        exec:
          command:
            - /bin/sh
            - -c
            - "netstat -lnt | grep -Eq 'tcp6?[[:space:]]+[0-9]+[[:space:]]+[0-9]+[[:space:]]+[^ ]+:9091.*LISTEN[[:space:]]'"
        initialDelaySeconds: 5
        periodSeconds: 1
        successThreshold: 1
        failureThreshold: 55
      securityContext:
        runAsNonRoot: true
        readOnlyRootFilesystem: true
      volumeMounts:
        - name: tmp
          mountPath: /tmp
  automountServiceAccountToken: false
  terminationGracePeriodSeconds: 0
  volumes:
    - name: tmp
      emptyDir: {}
