Kubernetes搭建Zabbix监控
因使用PostgreSQL14.10+TimeScaleDB2.13.1
作为数据库,需首先创建对应数据库,已创建可忽略。本想做Mysql双主双从模式,但实际只有一台机器只能换成pg。
部署过程:https://199604.com/2861
创建Zabbix用户及数据库
虽镜像会自动导入相关sql,但还存在部分bug,为了解决问题还是自行导入sql较好。
问题:https://stackoverflow.com/questions/65895096/cannot-start-docker-image-of-zabbix-server-mysql-cannot-use-database-zabbix
# 创建zabbix用户
create database zabbix;
create user zabbix with password 'zabbix@123';
GRANT ALL PRIVILEGES ON DATABASE zabbix TO zabbix;
# Zabbix数据库启用TimescleDB插件
\c zabbix;
create EXTENSION IF NOT EXISTS timescaledb;
# 下载zabbix源码地址:https://www.zabbix.com/cn/download_sources#60LTS
# zabbix sql手册:https://www.zabbix.com/documentation/current/en/manual/appendix/install/db_scripts
# timescaledb 配置说明:https://www.zabbix.com/documentation/6.0/zh/manual/appendix/install/timescaledb
# 下载zabbix源码并解压,导入sql
cd database/postgresql
psql -Uzabbix -p8306 -W -dzabbix -f ./schema.sql
psql -Uzabbix -p8306 -W -dzabbix -f ./images.sql
psql -Uzabbix -p8306 -W -dzabbix -f ./data.sql
psql -Uzabbix -p8306 -W -dzabbix -f ./timescaledb.sql
k8s部署zabbix
创建命名空间
[root@k8s-master zabbix]# kubectl create namespace zabbix
namespace/zabbix created
部署zabbix-server
编写zabbix_server.yaml
文件
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: zabbix-server
name: zabbix-server
namespace: zabbix
spec:
replicas: 1
selector:
matchLabels:
app: zabbix-server
template:
metadata:
labels:
app: zabbix-server
spec:
containers:
- image: reg-hub.glj.com/zabbix/zabbix-server-pgsql:6.0.25-centos
name: zabbix-server-pgsql
imagePullPolicy: IfNotPresent
env:
- name: DB_SERVER_HOST
value: "10.196.69.28"
- name: DB_SERVER_PORT
value: "8306"
- name: POSTGRES_USER
value: "zabbix"
- name: POSTGRES_PASSWORD
value: "zabbix@123"
- name: POSTGRES_DB
value: "zabbix"
- name: ZBX_TIMEOUT
value: "30"
- name: TZ
value: "Asia/Shanghai"
ports:
- containerPort: 10051
name: zabbix-server
protocol: TCP
resources:
requests:
cpu: '0.5'
memory: '512m'
limits:
cpu: '1'
memory: '4Gi'
hostNetwork: true #使用宿主机网络,固定ip。
nodeSelector:
"kubernetes.io/hostname": "k8s-m02"
tolerations:
- key: "node-role.kubernetes.io/controlplane"
operator: "Exists"
- key: "node-role.kubernetes.io/etcd"
operator: "Exists"
imagePullSecrets:
- name: hub
---
apiVersion: v1
kind: Service
metadata:
namespace: zabbix
name: zabbix-server-svc
labels:
name: zabbix-server-svc
spec:
type: ClusterIP
ports:
- port: 10051
name: zabbix-server
targetPort: 10051
selector:
app: zabbix-server
一些外部脚本记得自行映射
部署zabbix-web
编写zabbix_web.yaml
文件
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: zabbix-web
name: zabbix-web
namespace: zabbix
spec:
replicas: 1
selector:
matchLabels:
app: zabbix-web
template:
metadata:
labels:
app: zabbix-web
spec:
containers:
- image: reg-hub.glj.com/zabbix/zabbix-web-nginx-pgsql:6.0.25-centos
name: zabbix-web-nginx-pgsql
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: web
protocol: TCP
env:
- name: DB_SERVER_HOST
value: "10.196.69.28"
- name: DB_SERVER_PORT
value: "8306"
- name: POSTGRES_USER
value: "zabbix"
- name: POSTGRES_PASSWORD
value: "zabbix@123"
- name: POSTGRES_DB
value: "zabbix"
- name: PHP_TZ
value: Asia/shanghai
- name: ZBX_SERVER_HOST
value: "zabbix-server-svc"
- name: TZ
value: "Asia/Shanghai"
resources:
requests:
cpu: 500m
memory: 500Mi
limits:
cpu: 1000m
memory: 1Gi
imagePullSecrets:
- name: hub
---
apiVersion: v1
kind: Service
metadata:
namespace: zabbix
name: zabbix-web-svc
labels:
name: zabbix-web-svc
spec:
type: ClusterIP
ports:
- port: 8080
name: web
targetPort: 8080
selector:
app: zabbix-web
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: zabbix-web-ing
namespace: zabbix
spec:
ingressClassName: nginx
rules:
- host: web.zabbix.glj.com
http:
paths:
- backend:
service:
name: zabbix-web-svc
port:
number: 8080
path: /
pathType: Prefix
参考
1.https://blog.csdn.net/u010533742/article/details/125280581
2.https://zhuanlan.zhihu.com/p/105205984
3.https://mp.weixin.qq.com/s/S84jFIWXTy1onVff_D8TrQ
4.https://blog.csdn.net/a492391142/article/details/114696650