Managing Clusters

Clusters - 图1tip

This page only shows some frequently used operations.

  • For the latest and complete information about Pulsar admin, including commands, flags, descriptions, and more, see Pulsar admin doc.

  • For the latest and complete information about REST API, including parameters, responses, samples, and more, see REST API doc.

  • For the latest and complete information about Java admin API, including classes, methods, descriptions, and more, see Java admin API doc.

Pulsar clusters consist of one or more Pulsar brokers, one or more BookKeeper servers (aka bookies), and a ZooKeeper cluster that provides configuration and coordination management.

Clusters can be managed via:

  • The clusters command of the pulsar-admin tool
  • The /admin/v2/clusters endpoint of the admin REST API
  • The clusters method of the PulsarAdmin object in the Java API

Clusters resources

Provision

New clusters can be provisioned using the admin interface.

Clusters - 图2note

This operation requires superuser privileges.

  • pulsar-admin
  • REST API
  • Java

You can provision a new cluster using the create subcommand. Here’s an example:

  1. pulsar-admin clusters create cluster-1 \
  2. --url http://my-cluster.org.com:8080 \
  3. --broker-url pulsar://my-cluster.org.com:6650

PUT /admin/v2/clusters/:cluster/createCluster

  1. ClusterData clusterData = new ClusterData(
  2. serviceUrl,
  3. serviceUrlTls,
  4. brokerServiceUrl,
  5. brokerServiceUrlTls
  6. );
  7. admin.clusters().createCluster(clusterName, clusterData);

Initialize cluster metadata

When provisioning a new cluster, you need to initialize that cluster’s metadata. When initializing cluster metadata, you need to specify all of the following:

  • The name of the cluster
  • The local metadata store connection string for the cluster
  • The configuration store connection string for the entire instance
  • The web service URL for the cluster
  • A broker service URL enabling interaction with the brokers in the cluster

You must initialize cluster metadata before starting up any brokers that will belong to the cluster.

No cluster metadata initialization through the REST API or the Java admin API

Unlike most other admin functions in Pulsar, cluster metadata initialization cannot be performed via the admin REST API or the admin Java client, as metadata initialization involves communicating with ZooKeeper directly. Instead, you can use the pulsar CLI tool, in particular the initialize-cluster-metadata command.

Here’s an example cluster metadata initialization command:

  1. bin/pulsar initialize-cluster-metadata \
  2. --cluster us-west \
  3. --metadata-store zk:zk1.us-west.example.com:2181,zk2.us-west.example.com:2181/my-chroot-path \
  4. --configuration-metadata-store zk:zk1.us-west.example.com:2181,zk2.us-west.example.com:2181/my-chroot-path \
  5. --web-service-url http://pulsar.us-west.example.com:8080/ \
  6. --web-service-url-tls https://pulsar.us-west.example.com:8443/ \
  7. --broker-service-url pulsar://pulsar.us-west.example.com:6650/ \
  8. --broker-service-url-tls pulsar+ssl://pulsar.us-west.example.com:6651/

You’ll need to use --*-tls flags only if you’re using mTLS authentication in your instance.

Get configuration

You can fetch the configuration for an existing cluster at any time.

  • pulsar-admin
  • REST API
  • Java

Use the get subcommand and specify the name of the cluster. Here’s an example:

  1. pulsar-admin clusters get cluster-1

Output:

  1. {
  2. "serviceUrl": "http://my-cluster.org.com:8080/",
  3. "serviceUrlTls": null,
  4. "brokerServiceUrl": "pulsar://my-cluster.org.com:6650/",
  5. "brokerServiceUrlTls": null
  6. "peerClusterNames": null
  7. }

GET /admin/v2/clusters/:cluster/getCluster

  1. admin.clusters().getCluster(clusterName);

Update

You can update the configuration for an existing cluster at any time.

  • pulsar-admin
  • REST API
  • Java

Use the update subcommand and specify new configuration values using flags.

  1. pulsar-admin clusters update cluster-1 \
  2. --url http://my-cluster.org.com:4081 \
  3. --broker-url pulsar://my-cluster.org.com:3350

POST /admin/v2/clusters/:cluster/updateCluster

  1. ClusterData clusterData = new ClusterData(
  2. serviceUrl,
  3. serviceUrlTls,
  4. brokerServiceUrl,
  5. brokerServiceUrlTls
  6. );
  7. admin.clusters().updateCluster(clusterName, clusterData);

Delete

Clusters can be deleted from a Pulsar instance.

  • pulsar-admin
  • REST API
  • Java

Use the delete subcommand and specify the name of the cluster.

  1. pulsar-admin clusters delete cluster-1

DELETE /admin/v2/clusters/:cluster/deleteCluster

  1. admin.clusters().deleteCluster(clusterName);

List

You can fetch a list of all clusters in a Pulsar instance.

  • pulsar-admin
  • REST API
  • Java

Use the list subcommand.

  1. pulsar-admin clusters list

Output:

  1. cluster-1
  2. cluster-2

GET /admin/v2/clusters/getClusters

  1. admin.clusters().getClusters();

Update peer-cluster data

Peer clusters can be configured for a given cluster in a Pulsar instance.

  • pulsar-admin
  • REST API
  • Java

Use the update-peer-clusters subcommand and specify the list of peer-cluster names.

  1. pulsar-admin update-peer-clusters cluster-1 --peer-clusters cluster-2

POST /admin/v2/clusters/:cluster/peers/setPeerClusterNames

  1. admin.clusters().updatePeerClusterNames(clusterName, peerClusterList);