kv consul of use

Official gateway to this part of the presentation: https://learn.hashicorp.com/consul/getting-started/kv

The consul kv function can be used for dynamic configuration, modify kv increased by consul delete query in addition to the client, but also through http api and ui consul's , and therefore whether it is integrated into the program, or view the management interface / configurations very convenient.

consul client

By consul client uses kv function I do not know of any practical use, but for the first time to experience the consul kv is still very convenient, can be achieved by simple additions and deletions kv command to change search.

First, consul agent is supported by default kv function, no special configuration, as long as the consul agent running, kv function can be used.

New data / modify data

These two commands are the same

consul kv put key value

Note: key is with a path, like this below

With a path on the one hand you can make your key more organized, more convenient watching, meaning more clearly, on the other hand, when a query, you can query the entire configuration of a direct path.

In addition the -flags argument can be used to add metadata to value, that is, keep some attribute information, so more convenient to use than ordinary kv.

Query data

Query a single key command as follows

consul kv get key

E.g:

All key inquiry under the specified path

consul kv get -recurse path

path can not write, do not write the words is to query all of the key

Metadata can be increased when adding / modifying data, this information may be obtained by adding the -detailed option

delete data

The following command to delete data

consul kv delete key

E.g: 

 Http API

Note Before that, start consul agent when the need to add parameters -client 0.0.0.0, this means that permit ip any machine connected consul, if not this parameter, consul default only the machine can access.

Query data

Use http get, url below, ip consul agent to run the machines ip, port 8500 by default, you can specify a different port, key path, then pay attention if there is need to bring through -http-port option when you start the consul agent.

http://ip:port/v1/kv/key

E.g: 

Note: value is the result of base64 encoded program in use http api, then the need for results value is decoded.

Add / Modify data

Use http put, url follows, body carrying value

http://ip:port/v1/kv/key

E.g: 

If you need to set the flags, the parameters added to the query, for example:

delete data

Use http delete, url below

http://ip:port/v1/kv/key

E.g:

 consul UI

By consul ui, you can easily operate kv data, also need to pay attention, to start consul agent when combined with -client 0.0.0.0 parameters, so as to achieve the consul run on the server, and you can access consul ui through the machine.

The operation is very convenient, not go into details.

Published 39 original articles · won praise 25 · views 120 000 +

Guess you like

Origin blog.csdn.net/u013536232/article/details/104188286