## Summary - Replaces 18 TeslaMate dashboard ConfigMaps (713 KB / 22,080 lines) with a Grafana init container - Init container fetches dashboard JSON directly from `mirrors/teslamate` on forge, pinned to `v3.0.0` - Grafana's file provider picks them up from `/tmp/dashboards/TeslaMate/` via `foldersFromFilesStructure` - Non-TeslaMate dashboards remain as ConfigMaps (unchanged) ## How it works - New `init-teslamate-dashboards` init container uses busybox `wget` to fetch each JSON file from `https://forge.eblu.me/mirrors/teslamate/raw/tag/v3.0.0/grafana/dashboards/` - Files land in `/tmp/dashboards/TeslaMate/`, same emptyDir volume the sidecar uses - The sidecar continues to handle ConfigMap-based dashboards; the init container handles TeslaMate - Version pin is in the init container args (TESLAMATE_VERSION) ## Deployment and Testing - [ ] Sync `grafana` app from branch — verify init container runs and fetches dashboards - [ ] Sync `grafana-config` app from branch — verify TeslaMate ConfigMaps are pruned - [ ] Check Grafana UI: TeslaMate folder should still contain all 18 dashboards - [ ] Verify non-TeslaMate dashboards are unaffected - [ ] After merge: sync both apps from main Reviewed-on: #296
221 lines
7.1 KiB
YAML
221 lines
7.1 KiB
YAML
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: grafana
|
|
namespace: monitoring
|
|
labels:
|
|
app.kubernetes.io/name: grafana
|
|
app.kubernetes.io/instance: grafana
|
|
spec:
|
|
replicas: 1
|
|
revisionHistoryLimit: 10
|
|
selector:
|
|
matchLabels:
|
|
app.kubernetes.io/name: grafana
|
|
app.kubernetes.io/instance: grafana
|
|
strategy:
|
|
type: RollingUpdate
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app.kubernetes.io/name: grafana
|
|
app.kubernetes.io/instance: grafana
|
|
annotations:
|
|
kubectl.kubernetes.io/default-container: grafana
|
|
spec:
|
|
automountServiceAccountToken: true
|
|
serviceAccountName: grafana
|
|
securityContext:
|
|
fsGroup: 472
|
|
runAsGroup: 472
|
|
runAsNonRoot: true
|
|
runAsUser: 472
|
|
initContainers:
|
|
- name: init-chown-data
|
|
image: docker.io/library/busybox:kustomized
|
|
imagePullPolicy: IfNotPresent
|
|
command: ["chown", "-R", "472:472", "/var/lib/grafana"]
|
|
securityContext:
|
|
runAsNonRoot: false
|
|
runAsUser: 0
|
|
capabilities:
|
|
add: ["CHOWN"]
|
|
seccompProfile:
|
|
type: RuntimeDefault
|
|
volumeMounts:
|
|
- name: storage
|
|
mountPath: /var/lib/grafana
|
|
# Fetch TeslaMate dashboards from forge mirror at a pinned tag.
|
|
# To upgrade: update TESLAMATE_VERSION below.
|
|
- name: init-teslamate-dashboards
|
|
image: docker.io/library/alpine:kustomized
|
|
imagePullPolicy: IfNotPresent
|
|
command: ["sh", "-c"]
|
|
args:
|
|
- |
|
|
set -e
|
|
TESLAMATE_VERSION="v3.0.0"
|
|
BASE_URL="https://forge.ops.eblu.me/mirrors/teslamate/raw/tag/${TESLAMATE_VERSION}/grafana/dashboards"
|
|
DEST="/tmp/dashboards/TeslaMate"
|
|
mkdir -p "$DEST"
|
|
for f in \
|
|
battery-health.json \
|
|
charge-level.json \
|
|
charges.json \
|
|
charging-stats.json \
|
|
drive-stats.json \
|
|
drives.json \
|
|
efficiency.json \
|
|
locations.json \
|
|
mileage.json \
|
|
overview.json \
|
|
projected-range.json \
|
|
states.json \
|
|
statistics.json \
|
|
timeline.json \
|
|
trip.json \
|
|
updates.json \
|
|
vampire-drain.json \
|
|
visited.json \
|
|
; do
|
|
wget -q -O "$DEST/$f" "$BASE_URL/$f"
|
|
done
|
|
echo "Fetched $(ls "$DEST" | wc -l) TeslaMate dashboards"
|
|
securityContext:
|
|
allowPrivilegeEscalation: false
|
|
capabilities:
|
|
drop: ["ALL"]
|
|
seccompProfile:
|
|
type: RuntimeDefault
|
|
volumeMounts:
|
|
- name: sc-dashboard-volume
|
|
mountPath: /tmp/dashboards
|
|
containers:
|
|
# Dashboard sidecar - watches ConfigMaps with grafana_dashboard=1
|
|
- name: grafana-sc-dashboard
|
|
image: registry.ops.eblu.me/blumeops/grafana-sidecar:kustomized
|
|
imagePullPolicy: IfNotPresent
|
|
env:
|
|
- name: METHOD
|
|
value: WATCH
|
|
- name: LABEL
|
|
value: grafana_dashboard
|
|
- name: LABEL_VALUE
|
|
value: "1"
|
|
- name: FOLDER
|
|
value: /tmp/dashboards
|
|
- name: RESOURCE
|
|
value: both
|
|
- name: FOLDER_ANNOTATION
|
|
value: grafana_folder
|
|
- name: REQ_USERNAME
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: grafana-admin
|
|
key: admin-user
|
|
- name: REQ_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: grafana-admin
|
|
key: admin-password
|
|
- name: REQ_URL
|
|
value: http://localhost:3000/api/admin/provisioning/dashboards/reload
|
|
- name: REQ_METHOD
|
|
value: POST
|
|
securityContext:
|
|
allowPrivilegeEscalation: false
|
|
capabilities:
|
|
drop: ["ALL"]
|
|
seccompProfile:
|
|
type: RuntimeDefault
|
|
volumeMounts:
|
|
- name: sc-dashboard-volume
|
|
mountPath: /tmp/dashboards
|
|
# Grafana
|
|
- name: grafana
|
|
image: registry.ops.eblu.me/blumeops/grafana:kustomized
|
|
imagePullPolicy: IfNotPresent
|
|
env:
|
|
- name: POD_IP
|
|
valueFrom:
|
|
fieldRef:
|
|
fieldPath: status.podIP
|
|
- name: GF_SECURITY_ADMIN_USER
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: grafana-admin
|
|
key: admin-user
|
|
- name: GF_SECURITY_ADMIN_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: grafana-admin
|
|
key: admin-password
|
|
- name: GF_PATHS_DATA
|
|
value: /var/lib/grafana/
|
|
- name: GF_PATHS_LOGS
|
|
value: /var/log/grafana
|
|
- name: GF_PATHS_PLUGINS
|
|
value: /var/lib/grafana/plugins
|
|
- name: GF_PATHS_PROVISIONING
|
|
value: /etc/grafana/provisioning
|
|
envFrom:
|
|
- secretRef:
|
|
name: grafana-teslamate-datasource
|
|
optional: true
|
|
- secretRef:
|
|
name: grafana-authentik-oauth
|
|
optional: true
|
|
ports:
|
|
- name: http
|
|
containerPort: 3000
|
|
protocol: TCP
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /api/health
|
|
port: 3000
|
|
initialDelaySeconds: 60
|
|
timeoutSeconds: 30
|
|
failureThreshold: 10
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /api/health
|
|
port: 3000
|
|
resources:
|
|
requests:
|
|
cpu: 100m
|
|
memory: 128Mi
|
|
limits:
|
|
cpu: 500m
|
|
memory: 512Mi
|
|
securityContext:
|
|
allowPrivilegeEscalation: false
|
|
capabilities:
|
|
drop: ["ALL"]
|
|
seccompProfile:
|
|
type: RuntimeDefault
|
|
volumeMounts:
|
|
- name: config
|
|
mountPath: /etc/grafana/grafana.ini
|
|
subPath: grafana.ini
|
|
- name: config
|
|
mountPath: /etc/grafana/provisioning/datasources/datasources.yaml
|
|
subPath: datasources.yaml
|
|
- name: storage
|
|
mountPath: /var/lib/grafana
|
|
- name: sc-dashboard-volume
|
|
mountPath: /tmp/dashboards
|
|
- name: sc-dashboard-provider
|
|
mountPath: /etc/grafana/provisioning/dashboards/sc-dashboardproviders.yaml
|
|
subPath: provider.yaml
|
|
volumes:
|
|
- name: config
|
|
configMap:
|
|
name: grafana
|
|
- name: storage
|
|
persistentVolumeClaim:
|
|
claimName: grafana
|
|
- name: sc-dashboard-volume
|
|
emptyDir: {}
|
|
- name: sc-dashboard-provider
|
|
configMap:
|
|
name: grafana-config-dashboards
|