<p>I have a project with two microservices and gateway generated through JHipster. I deployed the project in AWS cloud using <a href="https://aws.amazon.com/quickstart/architecture/heptio-kubernetes/" rel="nofollow noreferrer">Kubernetes by Heptio on AWS</a>. Kafka container failed to start after several attempts. When I logged into the container through <code>kubectl</code>, I found out that Kafka unable to recognize the zookeeper hostname. Kafka and Zookeeper configuration files <a href="https://www.jhipster.tech/kubernetes/" rel="nofollow noreferrer">generated</a> by JHipster. </p>

<p>Exception:</p>

<pre><code>pjadda$ kubectl attach -it chargecodes-kafka-5799d8f99b-wnqhc  -n duppoc
Unable to use a TTY - container kafka did not allocate one
If you don't see a command prompt, try pressing enter.
waiting for kafka to be ready
waiting for kafka to be ready
[2018-03-21 00:22:29,263] INFO Terminate ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2018-03-21 00:22:29,265] FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.I0Itec.zkclient.exception.ZkException: Unable to connect to chargecodes-zookeeper.duppoc.svc.cluster.local:2181
    at org.I0Itec.zkclient.ZkConnection.connect(ZkConnection.java:72)
    at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:1228)
    at org.I0Itec.zkclient.ZkClient.&lt;init&gt;(ZkClient.java:157)
    at org.I0Itec.zkclient.ZkClient.&lt;init&gt;(ZkClient.java:131)
    at kafka.utils.ZkUtils$.createZkClientAndConnection(ZkUtils.scala:115)
    at kafka.utils.ZkUtils$.withMetrics(ZkUtils.scala:92)
    at kafka.server.KafkaServer.initZk(KafkaServer.scala:350)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:194)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
    at kafka.Kafka$.main(Kafka.scala:92)
    at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: chargecodes-zookeeper.duppoc.svc.cluster.local: System error
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at org.apache.zookeeper.client.StaticHostProvider.&lt;init&gt;(StaticHostProvider.java:61)
    at org.apache.zookeeper.ZooKeeper.&lt;init&gt;(ZooKeeper.java:445)
    at org.apache.zookeeper.ZooKeeper.&lt;init&gt;(ZooKeeper.java:380)
    at org.I0Itec.zkclient.ZkConnection.connect(ZkConnection.java:70)
    ... 10 more
[2018-03-21 00:22:29,269] INFO shutting down (kafka.server.KafkaServer)
[2018-03-21 00:22:29,280] INFO shut down completed (kafka.server.KafkaServer)
[2018-03-21 00:22:29,281] FATAL Exiting Kafka. (kafka.server.KafkaServerStartable)
[2018-03-21 00:22:29,283] INFO shutting down (kafka.server.KafkaServer)
</code></pre>

<p>Kubernetes Pods:</p>

<pre><code>NAME                                     READY     STATUS             RESTARTS   AGE
chargecodes-56fdf7cd49-fsrhb             0/1       CrashLoopBackOff   7          14m
chargecodes-kafka-5799d8f99b-wnqhc       0/1       CrashLoopBackOff   7          14m
chargecodes-mysql-5d8f4c9484-hxlrl       1/1       Running            0          14m
chargecodes-zookeeper-85d59f6759-lf4mh   1/1       Running            0          14m
jhipster-registry-0                      1/1       Running            0          14m
jhipster-registry-1                      1/1       Running            0          14m
</code></pre>

<p>chargecodes-kafka.yml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: chargecodes-kafka
  namespace: duppoc
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: chargecodes-kafka
    spec:
      containers:
      - name: kafka
        image: wurstmeister/kafka:1.0.0
        env:
        - name: KAFKA_ADVERTISED_HOST_NAME
          value: chargecodes-kafka.duppoc.svc.cluster.local
        - name: KAFKA_ADVERTISED_PORT
          value: '9092'
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: chargecodes-zookeeper.duppoc.svc.cluster.local:2181
        - name: KAFKA_CREATE_TOPICS
          value: 'topic-jhipster:1:1'
        ports:
        - containerPort: 9092
---
apiVersion: v1
kind: Service
metadata:
  name: chargecodes-kafka
  namespace: duppoc
spec:
  selector:
    app: chargecodes-kafka
  ports:
  - port: 9092
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: chargecodes-zookeeper
  namespace: duppoc
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: chargecodes-zookeeper
    spec:
      containers:
      - name: zookeeper
        image: wurstmeister/zookeeper:3.4.6
        ports:
        - containerPort: 2181
---
apiVersion: v1
kind: Service
metadata:
  name: chargecodes-zookeeper
  namespace: duppoc
spec:
  selector:
    app: chargecodes-zookeeper
  ports:
  - port: 2181
</code></pre>

<p>I deleted and recreated cloud formation stack in AWS. I think the issue was due to the fact that I deleted <code>kube-system</code> namespace by mistake. I think resetting <code>kube-system</code> namespace also solves the problem, but I had to make some changes to cluster so I deleted it.</p>
