Consul Commands (CLI)

    The consul CLI is a well-behaved command line application. In erroneous cases, a non-zero exit status will be returned. It also responds to -h and --help as you’d most likely expect. And some commands that expect input accept “-“ as a parameter to tell Consul to read the input from stdin.

    To view a list of the available commands at any time, just run consul with no arguments:

    1. $ consul
    2. Usage: consul [--version] [--help] <command> [<args>]
    3. Available commands are:
    4. acl Interact with Consul's ACLs
    5. agent Runs a Consul agent
    6. catalog Interact with the catalog
    7. connect Interact with Consul Connect
    8. debug Records a debugging archive for operators
    9. event Fire a new event
    10. exec Executes a command on Consul nodes
    11. force-leave Forces a member of the cluster to enter the "left" state
    12. info Provides debugging information for operators.
    13. intention Interact with Connect service intentions
    14. join Tell Consul agent to join cluster
    15. keygen Generates a new encryption key
    16. keyring Manages gossip layer encryption keys
    17. kv Interact with the key-value store
    18. leave Gracefully leaves the Consul cluster and shuts down
    19. lock Execute a command holding a lock
    20. login Login to Consul using an auth method
    21. logout Destroy a Consul token created with login
    22. maint Controls node or service maintenance mode
    23. members Lists the members of a Consul cluster
    24. monitor Stream logs from a Consul agent
    25. operator Provides cluster-level tools for Consul operators
    26. reload Triggers the agent to reload configuration files
    27. rtt Estimates network round trip time between nodes
    28. services Interact with services
    29. snapshot Saves, restores and inspects snapshots of Consul server state
    30. validate Validate config files/directories
    31. version Prints the Consul version
    32. watch Watch for changes in Consul

    To get help for any specific command, pass the -h flag to the relevant subcommand. For example, to see help about the join subcommand:

    1. $ consul join --help
    2. Usage: consul join [options] address ...
    3. by specifying at least one existing member.
    4. HTTP API Options
    5. -http-addr=<address>
    6. The `address` and port of the Consul HTTP agent. The value can be
    7. an IP address or DNS address, but it must also include the port.
    8. This can also be specified via the CONSUL_HTTP_ADDR environment
    9. variable. The default value is http://127.0.0.1:8500. The scheme
    10. can also be set to HTTPS by setting the environment variable
    11. CONSUL_HTTP_SSL=true.
    12. -token=<value>
    13. ACL token to use in the request. This can also be specified via the
    14. CONSUL_HTTP_TOKEN environment variable. If unspecified, the query
    15. will default to the token of the Consul agent at the HTTP address.
    16. Command Options
    17. -wan
    18. Joins a server to another server in the WAN pool.
    1. $ consul join --help
    2. Usage: consul join [options] address ...
    3. Tells a running Consul agent (with "consul agent") to join the cluster
    4. by specifying at least one existing member.
    5. HTTP API Options
    6. -http-addr=<address>
    7. The `address` and port of the Consul HTTP agent. The value can be
    8. an IP address or DNS address, but it must also include the port.
    9. This can also be specified via the CONSUL_HTTP_ADDR environment
    10. variable. The default value is http://127.0.0.1:8500. The scheme
    11. can also be set to HTTPS by setting the environment variable
    12. CONSUL_HTTP_SSL=true.
    13. -token=<value>
    14. ACL token to use in the request. This can also be specified via the
    15. CONSUL_HTTP_TOKEN environment variable. If unspecified, the query
    16. Command Options
    17. -wan
    18. Joins a server to another server in the WAN pool.

    When the ACL system is enabled the Consul CLI will require an to perform API requests.

    The ACL token can be provided directly on the command line using the -token command line flag, from a file using the -token-file command line flag, or from the CONSUL_HTTP_TOKEN environment variable.

    The consul command features opt-in subcommand autocompletion that you can enable for your shell with consul -autocomplete-install. After doing so, you can invoke a new shell and use the feature.

    For example, assume a tab is typed at the end of each prompt line:

    1. $ consul e
    2. event exec
    3. $ consul r
    4. reload rtt
    5. list-peers remove-peer
    1. $ consul e
    2. event exec
    3. $ consul r
    4. reload rtt
    5. $ consul operator raft
    6. list-peers remove-peer

    The CLI automatically URL-encodes arguments, which are then . To avoid double-encoding arguments, do not URL-encode arguments passed to the CLI.

    These environment variables and their purpose are described below:

    This is the HTTP API address to the local Consul agent (not the remote server) specified as a URI with optional scheme:

    1. CONSUL_HTTP_ADDR=127.0.0.1:8500
    1. CONSUL_HTTP_ADDR=127.0.0.1:8500

    or as a Unix socket path:

    1. CONSUL_HTTP_ADDR=unix:///var/run/consul_http.sock
    1. CONSUL_HTTP_ADDR=unix:///var/run/consul_http.sock

    If the https:// scheme is used, CONSUL_HTTP_SSL is implied to be true.

    CONSUL_HTTP_TOKEN

    This is the API access token required when access control lists (ACLs) are enabled, for example:

    1. CONSUL_HTTP_TOKEN=aba7cbe5-879b-999a-07cc-2efd9ac0ffe
    1. CONSUL_HTTP_TOKEN=aba7cbe5-879b-999a-07cc-2efd9ac0ffe

    CONSUL_HTTP_TOKEN_FILE

    This is a path to a file containing the API access token required when access control lists (ACLs) are enabled, for example:

    1. CONSUL_HTTP_TOKEN_FILE=/path/to/consul.token

    CONSUL_HTTP_AUTH

    This specifies HTTP Basic access credentials as a username:password pair:

    1. CONSUL_HTTP_AUTH=operations:JPIMCmhDHzTukgO6
    1. CONSUL_HTTP_AUTH=operations:JPIMCmhDHzTukgO6

    This is a boolean value (default is false) that enables the HTTPS URI scheme and SSL connections to the HTTP API:

    1. CONSUL_HTTP_SSL=true
    1. CONSUL_HTTP_SSL=true

    CONSUL_HTTP_SSL_VERIFY

    1. CONSUL_HTTP_SSL_VERIFY=false
    1. CONSUL_HTTP_SSL_VERIFY=false

    CONSUL_CACERT

    Path to a CA file to use for TLS when communicating with Consul.

    1. CONSUL_CACERT=ca.crt
    1. CONSUL_CACERT=ca.crt

    CONSUL_CAPATH

    Path to a directory of CA certificates to use for TLS when communicating with Consul.

    1. CONSUL_CAPATH=ca_certs/
    1. CONSUL_CAPATH=ca_certs/

    Path to a client cert file to use for TLS when verify_incoming is enabled.

    1. CONSUL_CLIENT_CERT=client.crt

    CONSUL_CLIENT_KEY

    Path to a client key file to use for TLS when verify_incoming is enabled.

    1. CONSUL_CLIENT_KEY=client.key
    1. CONSUL_CLIENT_KEY=client.key

    CONSUL_TLS_SERVER_NAME

    The server name to use as the SNI host when connecting via TLS.

    1. CONSUL_TLS_SERVER_NAME=consulserver.domain
    1. CONSUL_TLS_SERVER_NAME=consulserver.domain

    CONSUL_GRPC_ADDR

    Like but configures the address the local agent is listening for gRPC requests. Currently gRPC is only used for integrating Envoy proxy and must be in agent configuration.

    1. CONSUL_GRPC_ADDR=127.0.0.1:8502
    1. CONSUL_GRPC_ADDR=127.0.0.1:8502

    or as a Unix socket path:

    1. CONSUL_GRPC_ADDR=unix://var/run/consul_grpc.sock
    1. CONSUL_GRPC_ADDR=unix://var/run/consul_grpc.sock

    If the agent is configured with TLS certificates, then the gRPC listener will require TLS and present the same certificate as the https listener. As with CONSUL_HTTP_ADDR, if TLS is enabled either the https:// scheme should be used, or CONSUL_HTTP_SSL set.

      1. CONSUL_NAMESPACE=default