---
title: "How monitoring works in Kubernetes? - Fairbanks"
description: "This tutorial guides you through monitoring for Kubernetes. Setting up a simple Node.js application using Prometheus and Grafana."
url: "https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes/"
language: "en"
---

Blog

# How monitoring works in Kubernetes?

Technology

September 26, 2023

Author: Elvira Dautović

In this post

[Why is monitoring important?](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-1)[Prerequisites:](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-2)[Step 1: Set up the Node.js application](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-3)[Step 2: Set Up a Dockerfile](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-4)[Step 3: Deploy to Kubernetes](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-5)[Step 4: Set up Prometheus](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-6)[Step 5: Set up Grafana](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-7)[Step 6: Accessing the services](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-8)[Step 7: Create a Grafana dashboard](https://fairbanks-upgrade.ubo-dev.nl/how-monitoring-works-in-kubernetes#section-1-9)

Share this post

[](https://www.linkedin.com/company/fairbanks/)Monitoring in Kubernetes involves observing and collecting data about the health, performance, and resource utilization of your cluster, nodes, pods, and containers. There are various tools available for monitoring Kubernetes applications, and one popular choice is Prometheus along with Grafana for visualization. In this tutorial, I’ll guide you through setting up monitoring for a simple Node.js application using Prometheus and Grafana.

## Why is monitoring important?

Monitoring is essential in Kubernetes to ensure the health, performance, and reliability of applications and infrastructure. In the dynamic and distributed nature of Kubernetes, monitoring tools provide real-time insights into resource utilization, application behaviour, and system performance. This proactive approach allows for early issue detection, optimized resource allocation, and efficient troubleshooting. Monitoring aids in scaling applications, identifying bottlenecks, meeting security and compliance requirements, and making informed decisions about capacity planning. With alerts and notifications, monitoring enables rapid response to critical incidents, enhancing overall application stability. Ultimately, monitoring is a foundational practice that empowers organizations to maintain a resilient and high-performing Kubernetes environment, supporting both operational excellence and continuous improvement.

Let’s explore how monitoring works in Kubernetes through a simple tutorial.

## Prerequisites:

- [**Docker Desktop**](https://docs.docker.com/desktop/) installed and running
- [**Nodejs installed**](https://nodejs.org/en/download)
- **[Minikube](https://minikube.sigs.k8s.io/docs/start/)** installed for creating a single node cluster

## Step 1: Set up the Node.js application

Let’s start with a basic Node.js application.

`npm init -y`

Create a file named **app.js** with the following code:

`const http = require('http');`

`const server = http.createServer((req, res) => {`

` res.writeHead(200, { 'Content-Type': 'text/plain' });`

`res.end('Hello, Kubernetes monitoring tutorial!n');`

`});`

`const PORT = process.env.PORT || 3000;`

`server.listen(PORT, () => {`

``  console.log(`Server running on port ${PORT}`); ``

`});`

If you run the application with the following command,

`node app.js`

## Step 2: Set Up a Dockerfile

Create a Dockerfile and add the following code.

`FROM node:14`

`WORKDIR /usr/src/app`

`COPY package*.json ./`

`RUN npm install`

`COPY . .`

`EXPOSE 3000`

`CMD [ "node", "app.js" ]`

_Build the Docker image:_  
`docker build -t nodejs-app .`

Tag and push the Docker image to DockerHub

`docker tag nodejs-app your-dockerhub-username/nodejs-app`

Replace your-dockerhub-username with your actual Docker Hub username.

**You need to authenticate with Docker Hub to be able to push images.**

`docker login`

Push the tagged image to your Docker Hub repository.

`docker push your-dockerhub-username/nodejs-app`

## Step 3: Deploy to Kubernetes

Assuming you have a Kubernetes cluster running. If not, start with Minikube.

`minikube start`

 Create a Kubernetes deployment for your application using a YAML file named **app-deployment.yaml**:

`apiVersion: apps/v1  
kind: Deployment  
metadata:  
 name: nodejs-app  
spec:  
 replicas: 2  
 selector:  
 matchLabels:  
 app: nodejs-app  
 template:  
 metadata:  
 labels:  
 app: nodejs-app  
 spec:  
 containers:  
 - name: nodejs-app  
 image: your-dockerhub-username/nodejs-app:latest  
 ports:  
 - containerPort: 3000`

Apply the deployment:

`kubectl apply -f app-deployment.yaml`

Create a service YAML file

Create a file named **app-service.yaml** with the following content:

`apiVersion: v1  
kind: Service  
metadata:  
 name: nodejs-app-service  
spec:  
 type: NodePort  
 ports:  
 - port: 80  
 targetPort: 3000  
 nodePort: 31080 # Change the node port to an available value  
 selector:  
 app: nodejs-app`

Apply the service configuration:  
`kubectl apply -f app-service.yaml`

Access the application

Now you should be able to access your Node.js application using the Minikube IP and the new node port (31080 in this case):

http://<minikube-ip>:31080

## Step 4: Set up Prometheus

Create a file named **prometheus-config.yaml** for the Prometheus configuration:

` apiVersion: v1  
kind: ConfigMap  
metadata:  
 name: prometheus-config  
data:  
 prometheus.yml: |  
 global:  
 scrape_interval: 15s  
 scrape_configs:  
 - job_name: 'nodejs-app'  
 static_configs:  
 - targets: ['nodejs-app:3000']  
---  
apiVersion: apps/v1  
kind: Deployment  
metadata:  
 name: prometheus-deployment  
spec:  
 replicas: 1  
 selector:  
 matchLabels:  
 app: prometheus  
 template:  
 metadata:  
 labels:  
 app: prometheus  
 spec:  
 containers:  
 - name: prometheus  
 image: prom/prometheus:v2.30.0  
 args:  
 - '--config.file=/etc/prometheus/prometheus.yml'  
 - '--storage.tsdb.path=/prometheus'  
 ports:  
 - containerPort: 9090  
 volumeMounts:  
 - name: prometheus-config-volume  
 mountPath: /etc/prometheus/  
 - name: prometheus-storage-volume  
 mountPath: /prometheus  
 volumes:  
 - name: prometheus-config-volume  
 configMap:  
 name: prometheus-config  
 - name: prometheus-storage-volume  
 emptyDir: {}`

Apply the Prometheus configuration:

`kubectl apply -f prometheus-config.yaml`

Expose Prometheus using a NodePort service:

`apiVersion: v1  
kind: Service  
metadata:  
 name: prometheus-service  
spec:  
 type: NodePort  
 ports:  
 - port: 9090  
 targetPort: 9090  
 nodePort: 30000  
 selector:  
 app: prometheus`

Apply the Prometheus service:  
`kubectl apply -f prometheus-service.yaml`

## Step 5: Set up Grafana

Create a file named **grafana.yaml** for the Grafana deployment:

`apiVersion: apps/v1  
kind: Deployment  
metadata:  
 name: grafana-deployment  
spec:  
 replicas: 1  
 selector:  
 matchLabels:  
 app: grafana  
 template:  
 metadata:  
 labels:  
 app: grafana  
 spec:  
 containers:  
 - name: grafana  
 image: grafana/grafana:latest  
 ports:  
 - containerPort: 3000  
 env:  
 - name: GF_SECURITY_ADMIN_USER  
 value: admin  
 - name: GF_SECURITY_ADMIN_PASSWORD  
 value: adminpassword`  
`---  
apiVersion: v1  
kind: Service  
metadata:  
 name: grafana-service  
spec:  
 type: NodePort  
 ports:  
 - port: 3000  
 targetPort: 3000  
 nodePort: 31000  
 selector:  
 app: grafana`

Apply the Grafana deployment and service:

`kubectl apply -f grafana.yaml`

## Step 6: Accessing the services

Now you can access your application, Prometheus, and Grafana:

- **`Application`**: Open a web browser and navigate to [http://your-node-ip:30000](http://your-node-ip:30000/).
- **`Prometheus`**: Access the Prometheus dashboard at [http://your-node-ip:30000](http://your-node-ip:30000/).
- **`Grafana`**: Access the Grafana dashboard at [http://your-node-ip:31000](http://your-node-ip:31000/), and log in using the credentials admin (username) and adminpassword (password).

## Step 7: Create a Grafana dashboard

Inside Grafana, you can create a new dashboard to visualize metrics collected by Prometheus.

Log in to Grafana.

Click on the “+” icon on the left panel and select “Dashboard.”

Click on “Add new panel.”

In the panel settings, choose “Panel Title” and “Visualization” (e.g., Time Series).

In the “Query” section, select “Prometheus” as the data source and enter a query (e.g., http\_requests\_total to visualize the total HTTP requests).

Customize the panel settings, such as axes, legends, and thresholds.

Click “Apply” to save the panel settings.

Understanding how monitoring works in Kubernetes is crucial for ensuring the smooth operation of complex containerized applications. By implementing a robust monitoring solution, such as Prometheus and Grafana, organizations can gain valuable insights into the health, performance, and resource utilization of their Kubernetes clusters and applications. Monitoring facilitates proactive issue detection, resource optimization, scalability, and fault tolerance. It empowers teams to analyze performance, plan capacity, and make data-driven decisions for continuous improvement. With real-time alerts and notifications, monitoring enables swift responses to critical incidents, enhancing application reliability and user experience. Ultimately, monitoring is an indispensable practice that empowers Kubernetes administrators and developers to maintain a resilient, high-performing environment, contributing to operational excellence in modern application deployment.

![Michiel](https://fairbanks-upgrade.ubo-dev.nl/media/uploads/2025/06/Michiel.jpeg?width=500 "Michiel")

## Want to know more about open source private cloud

Let’s talk with Michiel Manten

[Let's talk](https://fairbanks-upgrade.ubo-dev.nl/contact/?subject=How%20monitoring%20works%20in%20Kubernetes)

Insights & resources

## Latest blogs & news

[Insights & resources](https://fairbanks-upgrade.ubo-dev.nl/insights-resources/)

[KeynoteSustainable private cloud: how to balance energy, performance and business impact![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)Sustainable private cloud: how to balance energy, performance and business impactEvent](https://fairbanks-upgrade.ubo-dev.nl/sustainable-private-cloud/)

[BlogOpenStack Hibiscus is here: What’s new in the latest release![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)October 20, 2026OpenStack Hibiscus is here: What’s new in the latest releaseTechnology](https://fairbanks-upgrade.ubo-dev.nl/openstack-hibiscus-is-here-whats-new-in-the-latest-release/)

[KeynoteHow Kubernetes and Talos make OpenStack easier to upgrade, manage and scale![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)How Kubernetes and Talos make OpenStack easier to upgrade, manage and scaleEvent](https://fairbanks-upgrade.ubo-dev.nl/how-kubernetes-and-talos-make-openstack-easier-to-upgrade-manage-and-scale/)

[KeynoteFrom infrastructure complexity to cloud control: how to orchestrate your datacenter with software![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)From infrastructure complexity to cloud control: how to orchestrate your datacenter with softwareEvent](https://fairbanks-upgrade.ubo-dev.nl/from-infrastructure-complexity-to-cloud-control-how-to-orchestrate-your-datacenter-with-software/)

[BlogDigital autonomy: looking beyond the cloud![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)September 9, 2026Digital autonomy: looking beyond the cloudTechnology](https://fairbanks-upgrade.ubo-dev.nl/digital-autonomy-looking-beyond-the-cloud/)

[BlogUpgrading OpenStack: why containerization and Kubernetes are the answer![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)August 26, 2026Upgrading OpenStack: why containerization and Kubernetes are the answerTechnology](https://fairbanks-upgrade.ubo-dev.nl/upgrading-openstack-containerization-kubernetes/)

[BlogCloud infrastructure migration: what are your options and where do you start?![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)July 24, 2026Cloud infrastructure migration: what are your options and where do you start?Technology](https://fairbanks-upgrade.ubo-dev.nl/cloud-infrastructure-migration-what-are-your-options-and-where-do-you-start/)

[BlogFairbanks named as a representative vendor in the 2026 Gartner® Market Guide![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)July 21, 2026Fairbanks named as a representative vendor in the 2026 Gartner® Market Guide for cloud infrastructure sovereign solutionsTechnology](https://fairbanks-upgrade.ubo-dev.nl/fairbanks-named-as-a-representative-vendor-in-the-2026-gartner-market-guide-for-cloud-infrastructure-sovereign-solutions/)

[BlogMutable vs. immutable infrastructure![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)June 18, 2026Mutable vs. immutable infrastructure: What it means for your datacenterTechnology](https://fairbanks-upgrade.ubo-dev.nl/mutable-vs-immutable-infrastructure-what-it-means-for-your-datacenter/)

[BlogPress release![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)June 10, 2026Press releaseEvent](https://fairbanks-upgrade.ubo-dev.nl/press-release/)

Newsletter
