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.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。