Operations 3 min read

How to Monitor Kubernetes API with Python and Zabbix Sender – Step‑by‑Step Guide

This tutorial walks you through using Python's requests library and Zabbix Sender to retrieve Kubernetes API metrics, covering API endpoint discovery, token generation, script deployment, host configuration, and manual trigger of checks to visualize the data.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Monitor Kubernetes API with Python and Zabbix Sender – Step‑by‑Step Guide

Step 1: Get the Kubernetes API address

Run the following command on the master node (not a worker) to obtain the current API endpoint:

Step 2: Generate a token on the master

Execute the following command to retrieve the admin‑user secret and extract the token:

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

Save the token to a local file for later use in the script.

Step 3: Upload and modify the script

Create a directory named k8s under /usr/local/zabbix/share/zabbix/externalcripts and place the get_k8s.py script there.

The script needs three modifications: upload the script, set the token, and adjust the host name.

Step 4: Create a host and apply the script

In Zabbix, create a host named k8s_master; the name must match exactly, otherwise data cannot be retrieved because Zabbix Sender sends data to that host.

Step 5: Manually trigger the check

Select the monitoring item in Zabbix and click “Check now”. The resulting graph shows successful retrieval of Kubernetes metrics via the API.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringPythonAutomationKubernetesOpsAPIZabbix
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.