You can Watch all our Tutorials and Training Videos on our YouTube Channel for Free! Subscribe Now!

How to Setup Prometheus Monitoring On Kubernetes

How to Setup Prometheus Monitoring On Kubernetes, setup prometheus on kubernetes, prometheus setup kubernetes, deploy prometheus on kubernetes
Admin
How to Setup Prometheus Monitoring On Kubernetes

Prometheus is an open-source monitoring tool that can be used to collect metrics from various sources and store them in a time-series database. Kubernetes is a popular container orchestration platform that allows developers to deploy and manage containerized applications.

In this article, we will go through the process of setting up Prometheus monitoring on Kubernetes.

Prerequisites

Before we start setting up Prometheus monitoring on Kubernetes, you will need the following:

  • A Kubernetes cluster
  • kubectl command-line tool installed on your local machine
  • Helm package manager installed on your local machine
  • Basic knowledge of Kubernetes and Prometheus

Step 1: Install Prometheus Operator

Prometheus Operator is a Kubernetes native application that makes it easy to deploy and manage Prometheus monitoring on Kubernetes. To install Prometheus Operator, use the following command:

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update
$ helm install prometheus prometheus-community/kube-prometheus-stack

Step 2: Accessing the Prometheus UI

To access the Prometheus UI, we need to first port-forward the Prometheus server to our local machine. Use the following command to port-forward:

$ kubectl --namespace default port-forward svc/prometheus-kube-prometheus-prometheus 9090

Now, you can access the Prometheus UI by opening a browser and going to http://localhost:9090.

Step 3: Deploying an Application with Prometheus Monitoring

To deploy an application with Prometheus monitoring, we need to add annotations to the Kubernetes deployment manifest. Here's an example:

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
annotations:
prometheus.io/scrape: "true"
prometheus.io/path: "/metrics"
prometheus.io/port: "8080"
spec:
containers:
- name: my-app
image: my-app:latest
ports:
- containerPort: 8080

In this example, we have added three annotations to the deployment manifest:

  • prometheus.io/scrape: "true" - This tells Prometheus to scrape metrics from this pod.
  • prometheus.io/path: "/metrics" - This tells Prometheus the path to the metrics endpoint.
  • prometheus.io/port: "8080" - This tells Prometheus the port number of the metrics endpoint.

Step 4: Viewing Metrics in Prometheus

To view the metrics collected by Prometheus, go to the Prometheus UI and enter the name of the metric in the query box. For example, if your application exposes a metric named http_requests_total, you can enter that name in the query box to view the metric.

In this article, we have gone through the process of setting up Prometheus monitoring on Kubernetes. We have installed Prometheus Operator, accessed the Prometheus UI, deployed an application with Prometheus monitoring, and viewed metrics in Prometheus.

With Prometheus monitoring, you can gain valuable insights into the health and performance of your Kubernetes applications.

Related Searches and Questions asked:

  • Kubernetes Monitoring Explained
  • How To Setup Grafana On Kubernetes
  • Kubernetes Autoscaling Explained
  • Kubernetes Dashboard Setup Explained
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.

    Post a Comment

    Cookie Consent
    We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
    Oops!
    It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
    AdBlock Detected!
    We have detected that you are using adblocking plugin in your browser.
    The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
    Site is Blocked
    Sorry! This site is not available in your country.