Skip to content

Loki cli

๐Ÿš€ How to Install and Use Loki CLIยถ

Loki CLI (loki-canary or logcli) is a command-line tool for querying logs from a Loki server. It is useful for troubleshooting, automation, and quick log access from your terminal.


๐Ÿ› ๏ธ Installationยถ

Choose the method that fits your environment

Using Prebuilt Binariesยถ

  1. Go to the Loki releases page.
  2. Download the latest logcli binary for your OS.
  3. Unpack and move it to a directory in your $PATH:

    tar -xzf logcli-<version>-<os>-amd64.zip
    sudo mv logcli /usr/local/bin/
    

Using Homebrew (macOS/Linux)ยถ

brew install grafana/tap/logcli

Using Dockerยถ

docker run --rm -it grafana/logcli:latest --help

โšก Basic Usageยถ

Prerequisites

  • Access to your Kubernetes cluster with Loki installed
  • kubectl access and permissions to port-forward the Loki service

Port-forward Loki Serviceยถ

Before running logcli, open a port-forward to your Loki service:

kubectl -n loki port-forward svc/loki 3100:3100

Query Logsยถ

logcli --addr="http://localhost:3100" query '{job="your-job"}' --limit=20

Example: Query logs for a Kubernetes podยถ

logcli --addr="http://localhost:3100" query '{namespace="sia-service", pod="sia-api-1234"}' --limit=50

Tail Logs (live)ยถ

logcli --addr="http://localhost:3100" tail '{namespace="sia-service"}'

Export Logs to Fileยถ

logcli --addr="http://localhost:3100" query '{namespace="sia-service"}' --limit=1000 > logs.txt

๐Ÿ” Authenticationยถ

No Authentication Required

By default, Loki in this environment does not require authentication when accessed via kubectl port-forward.


๐Ÿงฉ Common Troubleshootingยถ

Connection Issues

  • Ensure you are connected to the correct Kubernetes cluster.
  • Make sure the port-forward is active and running in a terminal:

    kubectl -n loki port-forward svc/loki 3100:3100
    
  • All logcli commands should use --addr="http://localhost:3100".

TLS/SSL

Loki is accessed over HTTP (not HTTPS) when using port-forward. No TLS/SSL flags are needed.


๐Ÿ“š Referencesยถ