title: How to start kafka on kubernetes
body: <p>My aim is to start a kafka topic with multiple partitions on kubernetes.
  To do that I deploy the following .yml file:    </p>
  
  <pre><code>apiVersion: v1
  kind: Namespace
  metadata:
    name: kafka
  
  ---
  
  apiVersion: v1
  kind: Pod
  metadata:
    name: kubernetes-kafka
    namespace: kafka
    labels:
      k8s-app: kubernetes-kafka
  spec:
    containers:
      - name: zookeeper
        image: zookeeper
        env:
        - name: ZOO_MY_ID
          value: "1"
  
  
      - name: kafka
        image: wurstmeister/kafka
        env:
        - name: KAFKA_ADVERTISED_HOST_NAME
          value: "kubernetes-cluster.nt"
        - name: KAFKA_ADVERTISED_PORT
          value: 30001
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: "localhost:2181"
        - name: KAFKA_BROKER_ID
          value: "1"
        - name: KAFKA_CREATE_TOPICS
          value: write:20:1
  
  ---
  
  apiVersion: v1
  kind: Service
  metadata:
    name: kubernetes-kafka
    namespace: kafka
  spec:
    type: NodePort
    selector:
      k8s-app: kubernetes-kafka
    ports:
    - name: zk-client
      port: 2181
      protocol: TCP
    - name: zk-follower
      port: 2888
      protocol: TCP
    - name: zk-election
      port: 3888
      protocol: TCP
    - name: zk-admin
      port: 8080
      protocol: TCP
    - name: kafka-client
      port: 9092
      nodePort: 30001
      protocol: TCP
  </code></pre>
  
  <p>I expect this code to create a <code>kafka</code> server on <code>kubernetes</code>, whose <code>write</code> topic  can be accessible via <code>host:port = kubernetes-cluster.nt:30001</code></p>
  
  <p>However, although kubernetes service and pod are started (<code>kubectl get pods --all-namespaces</code> and <code>kubectl get services --all-namespaces</code> commands list entries with the name kubernetes-kafka), the kafka topic is not created:</p>
  
  <pre><code>kafkacat -b kubernetes-cluster.nt:30001 -L
  </code></pre>
  
  <p>which should list all topics returns that 0 topics are created:</p>
  
  <pre><code>Metadata for all topics (from broker 1: kubernetes-cluster.nt:30001/1):
   1 brokers:
     broker 1 at kubernetes-cluster.nt:30001
   0 topics:
  </code></pre>
  
  <p><strong>What am I doing wrong</strong>?</p>