Grafana Operator Management Skill
Manage and analyze Grafana Operator instances, dashboards, and datasource configurations.
MANDATORY: Discovery-First Pattern
Always check Grafana Operator health and Grafana instances before inspecting dashboards.
Phase 1: Discovery
#!/bin/bash
echo "=== Grafana Operator Deployment ==="
kubectl get deployment -l app.kubernetes.io/name=grafana-operator --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,READY:.status.readyReplicas,IMAGE:.spec.template.spec.containers[0].image' 2>/dev/null
echo ""
echo "=== Grafana Instances ==="
kubectl get grafana --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,AGE:.metadata.creationTimestamp' 2>/dev/null
echo ""
echo "=== Grafana Dashboards ==="
kubectl get grafanadashboards --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,FOLDER:.spec.folder,UID:.status.uid' 2>/dev/null | head -20
echo ""
echo "=== Grafana Datasources ==="
kubectl get grafanadatasources --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,TYPE:.spec.datasource.type' 2>/dev/null | head -15
echo ""
echo "=== Grafana Folders ==="
kubectl get grafanafolders --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' 2>/dev/null | head -15
Phase 2: Analysis
#!/bin/bash
echo "=== Dashboard Sync Status ==="
kubectl get grafanadashboards --all-namespaces -o json 2>/dev/null | jq -r '
.items[] |
"\(.metadata.namespace)/\(.metadata.name)\tUID:\(.status.uid // "pending")\tHash:\(.status.hash // "none")"
' | head -20
echo ""
echo "=== Dashboards with Errors ==="
kubectl get grafanadashboards --all-namespaces -o json 2>/dev/null | jq -r '
.items[] |
select(.status.conditions[]? | select(.type == "Ready" and .status != "True")) |
"\(.metadata.namespace)/\(.metadata.name)\t\(.status.conditions[] | select(.type == "Ready") | .message // "unknown error")"
' | head -10
echo ""
echo "=== Datasource Configuration Summary ==="
kubectl get grafanadatasources --all-namespaces -o json 2>/dev/null | jq -r '
.items[] |
"\(.metadata.namespace)/\(.metadata.name)\tType:\(.spec.datasource.type)\tURL:\(.spec.datasource.url // "default")\tAccess:\(.spec.datasource.access // "proxy")"
' | head -15
echo ""
echo "=== Grafana Instance Details ==="
kubectl get grafana --all-namespaces -o json 2>/dev/null | jq -r '
.items[] |
"\(.metadata.namespace)/\(.metadata.name)\tExternal:\(.spec.external // "managed")"
' | head -10
echo ""
echo "=== Grafana Pods ==="
kubectl get pods -l app.kubernetes.io/name=grafana --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,STATUS:.status.phase,RESTARTS:.status.containerStatuses[0].restartCount' 2>/dev/null
echo ""
echo "=== Operator Logs (errors) ==="
OPERATOR_NS=$(kubectl get deployment -l app.kubernetes.io/name=grafana-operator --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null)
kubectl logs deployment/grafana-operator -n "$OPERATOR_NS" --tail=20 2>/dev/null | grep -i "error\|fail" | head -10
Output Format
- Target ≤50 lines per output
- Use
-o custom-columns for CRD listings
- Show dashboard folder hierarchy when available
- Aggregate dashboard counts by folder or namespace
- Never dump full dashboard JSON -- show name, folder, and sync status only
Anti-Hallucination Rules
- NEVER assume resource names — always discover via CLI/API in Phase 1 before referencing in Phase 2.
- NEVER fabricate metric names or dimensions — verify against the service documentation or
--help output.
- NEVER mix CLI commands between service versions — confirm which version/API you are targeting.
- ALWAYS use the discovery → verify → analyze chain — every resource referenced must have been discovered first.
- ALWAYS handle empty results gracefully — an empty response is valid data, not an error to retry.
Counter-Rationalizations
| Shortcut |
Counter |
Why |
| "I'll skip discovery and check known resources" |
Always run Phase 1 discovery first |
Resource names change, new resources appear — assumed names cause errors |
| "The user only asked for a quick check" |
Follow the full discovery → analysis flow |
Quick checks miss critical issues; structured analysis catches silent failures |
| "Default configuration is probably fine" |
Audit configuration explicitly |
Defaults often leave logging, security, and optimization features disabled |
| "Metrics aren't needed for this" |
Always check relevant metrics when available |
API/CLI responses show current state; metrics reveal trends and intermittent issues |
| "I don't have access to that" |
Try the command and report the actual error |
Assumed permission failures prevent useful investigation; actual errors are informative |
Common Pitfalls
- Operator versions: v4 vs v5 have significantly different CRD schemas -- check operator version first
- External Grafana: Operator can manage external Grafana instances -- check
spec.external field
- Dashboard source: Dashboards can come from JSON, URL, or ConfigMap -- check
spec.source or spec.json
- Datasource secrets: Credentials are often in Kubernetes Secrets -- verify secret references exist
- Instance selector: Dashboards use
instanceSelector to target specific Grafana instances -- unmatched selectors cause silent failures
- Multi-instance: Multiple Grafana instances can coexist -- ensure dashboards target the correct instance
- Folder creation: Folders must exist before dashboards reference them -- check GrafanaFolder resources
- Resync period: Operator periodically resyncs -- temporary API errors may self-resolve
1---2name: managing-k8s-grafana-operator3description: Use when working with K8S Grafana Operator — grafana Operator management for Kubernetes dashboard and datasource automation. Covers Grafana instances, GrafanaDashboard CRDs, GrafanaDatasource configurations, GrafanaFolder management, and operator health. Use when auditing dashboards, managing datasource configurations, debugging Grafana operator issues, or reviewing Grafana instance settings.4---56# Grafana Operator Management Skill78Manage and analyze Grafana Operator instances, dashboards, and datasource configurations.910## MANDATORY: Discovery-First Pattern1112**Always check Grafana Operator health and Grafana instances before inspecting dashboards.**1314### Phase 1: Discovery1516```bash17#!/bin/bash1819echo "=== Grafana Operator Deployment ==="20kubectl get deployment -l app.kubernetes.io/name=grafana-operator --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,READY:.status.readyReplicas,IMAGE:.spec.template.spec.containers[0].image' 2>/dev/null2122echo ""23echo "=== Grafana Instances ==="24kubectl get grafana --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,AGE:.metadata.creationTimestamp' 2>/dev/null2526echo ""27echo "=== Grafana Dashboards ==="28kubectl get grafanadashboards --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,FOLDER:.spec.folder,UID:.status.uid' 2>/dev/null | head -202930echo ""31echo "=== Grafana Datasources ==="32kubectl get grafanadatasources --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,TYPE:.spec.datasource.type' 2>/dev/null | head -153334echo ""35echo "=== Grafana Folders ==="36kubectl get grafanafolders --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' 2>/dev/null | head -1537```3839### Phase 2: Analysis4041```bash42#!/bin/bash4344echo "=== Dashboard Sync Status ==="45kubectl get grafanadashboards --all-namespaces -o json 2>/dev/null | jq -r '46 .items[] |47 "\(.metadata.namespace)/\(.metadata.name)\tUID:\(.status.uid // "pending")\tHash:\(.status.hash // "none")"48' | head -204950echo ""51echo "=== Dashboards with Errors ==="52kubectl get grafanadashboards --all-namespaces -o json 2>/dev/null | jq -r '53 .items[] |54 select(.status.conditions[]? | select(.type == "Ready" and .status != "True")) |55 "\(.metadata.namespace)/\(.metadata.name)\t\(.status.conditions[] | select(.type == "Ready") | .message // "unknown error")"56' | head -105758echo ""59echo "=== Datasource Configuration Summary ==="60kubectl get grafanadatasources --all-namespaces -o json 2>/dev/null | jq -r '61 .items[] |62 "\(.metadata.namespace)/\(.metadata.name)\tType:\(.spec.datasource.type)\tURL:\(.spec.datasource.url // "default")\tAccess:\(.spec.datasource.access // "proxy")"63' | head -156465echo ""66echo "=== Grafana Instance Details ==="67kubectl get grafana --all-namespaces -o json 2>/dev/null | jq -r '68 .items[] |69 "\(.metadata.namespace)/\(.metadata.name)\tExternal:\(.spec.external // "managed")"70' | head -107172echo ""73echo "=== Grafana Pods ==="74kubectl get pods -l app.kubernetes.io/name=grafana --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,STATUS:.status.phase,RESTARTS:.status.containerStatuses[0].restartCount' 2>/dev/null7576echo ""77echo "=== Operator Logs (errors) ==="78OPERATOR_NS=$(kubectl get deployment -l app.kubernetes.io/name=grafana-operator --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null)79kubectl logs deployment/grafana-operator -n "$OPERATOR_NS" --tail=20 2>/dev/null | grep -i "error\|fail" | head -1080```8182## Output Format8384- Target ≤50 lines per output85- Use `-o custom-columns` for CRD listings86- Show dashboard folder hierarchy when available87- Aggregate dashboard counts by folder or namespace88- Never dump full dashboard JSON -- show name, folder, and sync status only8990## Anti-Hallucination Rules91921. **NEVER assume resource names** — always discover via CLI/API in Phase 1 before referencing in Phase 2.932. **NEVER fabricate metric names or dimensions** — verify against the service documentation or `--help` output.943. **NEVER mix CLI commands between service versions** — confirm which version/API you are targeting.954. **ALWAYS use the discovery → verify → analyze chain** — every resource referenced must have been discovered first.965. **ALWAYS handle empty results gracefully** — an empty response is valid data, not an error to retry.9798## Counter-Rationalizations99100| Shortcut | Counter | Why |101|----------|---------|-----|102| "I'll skip discovery and check known resources" | Always run Phase 1 discovery first | Resource names change, new resources appear — assumed names cause errors |103| "The user only asked for a quick check" | Follow the full discovery → analysis flow | Quick checks miss critical issues; structured analysis catches silent failures |104| "Default configuration is probably fine" | Audit configuration explicitly | Defaults often leave logging, security, and optimization features disabled |105| "Metrics aren't needed for this" | Always check relevant metrics when available | API/CLI responses show current state; metrics reveal trends and intermittent issues |106| "I don't have access to that" | Try the command and report the actual error | Assumed permission failures prevent useful investigation; actual errors are informative |107108## Common Pitfalls109110- **Operator versions**: v4 vs v5 have significantly different CRD schemas -- check operator version first111- **External Grafana**: Operator can manage external Grafana instances -- check `spec.external` field112- **Dashboard source**: Dashboards can come from JSON, URL, or ConfigMap -- check `spec.source` or `spec.json`113- **Datasource secrets**: Credentials are often in Kubernetes Secrets -- verify secret references exist114- **Instance selector**: Dashboards use `instanceSelector` to target specific Grafana instances -- unmatched selectors cause silent failures115- **Multi-instance**: Multiple Grafana instances can coexist -- ensure dashboards target the correct instance116- **Folder creation**: Folders must exist before dashboards reference them -- check GrafanaFolder resources117- **Resync period**: Operator periodically resyncs -- temporary API errors may self-resolve