Consul login to get health status via CLI

I would like to get a CLI-equivalent listing of ui/dc1/services/consul/instances, but I am getting tripped up by consul login:
(Im not even sure if a login is require to retrieve this status?)

export CONSUL_HTTP_TOKEN="12345678-abcd-efgh-ijkl-123456789012"
export CONSUL_HTTP_ADDR="https://consul.k8s.example.com:8501/"
export CONSUL_HTTP_SSL_VERIFY="false"
export CONSUL_HTTP_SSL="true"
consul login -method=token -token-sink-file=/tmp/consul.token

Missing required ‘-bearer-token-file’ flag

The docs says

-bearer-token-file=<string> Path to a file containing a secret bearer token to use with this auth method.

but it seems like the word “token” is overloaded in this case? I mean, Im already supplying an auth token as an ENV (arent I?), which I assumed was a bearer token (in a different format), so … what is it looking for?

Hi @sbirl - consul login is used to provision ACL tokens whenever you’d need one. In this case you already have one so you can just proceed without that step.
To answer your question about the bearer-token this is a JWT token associated with your identity such as the JWT token for a Kubernetes ServiceAccount as an example.
The -token-sink-file would be your output file which would contain the ACL token produced by a successful consul login.

Thanks for the information @kschoche!

Oh joy! Not even the correct command then! :person_facepalming:

The real question is the first part of the first sentence:

I would like to get a CLI-equivalent listing of ui/dc1/services/consul/instances

So, how can I do that?
Thanks.

Hi @sbirl !

Unfortunately that ui endpoint actually makes several API calls in to consul and then constructs that page from it.
It is issuing these calls:

/v1/health/service/:service
/v1/catalog/connect/:service
/v1/discovery-chain/:service

You can probably get most of the information you’re looking for from the
/v1/health/service/:service endpoint.

Unfortunately there isn’t a single CLI command that displays this information in the same way the UI does, but you may find some of the info via the CLI with consul catalog services.

I hope that helps!
~Kyle

1 Like