feat(grafana): sidecar for loading dashboards from configmap

!1
This commit is contained in:
2023-09-24 06:38:04 +09:30
parent 82cd91a859
commit 8f53b0fa07
5 changed files with 137 additions and 31 deletions

View File

@ -0,0 +1,18 @@
{{ if .Values.nfc_monitoring.additions.dashboard_sidecar.enabled -}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/component: graphing
app.kubernetes.io/instance: k8s
app.kubernetes.io/name: grafana
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
app.kubernetes.io/version: {{ $.Chart.Version }}
name: Grafana-Sidecar
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "watch", "list"]
{{- end }}

View File

@ -0,0 +1,22 @@
{{ if .Values.nfc_monitoring.additions.dashboard_sidecar.enabled -}}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
labels:
app.kubernetes.io/component: graphing
app.kubernetes.io/instance: k8s
app.kubernetes.io/name: grafana
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
app.kubernetes.io/version: {{ $.Chart.Version }}
name: Grafana-Sidecar
roleRef:
kind: ClusterRole
name: Grafana-Sidecar
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: grafana
namespace: "{{ .Values.nfc_monitoring.grafana.namespace }}"
{{- end }}

View File

@ -0,0 +1,31 @@
{{ if .Values.nfc_monitoring.additions.dashboard_sidecar.enabled -}}
---
# Provisioning config
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: graphing
app.kubernetes.io/instance: k8s
app.kubernetes.io/name: grafana
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
app.kubernetes.io/version: {{ $.Chart.Version }}
name: provisioning-config
namespace: "{{ .Values.nfc_monitoring.grafana.namespace }}"
data:
provisioning.yaml: |-
apiVersion: 1
providers:
- name: 'configmap-dashboard-provider'
orgId: 1
folder: ''
folderUid: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: true
{{- end }}

View File

@ -55,6 +55,9 @@ spec:
spec: spec:
affinity: affinity:
{{- toYaml .Values.nfc_monitoring.grafana.affinity | nindent 12 }} {{- toYaml .Values.nfc_monitoring.grafana.affinity | nindent 12 }}
{{ if .Values.nfc_monitoring.additions.dashboard_sidecar.enabled }}
automountServiceAccountToken: true
{{ end }}
containers: containers:
- name: grafana - name: grafana
image: "{{ .Values.nfc_monitoring.grafana.image.name }}:{{ .Values.nfc_monitoring.grafana.image.tag }}" image: "{{ .Values.nfc_monitoring.grafana.image.name }}:{{ .Values.nfc_monitoring.grafana.image.tag }}"
@ -95,9 +98,33 @@ spec:
- mountPath: /etc/grafana/provisioning/plugins - mountPath: /etc/grafana/provisioning/plugins
name: plugin-config name: plugin-config
readOnly: false readOnly: false
{{ if .Values.nfc_monitoring.additions.dashboard_sidecar.enabled }}
- mountPath: /etc/grafana/provisioning/dashboards
name: provisioning-config
- mountPath: /var/lib/grafana/dashboards
name: dashboards
- image: "{{ .Values.nfc_monitoring.additions.dashboard_sidecar.image.name }}:{{ .Values.nfc_monitoring.additions.dashboard_sidecar.image.tag}}"
name: k8s-sidecar
env:
- name: LABEL
value: "{{ .Values.nfc_monitoring.additions.dashboard_sidecar.label_name }}"
- name: LABEL_VALUE
value: "{{ .Values.nfc_monitoring.additions.dashboard_sidecar.label_value }}"
- name: FOLDER
value: /var/lib/grafana/dashboards
- name: NAMESPACE
value: grafana
- name: RESOURCE
value: configmap
volumeMounts:
- mountPath: /var/lib/grafana/dashboards
name: dashboards
{{ end }}
securityContext:
fsGroup: 65534
volumes: volumes:
- name: grafana-storage #- name: grafana-storage
emptyDir: {}
- name: plugin-config - name: plugin-config
configMap: configMap:
# Provide the name of the ConfigMap you want to mount. # Provide the name of the ConfigMap you want to mount.
@ -106,35 +133,31 @@ spec:
items: items:
- key: "oncall-app.yaml" - key: "oncall-app.yaml"
path: "oncall-app.yaml" path: "oncall-app.yaml"
# - volumeClaimTemplates: {{ if .Values.nfc_monitoring.additions.dashboard_sidecar.enabled }}
# - metadata: - name: dashboards
# name: data emptyDir: {}
# labels: - name: provisioning-config
# app.kubernetes.io/name: loki configMap:
# app.kubernetes.io/component: logging name: provisioning-config
# app.kubernetes.io/part-of: {{ $.Chart.Name }} {{ end }}
# app.kubernetes.io/version: {{ $.Chart.Version }} - name: grafana-storage
# app.kubernetes.io/managed-by: {{ $.Release.Service }} ephemeral:
# spec: volumeClaimTemplate:
# accessModes: metadata:
# - "ReadWriteOnce" annotations:
# resources: pv.beta.kubernetes.io/gid: "65534"
# requests: labels:
# storage: "5Gi" app.kubernetes.io/name: grafana
app.kubernetes.io/component: graphing
app.kubernetes.io/part-of: {{ $.Chart.Name }}
app.kubernetes.io/version: {{ $.Chart.Version }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
spec:
accessModes:
- "ReadWriteMany"
resources:
requests:
storage: "5Gi"
serviceAccountName: grafana serviceAccountName: grafana
nodeSelector: nodeSelector:
kubernetes.io/os: linux kubernetes.io/os: linux
# persistentVolumeClaim:
# metadata:
# labels:
# app.kubernetes.io/component: graphing
# app.kubernetes.io/instance: k8s
# app.kubernetes.io/name: grafana
# app.kubernetes.io/managed-by: {{ $.Release.Service }}
# app.kubernetes.io/part-of: {{ $.Chart.Name }}
# app.kubernetes.io/version: {{ $.Chart.Version }}
# spec:
# resources:
# requests:
# storage: "5Gi"

View File

@ -195,6 +195,18 @@ nfc_monitoring:
matchLabels: matchLabels:
app: rook-ceph-mgr app: rook-ceph-mgr
# Add sidcar to grafana pod to load dashboards from configMap
dashboard_sidecar:
enabled: true
image:
name: ghcr.io/kiwigrid/k8s-sidecar
tag: '1.24.5'
label_name: grafana_dashboard
label_value: "1"
loki_instance: loki_instance:
image: image: