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 (
- Environment variable setting (
- Configuration file setting in
Command line flag settings take precedence over environment variable settings and configuration file settings. If the command line does not contain the
–-api-urls 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
--brokers flag or the
--api-urls flag, follow these guidelines:
Broker addresses are required for communicating with the Kafka API. Provide these addresses by using the
--brokersflag for commands related to Kafka broker tasks; for example,
rpk topic create,
rpk topic produce, and
rpk topic consume.
Admin API addresses are required for communicating with the Admin API. Provide these addresses by using the
—-api-urlsflag for commands related to cluster or user tasks; for example,
rpk cluster health,
rpk cluster maintenance enable <node_id>, and
rpk acl user. Note that
rpk cluster infois an exception to this rule, since it requires the
The following table shows which
rpk commands require the
–-brokers flag, which require the
–-hosts flag, and which don’t require either flag.
|Command||Address flag required|
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
REDPANDA_BROKERS for broker addresses so you don’t have to include the
--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:
For Admin API addresses, configure the environment variable
REDPANDA_API_ADMIN_ADDRS. For example, this is how you could configure the addresses to use when running Admin API commands on an external cluster with three nodes:
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.
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.
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.
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.