Logs and events

best practices

  1. use gitops - argocd for kubernetes deployments

  2. add persistent volume for loki and grafana

By default, if you don’t enable persistence for Loki, it stores logs only in the container’s ephemeral storage. (That means any pod restart or node restart will lose logs.)

chevron-rightAdd persistent storagehashtag

loki:
  persistence:
    enabled: true
    storageClassName: ebs-csi        # your EKS storage class
    size: 50Gi                        # adjust based on log volume
    accessModes:
      - ReadWriteOnce

  1. add retention policy

chevron-rightpolicyhashtag
loki:
  config:
    table_manager:
      retention_deletes_enabled: true
      retention_period: 7d

we are collecting pods logs using promtail here

here is our helm setup

chevron-rightReadme.mdhashtag


helm show values grafana/loki-stack > values.yamlhelm install loki 

helm repo add grafana https://grafana.github.io/helm-charts


helm install loki grafana/loki-stack -f values.yml --set promtail.enabled=true -n monitoring --create-namespace

helm list -n monitoring

kubectl get pods -n monitoring

helm upgrade loki grafana/loki-stack -f values.yaml --set promtail.enabled=true -n monitoring 

Access grafana using Cloudflared tunnel

add service <service-name>.<namespace>:port

# get grafana password
kubectl get secret loki-grafana -n monitoring -o jsonpath="{.data.admin-password}" | base64 --decode

chevron-rightValues.ymlhashtag

updated values.yml

chevron-rightvalues.ymlhashtag

pesistent volume

chevron-rightstorageclasshashtag

sc-ebs3,yml

kubectl apply -f ebs-gp3-expandable.yaml

storageclass.storage.k8s.io/ebs-gp3-expandable created

this Storage class automatically provision new ebs for pod if we call it

use in pod helm values.yml

Redeploy Loki & Grafana

Because StatefulSets don’t allow changing PVC storageClass, you’ll need to recreate Loki & Grafana PVCs:

if i do this i will loose all my custom dashboards in grafana can i keep grafana as it is i am ok if i loose loki data

Exactly ✅ you spotted the key point.

  • Grafana PVC holds your dashboards, users, and settings. If you delete that PVC, you’ll lose all custom dashboards.

  • Loki PVC only holds logs (which are ephemeral by nature) — safe to lose if you’re okay with resetting log history.

So yes, you can keep Grafana as-is and only redeploy Loki.

do not update ebs driver is grafana keep old one for our old backup/data

safe

delete only loki

kubectl scale sts loki --replicas=0 -n monitoring kubectl delete sts loki -n monitoring

redeploy

helm upgrade --install loki grafana/loki-stack -f values.yml -n monitoring

now we have pvc created for loki as well

filter logs by json

chevron-rightfilter logs for alerthashtag

chevron-rightworking queryhashtag

above command just highlight show full logs where status is 400

chevron-rightKubernetes Event by Prom tailhashtag

our grafana/loki-stack helm chart support service account

we need service account to trust promtail pod to give access to Kubernetes api via role and clusterrolebinding

kubectl get clusterrole,clusterrolebinding -A | grep promtail

clusterrole.rbac.authorization.k8s.io/loki-promtail 2025-01-29T09:59:00Z clusterrolebinding.rbac.authorization.k8s.io/loki-promtail

oki-Grafana (main) $ kubectl describe clusterrole loki-promtail Name: loki-promtail Labels: app.kubernetes.io/instance=loki app.kubernetes.io/managed-by=Helm app.kubernetes.io/name=promtail app.kubernetes.io/version=2.9.3 helm.sh/chart=promtail-6.15.5 Annotations: meta.helm.sh/release-name: loki meta.helm.sh/release-namespace: monitoring PolicyRule: Resources Non-Resource URLs Resource Names Verbs


endpoints [] [] [get watch list] nodes/proxy [] [] [get watch list] nodes [] [] [get watch list] pods [] [] [get watch list] services [] [] [get watch list]

step 1

kubectl apply -f promtail-events-rbac.yaml

(This gives the loki-promtail ServiceAccount permission to watch both legacy and events.k8s.io events.)

chevron-rightSteps to collect event by promtailhashtag

Perfect 👍 you already confirmed that the Helm chart created ServiceAccounts for:

  • Grafanaloki-grafana

  • Lokiloki

  • Promtailloki-promtail

So yes — the chart does handle ServiceAccounts automatically.

Now the missing piece is: RBAC rules. ServiceAccounts by themselves don’t have permissions. Promtail needs ClusterRole + ClusterRoleBinding so it can get, list, watch things like Pods, Namespaces, and Events.


🔍 How to check RBAC created by Helm

Run:

You should see something like:

Then inspect:

Expected rules include:


✅ If events is missing

If your loki-promtail ClusterRole doesn’t include events, you need to extend it. You can do this either by:

  1. Editing values.yaml Some Helm charts expose RBAC rules as configurable (check with:

    and search for rbac).

  2. Creating a custom ClusterRole patch For example:

    Apply it with kubectl apply -f.


👉 Do you want me to write you the final Promtail values.yaml snippet (with config + RBAC for events) so you can drop it into your Helm setup? That way you won’t need to manually patch later.

Last updated