Querying LOKI using LogCLI in Kubernetes cluster

7/19/2021

I am trying to query LOKI using LogCLI, but each time I try to query it, I get error stating Query failed: "Get http://...": dial tcp <ip_address>: connect: connection refused" I have installed loki using helm chart and created ingress service to expose it. Steps used to install loki:

$ helm repo add grafana https://grafana.github.io/helm-charts
"grafana" has been added to your repositories

$ helm repo update
...
Update Complete. ⎈Happy Helming!⎈

$ helm upgrade --install loki grafana/loki-stack


$ kubectl get pods | grep loki
loki-0                            1/1     Running   0          76s
loki-promtail-hm8kn               1/1     Running   0          76s
loki-promtail-nkv4p               1/1     Running   0          76s
loki-promtail-qfrcr               1/1     Running   0          76s

Ingress service yaml file:

$ cat ingress.yml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: loki-ingress
spec:
  rules:
    - http:
        paths:
          - backend:
              serviceName: loki
              servicePort: 3100
            path: /

$ kubectl get ing
NAME           CLASS    HOSTS   ADDRESS        PORTS   AGE
loki-ingress   <none>   *       10.128.0.6     80      7h

$ kubectl get svc
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes               ClusterIP   10.96.0.1        <none>        443/TCP          21h
loki                     ClusterIP   10.128.219.87    <none>        3100/TCP         16h
loki-headless            ClusterIP   None             <none>        3100/TCP         16h

And currently I am trying to access loki logs using:

$ export LOKI_ADDR="http://10.128.0.6"
$ logcli query '{app="events-collector"}'
http://10.128.0.6/loki/api/v1/query_range?direction=BACKWARD&end=1626690093532398790&limit=30&query=%7Bapp%3D%22events-collector%22%7D&start=1626686493532398790
Query failed: Get "http://10.128.0.6/loki/api/v1/query_range?direction=BACKWARD&end=1626690093532398790&limit=30&query=%7Bapp%3D%22events-collector%22%7D&start=1626686493532398790": dial tcp 10.128.0.6:80: connect: connection refused

How to query Loki in this case?

-- Dragnoid99
google-kubernetes-engine
grafana-loki
kubernetes
kubernetes-helm

0 Answers