apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka-app
  namespace: logharbour
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafka-app
  template:
    metadata:
      labels:
        app: kafka-app
    spec:
      initContainers:
      - name: permission-fix
        image: busybox:1.28
        command: ["/bin/sh", "-c"]
        args:
          - chown -R 1001:1001 /bitnami/kafka
        volumeMounts:
        - mountPath: /bitnami/kafka
          name: kafka-pv-volume
      containers:
      - name: kafka-container
        image: bitnami/kafka:3.6.0
        ports:
        - containerPort: 9092
        - containerPort: 9093
        - containerPort: 9094
        #resources:
         # limits:
          #  cpu: "0.5"
           # memory: "500Mi"
          #requests:
           # cpu: "0.5"
            #memory: "500Mi"
        env:
        - name: KAFKA_CFG_NODE_ID
          value: "0"
        - name: KAFKA_CFG_PROCESS_ROLES
          value: "controller,broker"
        - name: KAFKA_CFG_LISTENERS
          value: "PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094"
        - name: KAFKA_CFG_ADVERTISED_LISTENERS
          value: "PLAINTEXT://kafka-svc:9092,EXTERNAL://kafka-svc:9094"
        - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
          value: "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT"
        - name: KAFKA_CFG_CONTROLLER_QUORUM_VOTERS
          value: "0@localhost:9093"
        - name: KAFKA_CFG_CONTROLLER_LISTENER_NAMES
          value: "CONTROLLER"
        - name: ALLOW_PLAINTEXT_LISTENER
          value: "yes"
        - name: KAFKA_AUTO_CREATE_TOPICS_ENABLE
          value: "true"
        volumeMounts:
            - mountPath: "/bitnami/kafka"
              name: kafka-pv-volume
      volumes:
        - name: kafka-pv-volume
          persistentVolumeClaim:
            claimName: kafka-pv-claim
      nodeSelector:
        name: node-1
---
apiVersion: v1
kind: Service
metadata:
  name: kafka-svc
  namespace: logharbour
spec:
  selector:
    app: kafka-app
  ports:
  - name: port-9092
    port: 9092
    targetPort: 9092
  - name: port-9093
    port: 9093
    targetPort: 9093
  - name: port-9094
    port: 9094
    targetPort: 9094

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: kafka-pv-volume
  namespace: logharbour
  labels:
    type: local
spec:
  storageClassName: standard
  capacity:
    storage: 500Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/kra-data/data/dev/kafka-data"

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kafka-pv-claim
  namespace: logharbour
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi
