Skip to content

Running Kafka Commands via kubectl exec, work around JMX_PORT conflict #144

Description

@elm-

Is anyone executing commands against the cluster from shell scripts? I'm trying to run scripts for topic creation, disk space monitoring, etc. Directly running it from "kubectl exec" fails because of JMX_PORT conflict:

elmar@cpy-salt-master:~$ kubectl --namespace=kafka exec -it kafka-0 -- bin/kafka-topics.sh --zookeeper zookeeper:2181 --list
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 5555; nested exception is: 
	java.net.BindException: Address already in use (Bind failed)
command terminated with exit code 1

The workaround I use is to first bash into the machine and then run the cmds with the JMX_PORT env variable overwritten.

elmar@cpy-salt-master:~$ kubectl --namespace=kafka exec -it kafka-0 bash
root@kafka-0:/opt/kafka# JMX_PORT=4321 bin/kafka-topics.sh --zookeeper zookeeper:2181 --list
[...]
__consumer_offsets
[...]

Unfortunately kubectl exec does not support providing environment variables.

Any ideas how to make this work without first running bash?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions