zabbix-kubernetes-monitoring is zabbix-agent script and template for zabbix server. It is used for Kubernetes monitoring by Zabbix. Easy to deploy and configure. Auto discovery of pods, deployments, services, etc.
- Copy
k8s-stats.py
to /usr/lib/zabbix/externalscripts andk8s-stats.json
to /etc/zabbix/ and fix file permissions
cp k8s-stats.py /usr/lib/zabbix/externalscripts/
cp k8s-stats.json /etc/zabbix/
chmod +x /usr/lib/zabbix/externalscripts/k8s-stats.py
chown zabbix. /etc/zabbix/k8s-stats.json
chmod 640 /etc/zabbix/k8s-stats.json
- Import Zabbix template
k8s-zabbix-template.xml
to Zabbix server - Create zabbix user in Kubernetes (can use
zabbix-user-example.yml
) and set it's token and API server url ink8s-stats.json
. The root item key names in JSON config refer to - Apply template to host
{$K8S_CLUSTER_NAME}
macro value in zabbix configuration, see step 5. - Update
{$K8S_CLUSTER_NAME}
macro value appropriately in host configuration. Example:
{
"my-cloud-123": {
"api_url": "https://my_cloud_address:6443",
"access_token": "my_cloud_token"
}
}
You then need to use {$K8S_CLUSTER_NAME} => my-cloud-123
on zabbix host you have attached the template to
Simply add more dicts to k8s_stats.json
. Sample config file provided in repo has two clusters added.
$ kubectl apply -n kube-system -f zabbix-user-example.yml
serviceaccount/zabbix-user created
clusterrole.rbac.authorization.k8s.io/zabbix-user created
clusterrolebinding.rbac.authorization.k8s.io/zabbix-user created
- TOKEN:
$ TOKENNAME=$(kubectl get sa/zabbix-user -n kube-system -o jsonpath='{.secrets[0].name}')
$ TOKEN=$(kubectl -n kube-system get secret $TOKENNAME -o jsonpath='{.data.token}'| base64 --decode)
$ echo $TOKEN
- API SERVER:
$ APISERVER=https://$(kubectl -n default get endpoints kubernetes --no-headers | awk '{ print $2 }')
$ echo $APISERVER