Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Kafka Client fails to connect to docker image #123

Closed
Tracked by #744
loopingrage opened this issue Nov 18, 2020 · 11 comments
Closed
Tracked by #744

Java Kafka Client fails to connect to docker image #123

loopingrage opened this issue Nov 18, 2020 · 11 comments
Assignees

Comments

@loopingrage
Copy link

I spun up an instance of vectorized/redpanda:latest and tried connecting from the my Docker host using the standard Java client. This is what I see in my application log:

Connection to node 1 (/0.0.0.0:9092) could not be established.

I believe this is due to the fact that the Java client connects to redpanda as a bootsrtap and as part of the Kafka protocol handshake it is give the address to the actual broker which in this case seems to resolve to 0.0.0.0.

This is from the docker logs:

kafka                  | INFO  2020-11-18 05:31:30,439 [shard 0] redpanda::main - application.cc:162 - advertised_kafka_api:{nullopt}	- Address of Kafka API published to the clients
....
kafka                  | INFO  2020-11-18 05:31:30,440 [shard 0] redpanda::main - application.cc:162 - kafka_api:{host: 0.0.0.0, port: 9092}	- Address and port of an interface to listen for Kafka API requests

I'm migrating my app from Apache Kafka and for my existing config I had to specify some environment variables to get the bootstrap process to work including:

KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:9093
KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093

Note the support for multiple ports mapping to different host names. This was needed to work in both docker compose where the host name for the kafka container was literally kafka and when connecting from the host using an exposed port.

Does your Docker image have support for similar ENV configs? The redpanda docker image on Docker Hub doesn't have a README yet (I know you're working on one).

@BenPope
Copy link
Member

BenPope commented Nov 18, 2020

advertised_kafka_api needs to be set. Instead of using the docker standalone, it might be easier to use rpk container start -n 3, which will set things up properly: https://vectorized.io/rpk-container/

@dotnwat
Copy link
Member

dotnwat commented Nov 18, 2020

we should probably consider exposing similar configurations via environment variable, perhaps even 1-1 with the kafka environment variables if there is a strong connection between configurations. it would seem to make sense for this sort of network configuration.

@dotnwat
Copy link
Member

dotnwat commented Nov 18, 2020

@loopingrage we're working on the issue related to advertised host in #125. in the meantime, i was able to get the java client to connect successfully to redpanda running in docker using host networking, if that is an option for you:

docker run --network=host vectorized/redpanda:latest
bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --list

@loopingrage
Copy link
Author

I'm running within a Docker Compose environment so host networking unfortunately does not work in my case. The rpk container option won't work for the same reason.

Just a thought. Is there a way to mount my own redpanda config file into the container? If you place the config file in its own directory that would be it pretty easy for me to do using a a Docker Compose volume that mounts a config on the Docker host. We do this for our own software where environment variables are not flexible enough to express the multitude of config options.

@dotnwat
Copy link
Member

dotnwat commented Nov 18, 2020

@loopingrage yes, @0x5d i think has some instructions to make this volume mount + config trick work until #125 lands.

@loopingrage
Copy link
Author

Any thoughts @0x5d?

@0x5d
Copy link
Contributor

0x5d commented Nov 19, 2020

Hi @loopingrage. You can put the config file (redpanda.yaml) in a directory and mount it into /etc/redpanda/ on the container.

You can use this as a template (complete reference: https://vectorized.io/documentation/advanced-configuration/):

config_file: /etc/redpanda/redpanda.yaml
redpanda:
  admin:
    address: 0.0.0.0
    port: 9644
  advertised_kafka_api:
    address: 127.0.0.1
    port: 45677
  advertised_rpc_api:
    address: <container hostname>
    port: 33145
  data_directory: /var/lib/redpanda/data
  developer_mode: true
  kafka_api:
    address: <container hostname>
    port: 9092
  kafka_api_tls:
    cert_file: ""
    enabled: false
    key_file: ""
    truststore_file: ""
  node_id: <node id>
  rpc_server:
    address: <container hostname>
    port: 33145
  seed_servers: []
  auto_create_topics_enabled: true

rpk:
  enable_usage_stats: true
  tune_network: false
  tune_disk_scheduler: false
  tune_disk_nomerges: false
  tune_disk_irq: false
  tune_fstrim: false
  tune_cpu: false
  tune_aio_events: false
  tune_clocksource: false
  tune_swappiness: false
  enable_memory_locking: false
  tune_coredump: false

@dotnwat dotnwat self-assigned this Nov 20, 2020
@rk3rn3r
Copy link

rk3rn3r commented Feb 2, 2021

I start a single node Redpanda container with docker compose like that:

version: '2'
services:
  kafka:
    image: vectorized/redpanda:latest
    hostname: kafka
    ports:
     - 9092:9092
    command: ["start", "--advertise-kafka-addr", "kafka:9092"]

And it works well with Kafka Connect Distributed.
FYI @senior7515 ;)

@dotnwat
Copy link
Member

dotnwat commented Feb 2, 2021

excellent @rk3rn3r @loopingrage multi-network support just landed in the core so we now supported named listeners like you expect in kafka. that's being wired up right now through rpk tooling #529

@BenPope
Copy link
Member

BenPope commented Apr 30, 2021

Closing this as multi-listener is now configurable from config file and command line args. Please open a new issue if there are still issues.

@BenPope BenPope closed this as completed Apr 30, 2021
@rk3rn3r
Copy link

rk3rn3r commented May 3, 2021

@BenPope @dotnwat nice! I will test soon 🤞

gousteris added a commit to gousteris/redpanda that referenced this issue Mar 30, 2022
Added 2 additional jobs backport-type to get the backport
that the user wants to create; type-pr to create backport draft pull requests
when commenting on issues. The type-branch job creates the issue
or the PR based on the source of the comment (PR or issue).

Examples:
* comment on issues:
/backport v21.11.x: Creates backport issue and adds milestone/assignees

* comment on backport-issues (issues that the bot created to track a backport):
/backport 123: Cherry-picking the commits of PR redpanda-data#123 and creates a draft PR. Adds the issue
               link in the PR description

* comment on PR:
/backport v21.11.x: Cherry-picking the commits of the PR that the user posted the comment
                    and creates the draft PR
gousteris added a commit to gousteris/redpanda that referenced this issue Apr 6, 2022
Added 2 additional jobs backport-type to get the backport
that the user wants to create; type-pr to create backport draft pull requests
when commenting on issues. The type-branch job creates the issue
or the PR based on the source of the comment (PR or issue).

Examples:
* comment on issues:
/backport v21.11.x: Creates backport issue and adds milestone/assignees

* comment on backport-issues (issues that the bot created to track a backport):
/backport 123: Cherry-picking the commits of PR redpanda-data#123 and creates a draft PR. Adds the issue
               link in the PR description

* comment on PR:
/backport v21.11.x: Cherry-picking the commits of the PR that the user posted the comment
                    and creates the draft PR
gousteris added a commit to gousteris/redpanda that referenced this issue Apr 6, 2022
Added 2 additional jobs backport-type to get the backport
that the user wants to create; type-pr to create backport draft pull requests
when commenting on issues. The type-branch job creates the issue
or the PR based on the source of the comment (PR or issue).

Examples:
* comment on issues:
/backport v21.11.x: Creates backport issue and adds milestone/assignees

* comment on backport-issues (issues that the bot created to track a backport):
/backport 123: Cherry-picking the commits of PR redpanda-data#123 and creates a draft PR. Adds the issue
               link in the PR description

* comment on PR:
/backport v21.11.x: Cherry-picking the commits of the PR that the user posted the comment
                    and creates the draft PR
gousteris added a commit to gousteris/redpanda that referenced this issue Apr 6, 2022
Added 2 additional jobs backport-type to get the backport
that the user wants to create; type-pr to create backport draft pull requests
when commenting on issues. The type-branch job creates the issue
or the PR based on the source of the comment (PR or issue).

Examples:
* comment on issues:
/backport v21.11.x: Creates backport issue and adds milestone/assignees

* comment on backport-issues (issues that the bot created to track a backport):
/backport 123: Cherry-picking the commits of PR redpanda-data#123 and creates a draft PR. Adds the issue
               link in the PR description

* comment on PR:
/backport v21.11.x: Cherry-picking the commits of the PR that the user posted the comment
                    and creates the draft PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants