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