Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

icinga tutorials: How to monitor Kubernetes using icinga

Step 1: Prerequisites

  • Ensure you have Icinga 2 and Icinga Web 2 installed on your Icinga server.
  • Kubernetes cluster where you want to implement monitoring.
  • Administrative access to both the Kubernetes cluster and the Icinga server.

Step 2: Install and Configure kubectl on Icinga Server

kubectl is the Kubernetes command-line tool that allows you to run commands against Kubernetes clusters.

Install kubectl:

$ sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
$ sudo apt-get update
$ sudo apt-get install -y kubectl

Configure kubectl:

$ Copy your Kubernetes cluster's kubeconfig file to your Icinga server.
$ Set the KUBECONFIG environment variable or use the default location (~/.kube/config).Code language: PHP (php)

Step 3: Install Kubernetes Monitoring Plugin

There are various plugins available for monitoring Kubernetes, such as check_kube, which can be installed on the Icinga server.

Download and install the monitoring plugin:

$ cd /usr/lib/nagios/plugins
$ sudo wget https://example.com/path/to/check_kube  # Replace with actual URL
$ sudo chmod +x check_kubeCode language: JavaScript (javascript)

Step 4: Configure Icinga 2

You need to define commands, services, and hosts in Icinga 2 for Kubernetes monitoring.

Define Command in Icinga:
Create or edit a configuration file:

$ sudo nano /etc/icinga2/conf.d/commands.conf

Add a command definition for Kubernetes checks:

object CheckCommand "check_kubernetes" {
    command = [ "/usr/lib/nagios/plugins/check_kube" ]
    arguments = {
        "-K" = "$kubeconfig$",
        "-N" = "$namespace$",
        "-D" = "$deployment$"
    }
}

Define Host for Kubernetes Cluster:
Add a host object for your Kubernetes cluster:

object Host "kubernetes-cluster" {
    import "generic-host"
    address = "127.0.0.1"  // Use an appropriate address
    check_command = "hostalive"
}

Define Service for Kubernetes Monitoring:
Create services to monitor various components:

apply Service "check-deployment" {
    import "generic-service"
    check_command = "check_kubernetes"
    vars.kubeconfig = "/path/to/kubeconfig"
    vars.namespace = "default"
    vars.deployment = "example-deployment"
    assign where host.name == "kubernetes-cluster"
}Code language: JavaScript (javascript)

Step 5: Reload Icinga 2

After configuring your commands and services, reload Icinga 2 to apply changes:

sudo systemctl reload icinga2

Step 6: Verify and Adjust

<ul style="border: 0px solid rgb(227, 227, 227); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; list-style-type: disc; margin: 0px 0px 1.25em; padding: 0px 0px 0px 1.625em; color: rgb(13, 13, 13); font-family: Söhne, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; font-size: 16px;"><li style="border: 0px solid rgb(227, 227, 227); box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; margin-bottom: 0.5em; margin-top: 0.5em; padding-left: 0.375em;"><span style="border: 0px solid rgb(227, 227, 227); box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; font-weight: 600; color: var(--tw-prose-bold); margin-top: 1.25em; margin-bottom: 1.25em;">Verify in Icinga Web 2</span>: Log into Icinga Web 2 and check the newly configured services for your Kubernetes cluster. Ensure they are reporting correctly.<span style="border: 0px solid rgb(227, 227, 227); box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; font-weight: 600; color: var(--tw-prose-bold); margin-top: 1.25em; margin-bottom: 1.25em;">Adjustments</span>: Depending on your specific monitoring needs, you may need to add additional service checks or refine existing ones to cover different Kubernetes objects like nodes, pods, and services.</li></ul>Code language: JavaScript (javascript)

Alternate Method


Step 1: Install and Configure the Icinga2 Kubernetes Plugin
Before you start, ensure that you have kubectl configured on the same server where your Icinga2 agent is running. This will allow the Icinga2 agent to use kubectl to gather metrics from Kubernetes.

Install the Kubernetes plugin for Icinga2: You might need to write custom check scripts or find existing plugins that can use kubectl to fetch data from Kubernetes. There are community plugins available, or you can create simple bash scripts that wrap kubectl commands.

Example script: Here's a basic example of a script that checks the number of running pods in a specific namespace:


#!/bin/bash
NAMESPACE=$1
MIN_PODS=$2

# Get the number of running pods
RUNNING_PODS=$(kubectl get pods --namespace $NAMESPACE --field-selector=status.phase=Running --no-headers | wc -l)

# Check if the number of running pods is less than the minimum required
if [ "$RUNNING_PODS" -lt "$MIN_PODS" ]; then
  echo "CRITICAL - Only $RUNNING_PODS running pods in $NAMESPACE, minimum required is $MIN_PODS"
  exit 2
else
  echo "OK - $RUNNING_PODS running pods in $NAMESPACE"
  exit 0
fi
Save this script on the Icinga2 agent machine, and make sure it's executable (chmod +x check_kube_pods.sh).

Step 2: Configure Icinga2 Agent
You need to configure your Icinga2 agent to execute the Kubernetes monitoring script.

Define the check command:


object CheckCommand "check_kube_pods" {
  command = [ "/path/to/check_kube_pods.sh" ]
  arguments = {
    "--namespace" = "$namespace$"
    "--min-pods" = "$min_pods$"
  }
}
Add the service definition to Icinga2:


apply Service "kube-pods" {
  import "generic-service"
  check_command = "check_kube_pods"
  vars.namespace = "default"
  vars.min_pods = 10
  assign where host.vars.kubernetes == true
}
Step 3: Define Host and Service in Icinga2
You need to ensure that your Kubernetes cluster or specific nodes are defined as hosts in your Icinga2 configuration.

Define a host for your Kubernetes cluster:


object Host "kubernetes-cluster" {
  import "generic-host"
  address = "127.0.0.1"  // Use an internal or external IP address
  vars.kubernetes = true
}
Step 4: Restart Icinga2
After setting up the configurations, restart Icinga2 to apply the changes.


sudo systemctl restart icinga2
Step 5: Validate the Setup
Check the Icinga2 dashboard or use the Icinga2 CLI to ensure that the new checks are being executed and that they return the expected results.


icinga2 object list --type Service
This setup will allow you to start monitoring basic Kubernetes metrics. You can expand this by adding more complex checks, such as node resource usage, pod status by deployment, or custom metrics exposed by your applications running in Kubernetes.Code language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

icinga: Commands

Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

Read More

icinga: icinga object types

In Icinga2, “objects” are fundamental components that represent various elements and configurations within the monitoring environment. They form the core building blocks of the Icinga2 configuration system….

Read More

icinga2: How to install icinga2 plugins in Linux?

Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

Read More

icinga2: How to enable Api in icinga?

In this example: Available permissions for specific URL endpoints: The permissions field in the ApiUser object specifies what the API user is allowed to do. You can…

Read More

icinga2: How to install icinga modules?

Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

Read More

icinga: Step by Step installing Icinga Director in ubuntu

Installing Icinga Director on an Ubuntu system involves several steps, primarily focused on ensuring that your system meets the prerequisites, installing Icinga Director, and integrating it with…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x