---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: zookeeper-service
  name: zookeeper-service
  namespace: statefun 
spec:
  type: NodePort
  ports:
  - name: zookeeper-port
    port: 2181
    targetPort: 2181
  selector:
    app: zookeeper

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: zookeeper
  name: zookeeper
  namespace: statefun
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zookeeper
  template:
    metadata:
      labels:
        app: zookeeper
    spec:
      containers:
      - image: library/zookeeper:3.4.13
        imagePullPolicy: IfNotPresent
        name: zookeeper
        ports:
        - containerPort: 2181
        env:
        - name: ZOO_MY_ID
          value: "1"
---
apiVersion: v1
kind: Service
metadata:
  name: kafka
  namespace: statefun 
  labels:
    app: kafka
spec:
  ports:
  - port: 9092
    name: plaintext
  - port: 9999
    name: jmx
  clusterIP: None
  selector:
    app: kafka
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka
  namespace: statefun
spec:
  selector:
    matchLabels:
      app: kafka
  replicas: 1
  template:
    metadata:
      labels:
        app: kafka
    spec:
      containers:
      - name: kafka
        image: wurstmeister/kafka:2.11-2.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9092
          name: plaintext
        - containerPort: 9999
          name: jmx
        env:
          - name: KAFKA_BROKER_ID
            value: "1"
          - name: KAFKA_ADVERTISED_HOST_NAME
            value: "kafka.statefun.svc.cluster.local"
          - name: KAFKA_ADVERTISED_PORT
            value: "9092"
          - name: KAFKA_ZOOKEEPER_CONNECT
            value: "zookeeper-service:2181"
          - name: KAFKA_LISTENERS
            value: "PLAINTEXT://:9092"
          - name: KAFKA_JMX_OPTS
            value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9999 -Djava.rmi.server.hostname=127.0.0.1"
          - name: JMX_PORT
            value: "9999"
          - name: KAFKA_AUTO_CREATE_TOPICS_ENABLE 
            value: "true"
          - name:  KAFKA_LOG_RETENTION_MS
            value: "600000"
          - name: KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS
            value: "60000"
          - name: KAFKA_TRANSACTION_MAX_TIMEOUT_MS
            value: "3600000"
