Skip to content

Latest commit

 

History

History
119 lines (88 loc) · 3.98 KB

how-to-use-context.md

File metadata and controls

119 lines (88 loc) · 3.98 KB

How to use pulsarctl context

In multi-cluster, context is a very interesting and useful function. It can help users cache information of multiple clusters, and can switch between multiple clusters.

The feature will be support in v0.3.0 of pulsarctl.

Define contexts and auth info

Suppose you have two clusters, one for development work and one for scratch work. In the development cluster, the broker service URL is http://1.2.3.4:8080, the bookie service URL is http://1.2.3.4:8083. In your scratch cluster, the broker service URL is http://5.6.7.8:8080, the bookie service URL is http://5.6.7.8:8083.

Now, you can use set of context to define your cluster, the command as follows:

$ pulsarctl context set development --admin-service-url="http://1.2.3.4:8080" --bookie-service-url="http://1.2.3.4:8083"
$ pulsarctl context set scratch --admin-service-url="http://5.6.7.8:8080" --bookie-service-url="http://5.6.7.8:8083"

Then you can use the following command check content of pulsar:

$ cat $HOME/.config/pulsar

The content of pulsar as follows:

auth-info:
  development:
    locationoforigin: $HOME/.config/pulsar
    tls_trust_certs_file_path: ""
    tls_allow_insecure_connection: false
    token: ""
    tokenFile: ""
  scratch:
    locationoforigin: $HOME/.config/pulsar
    tls_trust_certs_file_path: ""
    tls_allow_insecure_connection: false
    token: ""
    tokenFile: ""
contexts:
  development:
    admin-service-url: http://1.2.3.4:8080
    bookie-service-url: http://1.2.3.4:8083
  scratch:
    admin-service-url: http://5.6.7.8:8080
    bookie-service-url: http://5.6.7.8:8083
current-context: ""

If you want to set the auth info, you can specify the following flags:

  • --token
  • --token-file
  • --tls-trust-cert-path
  • --tls-allow-insecure

Set the current context

When you define the info of cluster in $HOME/.config/pulsar, you can quickly switch between clusters by using the following command(suppose you want to use scratch cluster):

$ pulsarctl context use scratch

Now, you are using the context and auth info of scratch. And you can validate the current context value by using pulsarctl context current.

If you don't know the current names of cluster, you can use the following command:

$ pulsarctl context get

The output as follows:

+---------+-------------+---------------------+---------------------+
| CURRENT |    NAME     | BROKER SERVICE URL  | BOOKIE SERVICE URL  |
+---------+-------------+---------------------+---------------------+
|         | development | http://1.2.3.4:8080 | http://1.2.3.4:8083 |
|   *     | scratch     | http://5.6.7.8:8080 | http://5.6.7.8:8083 |
+---------+-------------+---------------------+---------------------+

Rename the context

For some reason, we defined the name of the current context incorrectly. If you want to modify the name, you can use the following command:

$ pulsarctl context rename old_name new_name

Delete the context

If the current cluster information is invalid, you want to delete it(suppose the cluster name is scratch), you can use the following command:

$ pulsarctl context delete scratch