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: |4 Use when working with K8S Grafana Operator — grafana Operator management for5 Kubernetes dashboard and datasource automation. Covers Grafana instances,6 GrafanaDashboard CRDs, GrafanaDatasource configurations, GrafanaFolder7 management, and operator health. Use when auditing dashboards, managing8 datasource configurations, debugging Grafana operator issues, or reviewing9 Grafana instance settings.10connection_type: k8s11preload: false12metadata:13 source: https://skillmd.com/skills/cloudthinker-ai/managing-k8s-grafana-operator14---1516# Grafana Operator Management Skill1718Manage and analyze Grafana Operator instances, dashboards, and datasource configurations.1920## MANDATORY: Discovery-First Pattern2122**Always check Grafana Operator health and Grafana instances before inspecting dashboards.**2324### Phase 1: Discovery2526```bash27#!/bin/bash2829echo "=== Grafana Operator Deployment ==="30kubectl 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/null3132echo ""33echo "=== Grafana Instances ==="34kubectl get grafana --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,AGE:.metadata.creationTimestamp' 2>/dev/null3536echo ""37echo "=== Grafana Dashboards ==="38kubectl get grafanadashboards --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,FOLDER:.spec.folder,UID:.status.uid' 2>/dev/null | head -203940echo ""41echo "=== Grafana Datasources ==="42kubectl get grafanadatasources --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,TYPE:.spec.datasource.type' 2>/dev/null | head -154344echo ""45echo "=== Grafana Folders ==="46kubectl get grafanafolders --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' 2>/dev/null | head -1547```4849### Phase 2: Analysis5051```bash52#!/bin/bash5354echo "=== Dashboard Sync Status ==="55kubectl get grafanadashboards --all-namespaces -o json 2>/dev/null | jq -r '56 .items[] |57 "\(.metadata.namespace)/\(.metadata.name)\tUID:\(.status.uid // "pending")\tHash:\(.status.hash // "none")"58' | head -205960echo ""61echo "=== Dashboards with Errors ==="62kubectl get grafanadashboards --all-namespaces -o json 2>/dev/null | jq -r '63 .items[] |64 select(.status.conditions[]? | select(.type == "Ready" and .status != "True")) |65 "\(.metadata.namespace)/\(.metadata.name)\t\(.status.conditions[] | select(.type == "Ready") | .message // "unknown error")"66' | head -106768echo ""69echo "=== Datasource Configuration Summary ==="70kubectl get grafanadatasources --all-namespaces -o json 2>/dev/null | jq -r '71 .items[] |72 "\(.metadata.namespace)/\(.metadata.name)\tType:\(.spec.datasource.type)\tURL:\(.spec.datasource.url // "default")\tAccess:\(.spec.datasource.access // "proxy")"73' | head -157475echo ""76echo "=== Grafana Instance Details ==="77kubectl get grafana --all-namespaces -o json 2>/dev/null | jq -r '78 .items[] |79 "\(.metadata.namespace)/\(.metadata.name)\tExternal:\(.spec.external // "managed")"80' | head -108182echo ""83echo "=== Grafana Pods ==="84kubectl 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/null8586echo ""87echo "=== Operator Logs (errors) ==="88OPERATOR_NS=$(kubectl get deployment -l app.kubernetes.io/name=grafana-operator --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null)89kubectl logs deployment/grafana-operator -n "$OPERATOR_NS" --tail=20 2>/dev/null | grep -i "error\|fail" | head -1090```9192## Output Format9394- Target ≤50 lines per output95- Use `-o custom-columns` for CRD listings96- Show dashboard folder hierarchy when available97- Aggregate dashboard counts by folder or namespace98- Never dump full dashboard JSON -- show name, folder, and sync status only99100## Anti-Hallucination Rules1011021. **NEVER assume resource names** — always discover via CLI/API in Phase 1 before referencing in Phase 2.1032. **NEVER fabricate metric names or dimensions** — verify against the service documentation or `--help` output.1043. **NEVER mix CLI commands between service versions** — confirm which version/API you are targeting.1054. **ALWAYS use the discovery → verify → analyze chain** — every resource referenced must have been discovered first.1065. **ALWAYS handle empty results gracefully** — an empty response is valid data, not an error to retry.107108## Counter-Rationalizations109110| Shortcut | Counter | Why |111|----------|---------|-----|112| "I'll skip discovery and check known resources" | Always run Phase 1 discovery first | Resource names change, new resources appear — assumed names cause errors |113| "The user only asked for a quick check" | Follow the full discovery → analysis flow | Quick checks miss critical issues; structured analysis catches silent failures |114| "Default configuration is probably fine" | Audit configuration explicitly | Defaults often leave logging, security, and optimization features disabled |115| "Metrics aren't needed for this" | Always check relevant metrics when available | API/CLI responses show current state; metrics reveal trends and intermittent issues |116| "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 |117118## Common Pitfalls119120- **Operator versions**: v4 vs v5 have significantly different CRD schemas -- check operator version first121- **External Grafana**: Operator can manage external Grafana instances -- check `spec.external` field122- **Dashboard source**: Dashboards can come from JSON, URL, or ConfigMap -- check `spec.source` or `spec.json`123- **Datasource secrets**: Credentials are often in Kubernetes Secrets -- verify secret references exist124- **Instance selector**: Dashboards use `instanceSelector` to target specific Grafana instances -- unmatched selectors cause silent failures125- **Multi-instance**: Multiple Grafana instances can coexist -- ensure dashboards target the correct instance126- **Folder creation**: Folders must exist before dashboards reference them -- check GrafanaFolder resources127- **Resync period**: Operator periodically resyncs -- temporary API errors may self-resolve