一,环境:
1),k8s部署,master和node节点都部署成功
二,部署:
1),安装python3(资源中有)
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
2),安装依赖文件
yum -y install zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi libffi-devel gcc make glibc-kernheaders
3),编译安装python3
mkdir /usr/local/python3
tar -zxvf Python-3.7.4.tgz
cd Python-3.7.4
./configure --prefix=/usr/local/python3 --with-ssl --enable-shared CFLAGS=-fPIC
make && make install
ln -sv /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -sv /usr/local/python3/bin/pip3.7 /usr/bin/pip3
4), 导库
find / -name libpython3.7m.so.1.0
记搜到的目录为dir
echo "dir-libpython3.7m.so.1.0" > /etc/ld.so.conf.d/python3.7.conf
ldconfig
ldd /usr/local/python3/bin/python3.7
5),安装zabbix-sender
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum repolist
yum -y install zabbix-sender
6),安装dashboard,参考以往文章,目的是获取token,
7),获取k8s的api地址
kubectl cluster-info
8),创建脚本
cd /etc/zabbix/zabbix_agentd.d/
mkdir k8s
cd k8s/
vim get_k8s.py
cd /usr/lib/zabbix/externalscripts/
cat get_k8s
#!/usr/bin/bash
/usr/bin/python3 /etc/zabbix/zabbix_agentd.d/k8s/get_k8s.py get_pod
/usr/bin/python3 /etc/zabbix/zabbix_agentd.d/k8s/get_k8s.py get_health
/usr/bin/python3 /etc/zabbix/zabbix_agentd.d/k8s/get_k8s.py get_node
get_k8s.py在本文章的资源中
9),上传模板
配置->模板->右上角导入->选择文件->导入
10),给指定主机绑定模板
三,测试
1),配置
k8s-master:192.168.142.135
k8s-node01:192.168.142.136
k8s-node02:192.168.142.137
2),zabbix主机配置
3), 主机查看
有pod处于非Running状态
4),创建触发器
5),status不为Running则发邮箱
6),恢复/wordpress-mysql-6d8f95f69d-bwmpj
7),逻辑讲解
这里测试的是往期k8s+wordpress文章,在根据流程执行时,不去创建ssecret mysql-pass ,当wordpress的mysqldeploy创建wordpress-mysql-6d8f95f69d-bwmpj时,没有检测到mysql-pass,于是便处于 CreateContainerConfigError,然后让其触发咱们的触发器,当触发后,发邮箱报有错,状态处于pending,创建secret mysql-pass,让其状态恢复为Running,触发触发器,发邮件,状态恢复为Running