Broker and Admin API Addresses

In order for rpk to know where to run Kafka-related commands or admin-related commands, you must provide the broker addresses or admin server addresses for each node 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 or -X admin.hosts)

  • Environment variable setting (RPK_BROKERS or RPK_ADMIN_HOSTS)

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

Command line flag settings take precedence over environment variable settings and configuration file settings. If the command line does not contain the -X brokers or -X admin.hosts 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

To determine whether a command needs the -X brokers flag or the -X admin.hosts flag, follow these guidelines:

The following table shows which rpk commands require the -X brokers flag, which require the -X admin.hosts or --hosts flag, and which don’t require either flag.

Command Address flag required

rpk acl (all except rpk acl user)

-X brokers

rpk acl user

-X admin.hosts

rpk cloud

None

rpk cluster (all except rpk cluster info and rpk cluster metadata)

-X admin.hosts

rpk cluster info

-X brokers

rpk cluster metadata

-X brokers

rpk container

None

rpk debug

None

rpk generate

None

rpk group

-X brokers

rpk iotune

None

rpk plugin

None

rpk redpanda (all except rpk redpanda admin)

None

rpk redpanda admin

--hosts

rpk topic

-X brokers

rpk version

None

Environment variable settings

Environment variable settings last for the duration of the shell session, or until you set the variable to a different setting.

You can 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, this is how you could configure three brokers on a single machine running on localhost:

export RPK_BROKERS="127.0.0.1:41457,127.0.0.1:39397,127.0.0.1:37735"

For Admin API addresses, configure the environment variable RPK_ADMIN_HOSTS. For example, this is how you could configure the addresses to use when running Admin API commands on an external cluster with three nodes:

export RPK_ADMIN_HOSTS="192.168.78.34:9644,192.168.78.35:9644,192.168.78.36:9644"

Configuration file settings

As each Redpanda node starts up, a redpanda.yaml configuration file is automatically generated for that node. This file contains a section for rpk settings, which includes Kafka API settings and Admin 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 admin_api section contains the address and port for each admin server. The default address is 0.0.0.0, and the default port is 9644. You can edit this line and replace it with the Admin API IP addresses.

The following example shows the addresses and port numbers for two brokers and two admin servers.

rpk:
  kafka_api:
    brokers:
    - 192.168.72.34:9092
    - 192.168.72.35:9092

  admin_api:
    - 192.168.72.34:9644
    - 192.168.72.35:9644
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.