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 (
--brokersor--api-urls) -
Environment variable setting (
REDPANDA_BROKERSorREDPANDA_API_ADMIN_ADDRS) -
Configuration file setting in
redpanda.yaml(rpk.kafka_api.brokersorrpk.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 --brokers or –-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, andrpk 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>, andrpk acl user. Note thatrpk cluster infois an exception to this rule, since it requires the--brokersflag.
The following table shows which rpk commands require the --brokers flag, which require the --api-urls or --hosts flag, and which don’t require either flag.
| Command | Address flag required |
|---|---|
|
|
|
|
|
None |
|
|
|
|
|
|
|
None |
|
None |
|
None |
|
|
|
None |
|
None |
|
None |
|
|
|
|
|
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 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:
export REDPANDA_BROKERS="127.0.0.1:41457,127.0.0.1:39397,127.0.0.1:37735"
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:
export REDPANDA_API_ADMIN_ADDRS="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.
|