[DIY] Set Up Telegraf, InfluxDB, & Grafana on Kubernetes

A guide to getting started with monitoring and alerting.

Ankit Deshpande
Gojek Product + Tech
5 min readMar 3, 2020

--

Infrastructure and application observability and monitoring plays a very important role in ensuring uptime and smooth operations of services and systems in production. Better visibility into system health helps in timely detection of anomalies.

How do you achieve this? Monitoring Postgres/Kubernetes clusters, VMs etc. can be done with the help of the TIG (Telegraf, InfluxDB, Grafana) stack. With the help of configurable plugins, you can track custom events/metrics emitted by applications, and alerts can be set up to notify teams of high CPU usage, error rates, and so on.

In this post, we’ll discuss how to setup this stack on Kubernetes.

Let’s start with some introductions

InfluxDB
InfluxDB is an open-source time series database. Being a time series database, it suits the intensive workloads of storing and retrieving time-based data like application metrics, system health metrics (CPU, Memory, Network, Disk) usage etc.

Telegraf
Telegraf is an agent for collecting, processing, aggregating, and writing metrics. It supports multiple outputs, InfluxDB being one of them.

Grafana
Grafana is an open source visualization tool. It is used to create dashboards, and offers features and plugins to make them dynamic.

Now that that is out of the way, let’s look at how we can setup Grafana, Telegraf and InfluxDB on Kubernetes (Minikube).

Note: This is not a production ready configuration/setup, this is for experimenting how TIG stack works and how to setup it up.

Prerequisites

  • Access to K8 Cluster / Minikube / MicroK8
  • kubectx
  • kubens
  • alias k=’kubectl’

We will setup the following components:

  • Namespace (Optional)
  • InfluxDB
  • Telegraf
  • Grafana

Setup Namespace

We will use this namespace to deploy all the K8 resources needed for monitoring

Switch Namespace

Using kubens:

Select monitoring namespace (we can also specify this namespace in the resource definition)

Setup InfluxDB

For InfluxDB we will create:

  • A secret(username password to connect to DB)
  • Persistent Volume
  • Deployment
  • Expose this deployment using a service

Secret for InfluxDB

Persistent volume for InfluxDB

This persistent volume will be used by the InfluxDB container to store data across container restarts. StatefulSet Deployments can also be used for running InfluxDB pods.

InfluxDB Deployment

InfluxDB Service

Setup Telegraf

For running Telegraf we will create:

  • Secret (host, credentials to connect to InfluxDB)
  • Config
  • Deployment
  • Service
  • If running on Minikube, expose this service on Minikube so that it is accessible from outside the cluster

Telegraf Secret

Telegraf Config

Telegraf Deployment

Telegraf Service

If using Minikube, if you want services outside the k8 cluster to access this Telegraf service, use:

Setup Grafana

For Grafana we will create

  • Secret (admin username, password to access Grafana)
  • Deployment
  • Service
  • Expose on Minikube

Grafana secret

Grafana Deployment

Grafana Service

Expose on Minikube

All pods are running under monitoring namespace
minikube service list

The application can start publishing StatsD events to (192.168.99.100:32161 from outside the cluster), or Telegraf’s service IP using UDP protocol.

You can use target port to access Grafana in your web browser.

Setup influxDB data source in grafana

Password is root1234 for InfluxDB (specified in the InfluxDB secret).

A few helpful commands

Useful Links

InfluxDB: https://www.influxdata.com/products/influxdb-overview/

Telegraf: https://github.com/influxdata/telegraf

Grafana: https://grafana.com/grafana/

You can also find the yaml resource definitions here.

Want our stories in your email inbox? Sign up for our newsletter!

Gojek Job Openings
gojek.jobs

--

--