Promtail + Loki + Grafana

The key component in this stack is Loki. Loki has a set of components which are internally referred to as modules. Each component spawns a gRPC server for internal traffic and an HTTP/1 server for external API requests.

There are two ways to deploy Loki, monolithic mode and microservices mode.

Monolithic mode (single process mode)

Monolithic mode (single process mode) is ideally suited for local development, small workloads, and for evaluation purposes.

Prerequisites

  • Make sure KALM installed to your cluster.
  • Make sure you have kubectl and configure to your cluster.
  • Make sure your cluster has at least 500m cpu and 800Mi memory (each node has at least 100m cpu and 100Mi) to install PLG.

Install PLG on KALM

Run the following command to install monolithic mode plg. In the future, this step will be able to be done through web interface.

kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
name: my-first-log-app
labels:
istio-injection: enabled
kalm-enabled: "true"
---
apiVersion: core.kalm.dev/v1alpha1
kind: LogSystem
metadata:
name: plg
namespace: my-first-log-app
spec:
stack: plg-monolithic
plgConfig:
loki:
retentionDays: 7
diskSize: 1Gi
storageClass: standard
image: grafana/loki:1.6.0
grafana:
image: grafana/grafana:6.7.0
promtail:
image: grafana/promtail:1.6.0
EOF

View & Query logs

kubectl -n my-first-log-app port-forward $(kubectl get pods -n my-first-log-app -l app=plg-grafana -o jsonpath="{.items[].metadata.name}") 3000:3000

Open http://localhost:3000 in browser, and go to explore page. You can use label to filter logs you want. The query language here is called LogQL.

Let's view grafana log for demo by visiting this link.

note

Don't worry about the permission. As long as you don't give it a route, it will be only accessible locally with port-forward. External access with permissions is under development.

guide-logging-for-kalm3.png

Cleanup

After test, you can run the following command to clean up the test logging system. If you are using cloud platform, you need also delete generated Disks to avoid unexpected charge.

kubectl delete logsystems.core.kalm.dev -n my-first-log-app plg

Microservices mode

note

Working in progress.

Last updated on by david