---
# Source: kafka/templates/poddisruptionbudget.yaml
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: gitee-kafka
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: kafka
---
# Source: kafka/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: gitee-kafka
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
---
# Source: kafka/templates/jmx-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: gitee-kafka-jmx-configuration
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
data:
  jmx-kafka-prometheus.yml: |-
    jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:5555/jmxrmi
    lowercaseOutputName: true
    lowercaseOutputLabelNames: true
    ssl: false
    whitelistObjectNames: ["kafka.controller:*","kafka.server:*","java.lang:*","kafka.network:*","kafka.log:*"]
    rules:
      - pattern: kafka.controller<type=(ControllerChannelManager), name=(QueueSize), broker-id=(\d+)><>(Value)
        name: kafka_controller_$1_$2_$4
        labels:
          broker_id: "$3"
      - pattern: kafka.controller<type=(ControllerChannelManager), name=(TotalQueueSize)><>(Value)
        name: kafka_controller_$1_$2_$3
      - pattern: kafka.controller<type=(KafkaController), name=(.+)><>(Value)
        name: kafka_controller_$1_$2_$3
      - pattern: kafka.controller<type=(ControllerStats), name=(.+)><>(Count)
        name: kafka_controller_$1_$2_$3
      - pattern: kafka.server<type=(ReplicaFetcherManager), name=(.+), clientId=(.+)><>(Value)
        name: kafka_server_$1_$2_$4
        labels:
          client_id: "$3"
      - pattern : kafka.network<type=(Processor), name=(IdlePercent), networkProcessor=(.+)><>(Value)
        name: kafka_network_$1_$2_$4
        labels:
          network_processor: $3
      - pattern : kafka.network<type=(RequestMetrics), name=(RequestsPerSec), request=(.+)><>(Count)
        name: kafka_network_$1_$2_$4
        labels:
          request: $3
      - pattern: kafka.server<type=(.+), name=(.+), topic=(.+)><>(Count|OneMinuteRate)
        name: kafka_server_$1_$2_$4
        labels:
          topic: $3
      - pattern: kafka.server<type=(DelayedOperationPurgatory), name=(.+), delayedOperation=(.+)><>(Value)
        name: kafka_server_$1_$2_$3_$4
      - pattern: kafka.server<type=(.+), name=(.+)><>(Count|Value|OneMinuteRate)
        name: kafka_server_$1_total_$2_$3
      - pattern: kafka.server<type=(.+)><>(queue-size)
        name: kafka_server_$1_$2
      - pattern: java.lang<type=(.+), name=(.+)><(.+)>(\w+)
        name: java_lang_$1_$4_$3_$2
      - pattern: java.lang<type=(.+), name=(.+)><>(\w+)
        name: java_lang_$1_$3_$2
      - pattern : java.lang<type=(.*)>
      - pattern: kafka.log<type=(.+), name=(.+), topic=(.+), partition=(.+)><>Value
        name: kafka_log_$1_$2
        labels:
          topic: $3
          partition: $4
---
# Source: kafka/templates/scripts-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: gitee-kafka-scripts
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
data:
  setup.sh: |-
    #!/bin/bash
    result=$(echo $MY_POD_NAME | grep "gitee-kafka-backup-storage")
    if [ "$result" != "" ]; then
      ID="${MY_POD_NAME#"gitee-kafka-backup-storage-"}"
      export KAFKA_CFG_BROKER_ID="4$ID"
        echo $KAFKA_CFG_BROKER_ID
    fi
    if [ "$result" == "" ]; then
      ID="${MY_POD_NAME#"gitee-kafka-"}"
      export KAFKA_CFG_BROKER_ID="$ID"
      echo $KAFKA_CFG_BROKER_ID
    fi

    exec /entrypoint.sh /run.sh
---
# Source: kafka/charts/zookeeper/templates/svc-headless.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitee-kafka-zookeeper-headless
  namespace: middleware-test
  labels:
    app.kubernetes.io/name: zookeeper
    helm.sh/chart: zookeeper-5.14.5
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: zookeeper
spec:
  type: ClusterIP
  clusterIP: None
  publishNotReadyAddresses: true
  ports:
    
    - name: tcp-client
      port: 2181
      targetPort: client
    
    
    - name: follower
      port: 2888
      targetPort: follower
    - name: tcp-election
      port: 3888
      targetPort: election
  selector:
    app.kubernetes.io/name: zookeeper
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/component: zookeeper
---
# Source: kafka/charts/zookeeper/templates/svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitee-kafka-zookeeper
  namespace: middleware-test
  labels:
    app.kubernetes.io/name: zookeeper
    helm.sh/chart: zookeeper-5.14.5
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: zookeeper
spec:
  type: ClusterIP
  ports:
    
    - name: tcp-client
      port: 2181
      targetPort: client
    
    
    - name: follower
      port: 2888
      targetPort: follower
    - name: tcp-election
      port: 3888
      targetPort: election
  selector:
    app.kubernetes.io/name: zookeeper
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/component: zookeeper
---
# Source: kafka/templates/jmx-metrics-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitee-kafka-jmx-metrics
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
  annotations: 
    prometheus.io/path: /
    prometheus.io/port: ''
    prometheus.io/scrape: "true"
spec:
  type: ClusterIP
  ports:
    - name: http-metrics
      port: 5556
      protocol: TCP
      targetPort: metrics
      nodePort: null
  selector:
    app.kubernetes.io/name: kafka
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/component: kafka
---
# Source: kafka/templates/kafka-metrics-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitee-kafka-metrics
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: metrics
  annotations: 
    prometheus.io/path: /metrics
    prometheus.io/port: ''
    prometheus.io/scrape: "true"
spec:
  type: ClusterIP
  ports:
    - name: http-metrics
      port: 9308
      protocol: TCP
      targetPort: metrics
      nodePort: null
  selector:
    app.kubernetes.io/name: kafka
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/component: metrics
---
# Source: kafka/templates/svc-headless.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitee-kafka-headless
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - name: tcp-client
      port: 9092
      protocol: TCP
      targetPort: kafka-client
    - name: tcp-internal
      port: 9093
      protocol: TCP
      targetPort: kafka-internal
  selector:
    app.kubernetes.io/name: kafka
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/component: kafka
---
# Source: kafka/templates/svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitee-kafka
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  type: ClusterIP
  ports:
    - name: tcp-client
      port: 9092
      protocol: TCP
      targetPort: kafka-client
      nodePort: null
  selector:
    app.kubernetes.io/name: kafka
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/component: kafka
---
# Source: kafka/templates/kafka-metrics-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitee-kafka-exporter
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: metrics
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: metrics
  template:
    metadata:
      labels:
        app.kubernetes.io/name: kafka
        helm.sh/chart: kafka-11.0.2-osc
        app.kubernetes.io/instance: gitee-kafka
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: metrics
    spec:      
      imagePullSecrets:
        - name: oschub
      containers:
        - name: kafka-exporter
          image: registry.baidubce.com/gitee-poc/bitnami/kafka-exporter:1.2.0-debian-10-r131
          imagePullPolicy: "IfNotPresent"
          command:
            - /bin/bash
            - -ec
            - |
              kafka_exporter \
              --kafka.server=gitee-kafka-0.gitee-kafka-headless.middleware-test.svc.cluster.local:9092 \
              --kafka.server=gitee-kafka-1.gitee-kafka-headless.middleware-test.svc.cluster.local:9092 \
              --kafka.server=gitee-kafka-2.gitee-kafka-headless.middleware-test.svc.cluster.local:9092 \
              --web.listen-address=:9308
          # env:
          #   - name: SASL_USER_PASSWORD
          #     valueFrom:
          #       secretKeyRef:
          #         name: gitee-kafka-jaas
          #         key: client-password
          ports:
            - name: metrics
              containerPort: 9308
          resources: 
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi
---
# Source: kafka/charts/zookeeper/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gitee-kafka-zookeeper
  namespace: middleware-test
  labels:
    app.kubernetes.io/name: zookeeper
    helm.sh/chart: zookeeper-5.14.5
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: zookeeper
    role: zookeeper
spec:
  serviceName: gitee-kafka-zookeeper-headless
  replicas: 1
  podManagementPolicy: Parallel
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app.kubernetes.io/name: zookeeper
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: zookeeper
  template:
    metadata:
      name: gitee-kafka-zookeeper
      labels:
        app.kubernetes.io/name: zookeeper
        helm.sh/chart: zookeeper-5.14.5
        app.kubernetes.io/instance: gitee-kafka
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: zookeeper
    spec:
      
      imagePullSecrets:
        - name: oschub
      securityContext:
        fsGroup: 1001
      containers:
        - name: zookeeper
          image: registry.baidubce.com/gitee-prod/zookeeper:3.6.1-debian-10-r77
          imagePullPolicy: "IfNotPresent"
          securityContext:
            runAsUser: 1001
          command:
            - bash
            - -ec
            - |
                # Execute entrypoint as usual after obtaining ZOO_SERVER_ID based on POD hostname
                HOSTNAME=`hostname -s`
                if [[ $HOSTNAME =~ (.*)-([0-9]+)$ ]]; then
                  ORD=${BASH_REMATCH[2]}
                  export ZOO_SERVER_ID=$((ORD+1))
                else
                  echo "Failed to get index from hostname $HOST"
                  exit 1
                fi
                exec /entrypoint.sh /run.sh
          resources:
            limits:
              cpu: 0.5
              ephemeral-storage: 2Gi
              memory: 1G
            requests:
              cpu: 250m
              ephemeral-storage: 2Gi
              memory: 256Mi
          env:
            - name: ZOO_PORT_NUMBER
              value: "2181"
            - name: ZOO_TICK_TIME
              value: "2000"
            - name: ZOO_INIT_LIMIT
              value: "10"
            - name: ZOO_SYNC_LIMIT
              value: "5"
            - name: ZOO_MAX_CLIENT_CNXNS
              value: "60"
            - name: ZOO_4LW_COMMANDS_WHITELIST
              value: "srvr, mntr"
            - name: ZOO_LISTEN_ALLIPS_ENABLED
              value: "no"
            - name: ZOO_AUTOPURGE_INTERVAL
              value: "0"
            - name: ZOO_AUTOPURGE_RETAIN_COUNT
              value: "3"
            - name: ZOO_SERVERS
              value: gitee-kafka-zookeeper-0.gitee-kafka-zookeeper-headless.middleware-test.svc.cluster.local:2888:3888 
            - name: ZOO_ENABLE_AUTH
              value: "no"
            - name: ZOO_HEAP_SIZE
              value: "1024"
            - name: ZOO_LOG_LEVEL
              value: "ERROR"
            - name: ALLOW_ANONYMOUS_LOGIN
              value: "yes"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
          ports:
            
            - name: client
              containerPort: 2181
            
            
            - name: follower
              containerPort: 2888
            - name: election
              containerPort: 3888
          livenessProbe:
            tcpSocket:
              
              port: client
              
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          readinessProbe:
            tcpSocket:
              
              port: client
              
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          volumeMounts:
            - name: data
              mountPath: /bitnami/zookeeper
      volumes:
  volumeClaimTemplates:
    - metadata:
        name: data
        annotations:
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
        storageClassName: managed-nfs-storage-52
---
# Source: kafka/templates/statefulset-backup-storage.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gitee-kafka-backup-storage
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  podManagementPolicy: Parallel
  replicas: 0
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: kafka
  serviceName: gitee-kafka-headless
  updateStrategy:
    type: "RollingUpdate"
  template:
    metadata:
      labels:
        app.kubernetes.io/name: kafka
        helm.sh/chart: kafka-11.0.2-osc
        app.kubernetes.io/instance: gitee-kafka
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: kafka
      annotations:
        checksum/jmx-configuration: 70287ad9db553bdb5e499621ad5de6fe51b368f1b49ed2db14cc25ee8972ceef
    spec:      
      imagePullSecrets:
        - name: oschub
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchLabels:
                  app.kubernetes.io/component: kafka
                  app.kubernetes.io/instance: 'gitee-kafka'
                  app.kubernetes.io/name: kafka
              topologyKey: kubernetes.io/hostname
            weight: 100
      securityContext:
        fsGroup: 1001
        runAsUser: 1001
      serviceAccountName: gitee-kafka
      containers:
        - name: kafka
          image: registry.baidubce.com/gitee-prod/bitnami/kafka:2.5.0-debian-10-r54
          imagePullPolicy: "Always"
          command:
            - /scripts/setup.sh
          env:
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: KAFKA_CFG_ZOOKEEPER_CONNECT
              value: "gitee-kafka-zookeeper"
            - name: KAFKA_INTER_BROKER_LISTENER_NAME
              value: "INTERNAL"
            - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
              value: "INTERNAL:PLAINTEXT,CLIENT:PLAINTEXT"
            - name: KAFKA_CFG_LISTENERS
              value: "INTERNAL://:9093,CLIENT://:9092"
            - name: KAFKA_CFG_ADVERTISED_LISTENERS
              value: "INTERNAL://$(MY_POD_NAME).gitee-kafka-headless.middleware-test.svc.cluster.local:9093,CLIENT://$(MY_POD_NAME).gitee-kafka-headless.middleware-test.svc.cluster.local:9092"
            - name: ALLOW_PLAINTEXT_LISTENER
              value: "yes"
            - name: KAFKA_CFG_BROKER_ID
              value: "-1"
            - name: JMX_PORT
              value: "5555"
            - name: KAFKA_CFG_DELETE_TOPIC_ENABLE
              value: "false"
            - name: KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE
              value: "true"              
            - name: KAFKA_HEAP_OPTS
              value: "-Xmx1024m -Xms1024m"
            - name: KAFKA_CFG_LOG_FLUSH_INTERVAL_MESSAGES
              value: "10000"
            - name: KAFKA_CFG_LOG_FLUSH_INTERVAL_MS
              value: "1000"
            - name: KAFKA_CFG_LOG_RETENTION_BYTES
              value: "1073741824"
            - name: KAFKA_CFG_LOG_RETENTION_CHECK_INTERVALS_MS
              value: "300000"
            - name: KAFKA_CFG_LOG_RETENTION_HOURS
              value: "168"
            - name: KAFKA_CFG_MESSAGE_MAX_BYTES
              value: "1000012"
            - name: KAFKA_CFG_LOG_SEGMENT_BYTES
              value: "1073741824"
            - name: KAFKA_CFG_LOG_DIRS
              value: "/bitnami/kafka/data"
            - name: KAFKA_CFG_DEFAULT_REPLICATION_FACTOR
              value: "3"
            - name: KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR
              value: "3"
            - name: KAFKA_CFG_TRANSACTION_STATE_LOG_REPLICATION_FACTOR
              value: "3"
            - name: KAFKA_CFG_TRANSACTION_STATE_LOG_MIN_ISR
              value: "3"
            - name: KAFKA_CFG_NUM_IO_THREADS
              value: "8"
            - name: KAFKA_CFG_NUM_NETWORK_THREADS
              value: "3"
            - name: KAFKA_CFG_NUM_PARTITIONS
              value: "1"
            - name: KAFKA_CFG_NUM_RECOVERY_THREADS_PER_DATA_DIR
              value: "1"
            - name: KAFKA_CFG_SOCKET_RECEIVE_BUFFER_BYTES
              value: "102400"
            - name: KAFKA_CFG_SOCKET_REQUEST_MAX_BYTES
              value: "104857600"
            - name: KAFKA_CFG_SOCKET_SEND_BUFFER_BYTES
              value: "102400"
            - name: KAFKA_CFG_ZOOKEEPER_CONNECTION_TIMEOUT_MS
              value: "6000"
          ports:
            - name: kafka-client
              containerPort: 9092
            - name: kafka-internal
              containerPort: 9093
          livenessProbe:
            initialDelaySeconds: 10
            tcpSocket:
              port: kafka-client
            timeoutSeconds: 5
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 5
            tcpSocket:
              port: kafka-client
            timeoutSeconds: 5
          resources:
            limits:
              cpu: 2
              memory: 4Gi
            requests:
              cpu: 200m
              memory: 4Gi
          volumeMounts:
            - name: data
              mountPath: /bitnami/kafka
            - name: scripts
              mountPath: /scripts/setup.sh
              subPath: setup.sh
        - name: jmx-exporter
          image: registry.baidubce.com/gitee-poc/bitnami/jmx-exporter:0.13.0-debian-10-r20
          imagePullPolicy: "IfNotPresent"
          command:
            - java
            - -XX:+UnlockExperimentalVMOptions
            - -XX:+UseCGroupMemoryLimitForHeap
            - -XX:MaxRAMFraction=1
            - -XshowSettings:vm
            - -jar
            - jmx_prometheus_httpserver.jar
            - "5556"
            - /etc/jmx-kafka/jmx-kafka-prometheus.yml
          ports:
            - name: metrics
              containerPort: 5556
          resources:
            limits: {}
            requests: {}
          volumeMounts:
            - name: jmx-config
              mountPath: /etc/jmx-kafka
      volumes:
        - name: scripts
          configMap:
            name: gitee-kafka-scripts
            defaultMode: 0755
        - name: jmx-config
          configMap:
            name: gitee-kafka-jmx-configuration
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - "ReadWriteMany"
        resources:
          requests:
            storage: "8Gi"
        
        storageClassName: managed-nfs-storage-52
---
# Source: kafka/templates/statefulset-main-storage.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gitee-kafka
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  podManagementPolicy: Parallel
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: kafka
  serviceName: gitee-kafka-headless
  updateStrategy:
    type: "RollingUpdate"
  template:
    metadata:
      labels:
        app.kubernetes.io/name: kafka
        helm.sh/chart: kafka-11.0.2-osc
        app.kubernetes.io/instance: gitee-kafka
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: kafka
      annotations:
        checksum/jmx-configuration: 70287ad9db553bdb5e499621ad5de6fe51b368f1b49ed2db14cc25ee8972ceef
    spec:      
      imagePullSecrets:
        - name: oschub
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchLabels:
                  app.kubernetes.io/component: kafka
                  app.kubernetes.io/instance: 'gitee-kafka'
                  app.kubernetes.io/name: kafka
              topologyKey: kubernetes.io/hostname
            weight: 100
      securityContext:
        fsGroup: 1001
        runAsUser: 1001
      serviceAccountName: gitee-kafka
      containers:
        - name: kafka
          image: registry.baidubce.com/gitee-prod/bitnami/kafka:2.5.0-debian-10-r54
          imagePullPolicy: "Always"
          command:
            - /scripts/setup.sh
          env:
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: KAFKA_CFG_ZOOKEEPER_CONNECT
              value: "gitee-kafka-zookeeper"
            - name: KAFKA_INTER_BROKER_LISTENER_NAME
              value: "INTERNAL"
            - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
              value: "INTERNAL:PLAINTEXT,CLIENT:PLAINTEXT"
            - name: KAFKA_CFG_LISTENERS
              value: "INTERNAL://:9093,CLIENT://:9092"
            - name: KAFKA_CFG_ADVERTISED_LISTENERS
              value: "INTERNAL://$(MY_POD_NAME).gitee-kafka-headless.middleware-test.svc.cluster.local:9093,CLIENT://$(MY_POD_NAME).gitee-kafka-headless.middleware-test.svc.cluster.local:9092"
            - name: ALLOW_PLAINTEXT_LISTENER
              value: "yes"
            - name: KAFKA_CFG_BROKER_ID
              value: "-1"
            - name: JMX_PORT
              value: "5555"
            - name: KAFKA_CFG_DELETE_TOPIC_ENABLE
              value: "false"
            - name: KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE
              value: "true"              
            - name: KAFKA_HEAP_OPTS
              value: "-Xmx1024m -Xms1024m"
            - name: KAFKA_CFG_LOG_FLUSH_INTERVAL_MESSAGES
              value: "10000"
            - name: KAFKA_CFG_LOG_FLUSH_INTERVAL_MS
              value: "1000"
            - name: KAFKA_CFG_LOG_RETENTION_BYTES
              value: "1073741824"
            - name: KAFKA_CFG_LOG_RETENTION_CHECK_INTERVALS_MS
              value: "300000"
            - name: KAFKA_CFG_LOG_RETENTION_HOURS
              value: "168"
            - name: KAFKA_CFG_MESSAGE_MAX_BYTES
              value: "1000012"
            - name: KAFKA_CFG_LOG_SEGMENT_BYTES
              value: "1073741824"
            - name: KAFKA_CFG_LOG_DIRS
              value: "/bitnami/kafka/data"
            - name: KAFKA_CFG_DEFAULT_REPLICATION_FACTOR
              value: "3"
            - name: KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR
              value: "3"
            - name: KAFKA_CFG_TRANSACTION_STATE_LOG_REPLICATION_FACTOR
              value: "3"
            - name: KAFKA_CFG_TRANSACTION_STATE_LOG_MIN_ISR
              value: "3"
            - name: KAFKA_CFG_NUM_IO_THREADS
              value: "8"
            - name: KAFKA_CFG_NUM_NETWORK_THREADS
              value: "3"
            - name: KAFKA_CFG_NUM_PARTITIONS
              value: "1"
            - name: KAFKA_CFG_NUM_RECOVERY_THREADS_PER_DATA_DIR
              value: "1"
            - name: KAFKA_CFG_SOCKET_RECEIVE_BUFFER_BYTES
              value: "102400"
            - name: KAFKA_CFG_SOCKET_REQUEST_MAX_BYTES
              value: "104857600"
            - name: KAFKA_CFG_SOCKET_SEND_BUFFER_BYTES
              value: "102400"
            - name: KAFKA_CFG_ZOOKEEPER_CONNECTION_TIMEOUT_MS
              value: "6000"
          ports:
            - name: kafka-client
              containerPort: 9092
            - name: kafka-internal
              containerPort: 9093
          livenessProbe:
            initialDelaySeconds: 10
            tcpSocket:
              port: kafka-client
            timeoutSeconds: 5
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 5
            tcpSocket:
              port: kafka-client
            timeoutSeconds: 5
          resources:
            limits:
              cpu: 2
              memory: 4Gi
            requests:
              cpu: 200m
              memory: 4Gi
          volumeMounts:
            - name: data
              mountPath: /bitnami/kafka
            - name: scripts
              mountPath: /scripts/setup.sh
              subPath: setup.sh
        - name: jmx-exporter
          image: registry.baidubce.com/gitee-poc/bitnami/jmx-exporter:0.13.0-debian-10-r20
          imagePullPolicy: "IfNotPresent"
          command:
            - java
            - -XX:+UnlockExperimentalVMOptions
            - -XX:+UseCGroupMemoryLimitForHeap
            - -XX:MaxRAMFraction=1
            - -XshowSettings:vm
            - -jar
            - jmx_prometheus_httpserver.jar
            - "5556"
            - /etc/jmx-kafka/jmx-kafka-prometheus.yml
          ports:
            - name: metrics
              containerPort: 5556
          resources:
            limits: {}
            requests: {}
          volumeMounts:
            - name: jmx-config
              mountPath: /etc/jmx-kafka
      volumes:
        - name: scripts
          configMap:
            name: gitee-kafka-scripts
            defaultMode: 0755
        - name: jmx-config
          configMap:
            name: gitee-kafka-jmx-configuration
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - "ReadWriteMany"
        resources:
          requests:
            storage: "8Gi"
        
        storageClassName: managed-nfs-storage-52
---
# Source: kafka/templates/prometheusrule.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: kafka
  namespace: "middleware-test"
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  groups:
    - name: kafka
      rules:
        - alert: KafkaTopicsReplicas
          expr: sum(kafka_topic_partition_in_sync_replica) by (topic) < 3
          for: 0m
          labels:
            severity: critical
          annotations:
            summary:  Kafka topic({{ $labels.topic }}) in-sync partition 
            description: Kafka topic({{ $labels.topic }}) in-sync partition current values:{{ $value }}
        - alert: KafkaConsumersGroup
          expr: sum(kafka_consumergroup_lag) by (consumergroup) > 50
          for: 1m
          labels:
            severity: critical
          annotations:
            summary: Kafka consumers group ({{ $labels.consumergroup }})
            description: Kafka consumers group ({{ $labels.consumergroup }}) CurrentValue:{{ $value }}
---
# Source: kafka/templates/servicemonitor-jmx-metrics.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: gitee-kafka-jmx-metrics
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: kafka
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: kafka
  endpoints:
    - port: http-metrics
      path: "/"
  namespaceSelector:
    matchNames:
      - middleware-test
---
# Source: kafka/templates/servicemonitor-metrics.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: gitee-kafka-metrics
  labels:
    app.kubernetes.io/name: kafka
    helm.sh/chart: kafka-11.0.2-osc
    app.kubernetes.io/instance: gitee-kafka
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: metrics
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
      app.kubernetes.io/instance: gitee-kafka
      app.kubernetes.io/component: metrics
  endpoints:
    - port: http-metrics
      path: "/metrics"
  namespaceSelector:
    matchNames:
      - middleware-test
