2

monitoring method : python+zabbix _sender

principle : python request library, request the api address of k8s, and process data.

The first step: get the api address of k8s

The command to view the api address of K8S is as follows (it is best to execute this command on the master of the K 8s cluster, because if the command is executed on the node node, the old api address may be obtained)

Step 2: The Master host of the K8S cluster generates a token for authentication and requests data api data

The token generation command is as follows (execute the command on the Master host of K 8S)

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

Save the value of the token in a local file, and you need to add the value of the token to the script later.

Step 3: Upload the script and modify the script

cd /usr/local/zabbix/share/zabbix/exter nalscripts 

Create a directory named k 8s under the directory, and put the get _k8s.py script in this directory

Need to modify the script in three places

Upload the external check get _k8s script to the /usr/local/zabbix/share/zabbix/exter nalscript directory

Step 4: Create a host and apply the script

Note: The host name must be k 8s _master, otherwise the data cannot be obtained. (Because the data is sent to the host through zabbix_sender)

Step 5: Manually trigger the script

Select the monitoring item. Click to check now

Data effect

Zabbix gets k8s through api and the result is successful! It's that simple, that's it! !

The script is also ready for everyone. Readers who need it can reply to the keyword Zabbix-K8s background of the official account to obtain the monitoring script and template file.

Link: http://www.yidianzixun.com/article/0SyJkO6k


民工哥
26.4k 声望56.7k 粉丝

10多年IT职场老司机的经验分享,坚持自学一路从技术小白成长为互联网企业信息技术部门的负责人。2019/2020/2021年度 思否Top Writer