apiVersion: v1
kind: Service
metadata:
  name: kafka-service
  labels:
    run: kafka
  annotations:
    metallb.universe.tf/allow-shared-ip: "kafka"
# namespace: kafka
spec:
  ports:
    - name: kafka
      protocol: TCP
      port: 9092
      targetPort: 9092
  selector:
    run: kafka
  type: LoadBalancer
  loadBalancerIP: 10.42.42.238
  externalTrafficPolicy: Local
#---
#apiVersion: v1
#kind: Service
#metadata:
#  name: kafka-udp
#  labels:
#    run: kafka
#  annotations:
#    metallb.universe.tf/allow-shared-ip: "kafka"
#spec:
#  ports:
#    - name: dns
#      protocol: UDP
#      port: 53
#      targetPort: 53
#  selector:
#    run: kafka
#  type: LoadBalancer
#  loadBalancerIP: 10.42.42.238
#  externalTrafficPolicy: Local
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: kafka
# namespace: kafka
spec:
  capacity:
    storage: 5Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Kubernetes/volumes/static/kafka
    server: 10.42.42.10
  claimRef:
    name: kafka
# namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kafka
  annotations:
    nfs.io/storage-path: "kafka"
# namespace: kafka
spec:
  storageClassName: default
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Mi
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka
# namespace: kafka
spec:
  replicas: 1
  selector:
    matchLabels:
      run: kafka
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: kafka
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - image: ubuntu/kafka:latest
          imagePullPolicy: "Always"
          name: kafka
          env:
            - name: TZ
              value: US/Michigan
            - name: ZOOKEEPER_HOST
              value: 10.152.183.97
# Gather from kubectl get services -n kafka
            - name: ZOOKEEPER_PORT
              value: "2181"
          args: ["/etc/kafka/server.properties"]
#          args: ["/etc/kafka/server.properties", "--override", "advertised.listeners=PLAINTEXT://kafka-service:9092"]
#          args: ["--override", "advertised.listeners=PLAINTEXT://kafka.home.monkeybox.org:9092"]
          ports:
            - containerPort: 9092
              name: kafka
              protocol: TCP
          resources: {}
          volumeMounts:
            - mountPath: /kafka
              name: kafka
      restartPolicy: Always
      volumes:
        - name: kafka
          persistentVolumeClaim:
            claimName: kafka
status: {}
#---
## Hosting
#apiVersion: networking.k8s.io/v1
#kind: Ingress
#metadata:
#  name: kafka-management
#  annotations:
#    #nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
#    #nginx.ingress.kubernetes.io/proxy-ssl-verify: "off"
#    cert-manager.io/cluster-issuer: "letsencrypt-prod"
#spec:
#  tls:
#  - hosts:
#    - kafka.monkeybox.org
#    secretName: kafka-tls
#  rules:
#  - host: kafka.monkeybox.org
#    http:
#      paths:
#      - path: /
#        pathType: Prefix
#        backend:
#          service:
#            name: kafka-service
#            port:
#              number: 80
