Specify Broker Addresses for rpk

For rpk to know where to run Kafka-related commands, you must provide the broker addresses for each broker of a Redpanda cluster. You can specify these addresses as IP addresses or as hostnames, using any of these methods:

  • Command line flag (-X brokers)

  • Environment variable setting (RPK_BROKERS)

  • Configuration file setting in redpanda.yaml (rpk.kafka_api.brokers)

Command line flag settings take precedence over environment variable settings and configuration file settings. If the command line does not contain the -X brokers settings, the environment variable settings are used. If the environment variables are not set, the values in the configuration file are used.

Command line flags

Broker addresses are required for communicating with the Kafka API. Provide these addresses with the -X brokers flag for commands related to Kafka broker tasks, such as rpk topic create, rpk topic produce, and rpk topic consume.

The following table shows which rpk commands require the -X brokers flag.

Command Address flag required

rpk cluster info

-X brokers

rpk cluster metadata

-X brokers

rpk group

-X brokers

rpk security acl

-X brokers

rpk topic

-X brokers

Environment variable settings

Environment variable settings last for the duration of the shell session, or until you set the variable to a different setting. Configure the environment variable RPK_BROKERS for broker addresses, so you don’t have to include the -X brokers flag each time you run an rpk command.

For example, to configure three brokers on a single machine running on localhost:

export RPK_BROKERS="192.168.72.34:9092,192.168.72.35:9092,192.168.72.36.9092"

Configuration file settings

As each Redpanda broker starts up, a redpanda.yaml configuration file is automatically generated for that broker. This file contains a section for rpk settings, which includes Kafka API settings.

The kafka_api section contains the address and port for each broker. The default address is 0.0.0.0, and the default port is 9092. You can edit this line and replace it with the IP addresses of your Redpanda brokers.

The following example shows the addresses and port numbers for three brokers.

rpk:
  kafka_api:
    brokers:
    - 192.168.72.34:9092
    - 192.168.72.35:9092
    - 192.168.72.36.9092
If you do not update the default addresses in the redpanda.yaml file, you must provide the required addresses on the command line or by setting the corresponding environment variable.