创建主题,但在Kubernetes上使用Python获取Kafka FailedPayloadsError

时间:2015-09-14 12:42:50

标签: docker apache-kafka apache-zookeeper kubernetes kafka-python

我在python kafka-library中使用SimpleProducer。 这个脚本以前完美地运行了我尝试过的其他更加硬配置的kafka设置。

kafka = KafkaClient(u'[masterNodeIp]:[servicePort]')
producer = SimpleProducer(kafka)
#make a simple message, while true run
producer.send_messages(b'oneMoreTopic', sentence)

运行此脚本一次后,我在python-console中得到了这个响应。

kafka.common.LeaderNotAvailableError: TopicMetadata(topic='oneMoreTopic', error=5, partitions=[])

然后我可以在zookeeper.log上进入我的节点并查看:

2015-09-14 12:16:32,276 - INFO  [ProcessThread(sid:3  cport:-1)::PrepRequestProcessor@627] - Got user-level KeeperException when processing sessionid:0x34fcb982d030000 type:setData cxid:0x71 zxid:0x1000000d8 txntype:-1 reqpath:n/a Error Path:/config/topics/oneMoreTopic Error:KeeperErrorCode = NoNode for /config/topics/oneMoreTopic
2015-09-14 12:16:32,278 - INFO  [ProcessThread(sid:3 cport:-1)::PrepRequestProcessor@627] - Got user-level KeeperException when processing sessionid:0x34fcb982d030000 type:create cxid:0x72 zxid:0x1000000d9 txntype:-1 reqpath:n/a Error Path:/config/topics Error:KeeperErrorCode = NodeExists for /config/topics
2015-09-14 12:16:32,302 - INFO  [ProcessThread(sid:3 cport:-1)::PrepRequestProcessor@627] - Got user-level KeeperException when processing sessionid:0x34fcb982d030000 type:create cxid:0x7b zxid:0x1000000dc txntype:-1 reqpath:n/a Error Path:/brokers/topics/oneMoreTopic/partitions/0 Error:KeeperErrorCode = NoNode for /brokers/topics/oneMoreTopic/partitions/0
2015-09-14 12:16:32,304 - INFO  [ProcessThread(sid:3 cport:-1)::PrepRequestProcessor@627] - Got user-level KeeperException when processing sessionid:0x34fcb982d030000 type:create cxid:0x7c zxid:0x1000000dd txntype:-1 reqpath:n/a Error Path:/brokers/topics/oneMoreTopic/partitions Error:KeeperErrorCode = NoNode for /brokers/topics/oneMoreTopic/partitions

这似乎只是Zookeeper为该主题创建了一个新的Znode,因为它之前不存在。并且Kafka server.log打印:

[2015-09-14 12:16:32,282] INFO Topic creation {"version":1,"partitions":{"0":[10200119]}} (kafka.admin.AdminUtils$)
[2015-09-14 12:16:32,287] INFO [KafkaApi-10200219] Auto creation of topic oneMoreTopic with 1 partitions and replication factor 1 is successful! (kafka.server.KafkaApis)
[2015-09-14 12:16:51,579] INFO Closing socket connection to /10.240.1.94. (kafka.network.Processor)

但是,我的消息永远不会发布到主题上,下次我运行python脚本时总会得到:

kafka.common.FailedPayloadsError

在我使其工作的情况下,advertised.host.name始终是节点的外部IP,但我似乎无法通过Kubernetes工作。是否可以从容器中调用外部IP?

我的kafka / config / server.properties对所有经纪人来说都是这样的:

broker.id=10200121
host.name=kafka-f8p06
advertised.host.name=kafka-f8p06
++

2 个答案:

答案 0 :(得分:1)

broker.id=10200121
host.name=kafka-f8p06  <----- use IP here
advertised.host.name=kafka-f8p06  <---- use IP here

我认为您应该拥有host.nameadvertised.host.name的IP,因为K8不能通过主机名解析Pod,但它通过IP解析。

你的kafka节点可能无法以这种方式相互交谈,也无法找到领导者。

答案 1 :(得分:0)

我的问题的根本原因是通过确保我的所有节点都可以通过

到达互联网来解决
sudo iptables -t nat -A POSTROUTING ! -d 10.0.0.0/8 -o ens4v1 -j MASQUERADE

在此之后,我将advertised.host.name更改为我试图联系我的经纪人的外部IP地址。因此,如果我的GCE节点位于156.99.33.101,并且在33777上为我的kafka服务打开了nodePort,我会把:

advertised.host.name=156.99.33.101
advertised.host.port=33777

advertised.host.name是当其中一个代理获得请求时kafka用于连接回自身的内容,因此至少使用外部地址使其可以访问。虽然我不确定是否有任何后果将其指向本地地址空间之外。

Topic about LeaderNotAvailableException remotely