Specify Admin API Addresses for rpk

For rpk to know where to run admin-related commands, you must provide the admin server 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 admin.hosts)

  • Environment variable setting (RPK_ADMIN_HOSTS)

  • Configuration file setting in redpanda.yaml (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 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

Admin API addresses are required for communicating with the Admin API. Provide these addresses with the —-api-urls flag for commands related to cluster or user tasks, such as rpk cluster health and rpk cluster maintenance enable <node_id>. Note that rpk cluster info and rpk cluster metadata instead require the -X brokers flag.

The following table shows which rpk commands require the -X admin.hosts or --hosts flag.

Command Address flag required

rpk security user

-X admin.hosts

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

-X admin.hosts

rpk redpanda admin

--hosts

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_ADMIN_HOSTS.

For example, to configure the addresses to use when running Admin API commands on an external cluster with three brokers:

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 broker starts up, a redpanda.yaml configuration file is automatically generated for that broker. This file contains a section for rpk settings, which includes Admin API settings.

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 admin servers.

rpk:
  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.