Bird
Raised Fist0
Kubernetesdevops~30 mins

Grafana for visualization in Kubernetes - Mini Project: Build & Apply

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Grafana for visualization
📖 Scenario: You are working in a team that manages a Kubernetes cluster. You want to visualize the cluster's CPU usage using Grafana. To do this, you will deploy Grafana in the cluster and configure it to display CPU metrics.
🎯 Goal: Deploy Grafana on Kubernetes and configure it to visualize CPU usage metrics.
📋 What You'll Learn
Create a Kubernetes deployment for Grafana with the exact name grafana-deployment.
Create a Kubernetes service named grafana-service to expose Grafana on port 3000.
Add a ConfigMap named grafana-config with a basic Grafana configuration.
Print the command to get the Grafana service URL.
💡 Why This Matters
🌍 Real World
Grafana is widely used to visualize metrics from Kubernetes clusters and other systems. This project shows how to deploy and expose Grafana in a Kubernetes environment.
💼 Career
Understanding how to deploy monitoring tools like Grafana on Kubernetes is a key skill for DevOps engineers and site reliability engineers.
Progress0 / 4 steps
1
Create Grafana Deployment
Create a Kubernetes deployment named grafana-deployment with one replica. Use the image grafana/grafana:latest. Set the container port to 3000.
Kubernetes
Hint

Use kind: Deployment and specify replicas: 1. Set the container image and port exactly as instructed.

2
Create Grafana Service
Create a Kubernetes service named grafana-service of type NodePort that exposes port 3000 and targets the deployment with label app: grafana.
Kubernetes
Hint

Use kind: Service with type: NodePort. Match the selector label to the deployment's label.

3
Add Grafana ConfigMap
Create a ConfigMap named grafana-config with a key grafana.ini containing the text [server]\nhttp_port = 3000.
Kubernetes
Hint

Use kind: ConfigMap and add the key grafana.ini with the exact content.

4
Display Grafana Service URL
Write the command to get the NodePort of the grafana-service and print the full URL assuming the cluster node IP is 192.168.99.100. The output should be exactly: http://192.168.99.100:PORT where PORT is the NodePort number.
Kubernetes
Hint

Use kubectl get service grafana-service -o jsonpath={.spec.ports[0].nodePort} to get the NodePort. Then print the URL with the given IP.

Practice

(1/5)
1. What is the main purpose of Grafana in a Kubernetes environment?
easy
A. To visualize and monitor data from Kubernetes clusters
B. To deploy applications automatically
C. To manage Kubernetes user permissions
D. To store container images

Solution

  1. Step 1: Understand Grafana's role

    Grafana is a tool designed to create visual dashboards from data sources.
  2. Step 2: Connect Grafana to Kubernetes data

    In Kubernetes, Grafana connects to metrics sources to visualize cluster health and performance.
  3. Final Answer:

    To visualize and monitor data from Kubernetes clusters -> Option A
  4. Quick Check:

    Grafana = Visualization and Monitoring [OK]
Hint: Grafana = Visualize data, not deploy or store [OK]
Common Mistakes:
  • Confusing Grafana with deployment tools
  • Thinking Grafana manages permissions
  • Assuming Grafana stores images
2. Which Kubernetes resource is commonly used to deploy Grafana?
easy
A. Pod
B. Deployment
C. ConfigMap
D. ServiceAccount

Solution

  1. Step 1: Identify deployment method

    Grafana runs as an application that needs to be managed and scaled.
  2. Step 2: Choose Kubernetes resource for managing apps

    Deployments manage pods and allow updates and scaling.
  3. Final Answer:

    Deployment -> Option B
  4. Quick Check:

    Deployments = Manage app lifecycle [OK]
Hint: Use Deployment to run and scale Grafana pods [OK]
Common Mistakes:
  • Using Pod directly without Deployment
  • Confusing ConfigMap with deployment
  • Thinking ServiceAccount deploys apps
3. Given this snippet of a Grafana dashboard JSON, what type of visualization will it create?
{
  "panels": [
    {
      "type": "graph",
      "title": "CPU Usage"
    }
  ]
}
medium
A. A graph chart displaying CPU usage over time
B. A table showing CPU usage data
C. A text panel with CPU usage summary
D. A heatmap of CPU usage

Solution

  1. Step 1: Identify panel type in JSON

    The panel type is "graph", which means a line or bar chart.
  2. Step 2: Match visualization to type

    Graph panels show data trends over time, suitable for CPU usage.
  3. Final Answer:

    A graph chart displaying CPU usage over time -> Option A
  4. Quick Check:

    Panel type 'graph' = Chart visualization [OK]
Hint: Panel type 'graph' means line/bar chart [OK]
Common Mistakes:
  • Confusing 'graph' with 'table'
  • Assuming 'graph' means text
  • Mixing heatmap with graph
4. You deployed Grafana on Kubernetes but the dashboard shows no data. Which fix is most likely correct?
medium
A. Increase the CPU limits of the Grafana pod
B. Restart the Kubernetes cluster
C. Check if the data source is configured and connected properly
D. Delete the Grafana deployment and recreate it

Solution

  1. Step 1: Identify cause of no data in Grafana

    No data usually means Grafana cannot read from its data source.
  2. Step 2: Verify data source configuration

    Ensure the data source (like Prometheus) is added and reachable in Grafana settings.
  3. Final Answer:

    Check if the data source is configured and connected properly -> Option C
  4. Quick Check:

    No data = Check data source connection [OK]
Hint: No data? Verify data source setup first [OK]
Common Mistakes:
  • Restarting cluster unnecessarily
  • Deleting deployment without checking config
  • Changing CPU limits unrelated to data
5. You want to create a Grafana dashboard that shows CPU and memory usage side by side for multiple Kubernetes nodes. Which approach is best?
hard
A. Use a text panel describing CPU and memory usage
B. Use a single panel with combined CPU and memory metrics in one graph
C. Create separate dashboards for CPU and memory usage
D. Create a dashboard JSON with two panels: one for CPU and one for memory, each querying node metrics

Solution

  1. Step 1: Understand dashboard layout needs

    Side by side means multiple panels on one dashboard.
  2. Step 2: Design panels for each metric

    Create one panel for CPU and another for memory, each querying node metrics separately.
  3. Step 3: Avoid combining unrelated metrics in one graph

    Separate panels improve clarity and comparison.
  4. Final Answer:

    Create a dashboard JSON with two panels: one for CPU and one for memory, each querying node metrics -> Option D
  5. Quick Check:

    Separate panels = Clear side-by-side view [OK]
Hint: Use separate panels for different metrics side by side [OK]
Common Mistakes:
  • Combining CPU and memory in one confusing graph
  • Making separate dashboards instead of one
  • Using text panels instead of graphs