1. Answers
  2. Visualizing Pod Metrics With Grafana Dashboards

Visualizing Pod Metrics With Grafana Dashboards

Introduction

In this guide, we will set up a Grafana dashboard to visualize pod metrics in a Kubernetes cluster. We will use Pulumi to provision the necessary resources on AWS. The key services involved are Amazon EKS for the Kubernetes cluster, Prometheus for metrics collection, and Grafana for visualization.

Step-by-Step Explanation

Step 1: Set Up the EKS Cluster

  1. Provision an EKS Cluster: Use Pulumi to create an Amazon EKS cluster.
  2. Create Node Group: Add a node group to the EKS cluster to run the pods.

Step 2: Deploy Prometheus

  1. Install Prometheus: Use Helm to deploy Prometheus in the EKS cluster.
  2. Configure Prometheus: Set up Prometheus to scrape metrics from the Kubernetes pods.

Step 3: Deploy Grafana

  1. Install Grafana: Use Helm to deploy Grafana in the EKS cluster.
  2. Configure Grafana: Set up Grafana to use Prometheus as a data source.
  3. Create Dashboards: Create Grafana dashboards to visualize the pod metrics.

Conclusion

By following these steps, you will have a fully functional Grafana dashboard that visualizes pod metrics in your Kubernetes cluster. This setup leverages Amazon EKS for the Kubernetes cluster, Prometheus for metrics collection, and Grafana for visualization.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";

// Create an EKS cluster
const cluster = new eks.Cluster("eksCluster", {
    instanceType: "t2.medium",
    desiredCapacity: 2,
    minSize: 1,
    maxSize: 3,
});

// Export the cluster's kubeconfig
export const kubeconfig = cluster.kubeconfig;

// Create a Kubernetes provider instance
const k8sProvider = new k8s.Provider("k8sProvider", {
    kubeconfig: cluster.kubeconfig.apply(JSON.stringify),
});

// Deploy Prometheus using Helm
const prometheus = new k8s.helm.v3.Chart("prometheus", {
    chart: "prometheus",
    version: "14.6.0",
    fetchOpts: {
        repo: "https://prometheus-community.github.io/helm-charts",
    },
}, { provider: k8sProvider });

// Deploy Grafana using Helm
const grafanaChart = new k8s.helm.v3.Chart("grafana", {
    chart: "grafana",
    version: "6.17.4",
    fetchOpts: {
        repo: "https://grafana.github.io/helm-charts",
    },
    values: {
        adminUser: "admin",
        adminPassword: "admin",
        datasources: {
            "datasources.yaml": {
                apiVersion: 1,
                datasources: [{
                    name: "Prometheus",
                    type: "prometheus",
                    url: "http://prometheus-server",
                    access: "proxy",
                    isDefault: true,
                }],
            },
        },
    },
}, { provider: k8sProvider });

// Export the cluster name and Grafana dashboard URL
export const eksClusterName = cluster.eksCluster.name;
export const grafanaDashboardUrl = pulumi.interpolate\`http://\${grafanaChart.getResource("v1/Service", "grafana").status.loadBalancer.ingress[0].hostname}\`;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up