我正在尝试创建一个Kafka连接器后,连接分布式命令执行。我编写了entrypoint.sh脚本并将其与cmd一起使用。我有这样的docker文件:
FROM confluentinc/cp-kafka
RUN mkdir /plugins
RUN mkdir /config
COPY kafka-connect-couchbase-*.jar /plugins/
COPY config /config/
RUN chmod +x /config/stage/entrypoint.sh
ENV EXPOSED_PORT 8083
CMD /config/stage/entrypoint.sh
我的入口点脚本文件为:
connect-distributed config/"${DEPLOY_ENV}"/connect-distributed.properties
curl -X POST -H "Content-Type: application/json" -d @config.json http://localhost:8083/connectors
部署环境是无关的,它是来自Jenkins。配置文件和distributed.properties也不相关,而且是正确的,我手动尝试过。
kafka connect启动时没有问题,但是用于创建连接器的curl命令没有效果。
简而言之,我想在connect distributed启动后创建一个连接器,而不在容器外执行任何rest请求。我如何做到这一点?
2条答案
按热度按时间lmyy7pcs1#
多亏了罗宾·莫法特(robin moffatt)的绝妙解决方案,我把它与自己的需求结合起来,效果很好。
既然我把图像部署到库伯内特家,
/etc/confluent/docker/run &
background命令使容器传递到completed状态,而不是running。这使得容器无法通过rest接口从外部访问,如下所示:为了解决这个问题,我在最初的问题中使用了dockerfile,但是修改了robin的脚本,删除了汇合docker run命令并添加了额外的if来检查连接器是否存在。
之后,我通过添加post start lifecycle修改了kubernetes部署文件,并将entrypoint.sh脚本作为命令来执行,如下所示:
基本上,它首先启动kafka connect,在进程(pod)启动之后,我只需执行自定义shell脚本来创建kafka连接器。
希望这对有类似使用场景的人有所帮助。我也对其他(更好的)解决方案持开放态度。多谢罗宾·莫法特。
zdwk9cvp2#
您需要确保您正在等待kafka connect worker完全启动。
顺便说一句,你最好从Kafka连接基地的形象开始
通常您会使用confluent hub来安装连接器,但是看起来couchbase一个不在那里,所以您必须像以前一样在jar中复制。
在connect图像中启动kafka connect的实际脚本是
/etc/confluent/docker/run
,所以你的/config/stage/entrypoint.sh
应该是这样的:另请参见https://rmoff.net/2018/12/15/docker-tips-and-tricks-with-ksql-and-kafka/