Zabbix监控万物2--监控K8S

背景

由于项目中需要使用AWS EKS进行部署,传统的在服务器上安装zabbix agent的方法变得不再使用,还好Zabbix从6.0LTS开始就开始适配K8S,所以正好尝试一下

为什么不用Prometheus

诚然,在K8S监控领域,Prometheus可以说是绝对的主流,但是我主要有以下几点顾虑,仅为个人观点,欢迎讨论

  1. 监控人员没有EKS manager服务器的权限,这就意味着,没法上服务器修改配置文件,每次有配置变更会很被动
  2. 监控人员需要有较强的K8S知识才能修改相关的配置,比如alertmanager,而Zabbix从界面上进行配置,会简单很多
  3. Zabbix对各种自定义监控项的支持比较好,例如自定义shell,各种API health check等,而在prometheus中这些都需要自定义exporter,略显繁琐
    综上所述,导致了我希望可以尝试用Zabbix去监控K8S中的各项指标,才有了这一次的尝试

尝试过程

321上链接 https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/app/kubernetes_http
这个就是官方的步骤,跟着最下面的setup一步步做就行

安装

Install the kubectl and helm tools following the instructions.

Clone the repository:

1
2
3
cd ~
git clone https://git.zabbix.com/scm/zt/kubernetes-helm.git
cd kubernetes-helm

Export the default values of the chart helm-zabbix to the file $HOME/zabbix_values.yaml:

1
helm show values . > $HOME/zabbix_values.yaml

Change the zabbixProxy.env.ZBX_SERVER_HOST environment variable value in the file $HOME/zabbix_values.yaml to the address of the Zabbix server that is used for monitoring and which is reachable by the Zabbix proxy. Other values can be changed according to the environment if needed.

List the namespaces of the cluster.

1
kubectl get namespaces

Create the namespace monitoring if it does not exist in the cluster.

1
kubectl create namespace monitoring

Deploy the chart in the Kubernetes cluster (update the YAML files paths if necessary).

1
helm install zabbix . --dependency-update -f $HOME/zabbix_values.yaml -n monitoring

Get the token automatically created for the service account.

1
kubectl get secret zabbix-service-account -n monitoring -o jsonpath={.data.token} | base64 -d

导入模版

这一步其实没必要,新的zabbix都会自带这些模版,如果没有再下载导入即可

获取token

就是上面的最后一步

创建一个proxy

我们将转到Administration -> Proxies来添加Proxy

因为这默认是主动Proxy,所以我们只需要根据zabbix_values.yaml文件中的- name: ZBX_HOSTNAME字段填入对应的Proxy name,其他的保持默认即可
(默认名称为zabbix-proxy)

创建一个监控node的host

我们需要创建一个主机,用来采集与监控Kubernetes节点相关的指标,并且我们将使用Zabbix低级别自动发现来发现节点并创建新主机

给此主机命名Kubernetes Nodes,并关联模板kubernetes nodes by HTTP.
在这个模版里,有两个宏需要被修改

  1. {KUBE.API.ENDPOINT.URL}, 应该设置为Kubernetes API endpoint, 例如https://kubernetes.default.svc.cluster.local:443
  2. {$KUBE.API.TOKEN}, 应该设置为我们之前获取的token
    添加完主机几分钟后,我们就可以在host页面看到很多新的host,每个host都代表一个node

创建一个监控cluster的host

创建一个新的host,该host将代表通过Kubernetes API和kube-state-metrics端点可用的指标

  1. 再次单击Create Host按钮,将此主机命名为k8s-cluster-host。
  2. 同样选择之前创建的proxy
  3. 为该主机关联模板Kubernetes cluster state by HTTP
  4. 在Macro部分中,将kube.api.url更改为我们之前使用的相同内容,但这次在末尾省略/api。简单地:default.svc.cluster.local:443。
  5. {$KUBE.API.TOKEN} 设置为同样的内容

问题Todo

  1. Agent无法连接的问题
  2. Agent照理来说应该是DaemonSet自动创建的,但是现在只有proxy服务器的一个agent,其他node没有agent,很奇怪
  3. Prometheus数据接入,怎么对接prometheus的exporter