22/07/2026

K8s – Grafana pre-built dashboards

Herhangi bir deployment ile grafana ya otomatik olarak dashboardlarimizi ekleyebiliriz. Bir önceki postumda zaten prometheus a baglanmistik ve prometheus-grafana-kube stack icinde grafana da zaten hazir geliyor.

bize kalan sadece 2 3 tane dosyayi hazirlamak.

values.yaml

grafanaDashboard:
  # -- If true creates a Grafana dashboard.
  enabled: true

  # -- Label that ConfigMaps should have to be loaded as dashboards.
  sidecarLabel: "grafana_dashboard"
  # -- Label value that ConfigMaps should have to be loaded as dashboards.
  sidecarLabelValue: "1"

  # -- Annotations that ConfigMaps can have to get configured in Grafana,
  # See: sidecar.dashboards.folderAnnotation for specifying the dashboard folder.
  # https://github.com/grafana/helm-charts/tree/main/charts/grafana
  annotations: {}

  # -- Extra labels to a

sonra templates altina

grafana-dashboard.yaml

{{- if .Values.grafanaDashboard.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "ttt.namespace" . }}-dashboard
  namespace: {{ include "ttt.namespace" . }}
  labels:
    {{ .Values.grafanaDashboard.sidecarLabel }}: {{ .Values.grafanaDashboard.sidecarLabelValue | quote }}
    {{- include "ttt.labels" . | nindent 4 }}
    {{- include "ttt.selectorLabels" . | nindent 4 }}
    {{- with .Values.grafanaDashboard.extraLabels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.grafanaDashboard.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
data:
#  {{ include "ttt.namespace" . }}.json: |
  grafana-dashboard.json: |
    {{ tpl (.Files.Get "dashboards/grafana-dashboard.json" ) . | nindent 4 }}
{{- end }}

Bu kismi biraz inceleyelim

  • include lari biliyoruz helpers.tpl den geliyor.
  • {{ .Values.grafanaDashboard.sidecarLabel }}: {{ .Values.grafanaDashboard.sidecarLabelValue | quote }}
    • values dan cözüldügü zaman grafana_dashboard: “1” oluyor ki bu bir cesit enable komutu
  • en önemli kisim surasi :
grafana-dashboard.json: |
    {{ tpl (.Files.Get "dashboards/grafana-dashboard.json" ) . | nindent 4 }}
  • burada grafana-dashboard.json diye bir json datasi olusturuyoruz cünkü grafana json tipinde veri aliyor. Sonra tpl ile helpers.tpl deki datanin cözülmesini sagliyoruz bu json i okurken.
    • bunu birazdan asagida ki json datasinda görecegiz.

grafana-dashboard.json:

{
  "annotations": {
    "list": []
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "refresh": "5s",
  "schemaVersion": 39,
  "tags": [
    "{{ .Release.Namespace }}"
  ],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-5m",
    "to": "now"
  },
  "timezone": "browser",
  "title": "Application - {{ .Release.Name }}",
  "uid": "app-{{ .Release.Name }}",
  "version": 1,
  "panels": [
    {{ tpl (.Files.Get "dashboards/panels/uptime.json.tpl") . }},
    {{ tpl (.Files.Get "dashboards/panels/memory.json.tpl") . }}
  ]
}

Burada tags ve Panels en önemli kisim. Onlara deginecegiz ama kisaca

  • editable : true –> Kullanicilar panel ile oynayabilirler web arayüzünde.
  • templating –> "list": [ { "name": "namespace", ... } ]
    • gibi olup degisken ekleyebiliriz.

Tags : grafana yi actigimizda bir sürü dashboard görebiliriz tag bulmamizi kolaylastiran bir etiket olusturuyor.

Panels: gerekli paneli alip tpl ile degiskenleri cözümleyip kullaniyor. Böylece tek dosyada 1000 satir olmuyor.