Kubernetes中的Kafka UnknownHostException异常

时间:2018-03-21 00:38:40

标签: java docker apache-kafka kubernetes jhipster

我有一个项目,有两个微服务和通过JHipster生成的网关。我使用Kubernetes by Heptio on AWS在AWS云中部署了项目。几次尝试后,Kafka集装箱未能启动。当我通过kubectl登录容器时,我发现Kafka无法识别zookeeper主机名。 JHipster的Kafka和Zookeeper配置文件generated

例外:

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.<init>(ZkClient.java:157)
    at org.I0Itec.zkclient.ZkClient.<init>(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.<init>(StaticHostProvider.java:61)
    at org.apache.zookeeper.ZooKeeper.<init>(ZooKeeper.java:445)
    at org.apache.zookeeper.ZooKeeper.<init>(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)

Kubernetes Pods:

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

chargecodes-kafka.yml

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

1 个答案:

答案 0 :(得分:1)

我在AWS中删除并重新创建了云形成堆栈。我认为这个问题是因为我错误地删除了kube-system命名空间。我认为重置kube-system命名空间也解决了这个问题,但我不得不对群集进行一些更改,所以我删除了它。