1、github下载kubernetes.yaml (Zabbix 5.2 release prepare),直接创建资源,有报错:
$ kubectl create -f zabbix.yaml
namespace/zabbix created
service/mysql-server created
service/zabbix-proxy-sqlite3 created
service/zabbix-proxy-mysql created
service/zabbix-java-gateway created
service/zabbix-agent created
replicationcontroller/zabbix-web created
replicationcontroller/mysql-server created
replicationcontroller/zabbix-server created
replicationcontroller/zabbix-proxy-sqlite3 created
replicationcontroller/zabbix-proxy-mysql created
replicationcontroller/zabbix-java-gateway created
daemonset.apps/zabbix-agent created
horizontalpodautoscaler.autoscaling/zabbix-web created
persistentvolume/zabbix-mysql-data created
persistentvolumeclaim/zabbix-mysql-data-claim created
secret/db-secret created
Error from server (Invalid): error when creating "zabbix.yaml": Service "zabbix-web" is invalid: spec.externalIPs[0]: Invalid value: "
Error from server (Invalid): error when creating "zabbix.yaml": Service "zabbix-server" is invalid: spec.externalIPs[0]: Invalid value: "
$ kubectl get pod,service
NAME READY STATUS RESTARTS AGE
pod/mysql-server-8hnv2 0/1 Pending 0 2m17s
pod/zabbix-agent-9cg2f 1/1 Running 0 2m17s
pod/zabbix-java-gateway-5tfkj 1/1 Running 0 2m17s
pod/zabbix-proxy-mysql-pxfrg 1/1 Running 0 2m17s
pod/zabbix-proxy-sqlite3-vqltl 1/1 Running 0 2m17s
pod/zabbix-server-6lfzq 1/2 Running 0 2m17s
pod/zabbix-web-pcgdg 0/1 Running 1 2m17s
pod/zabbix-web-qdqwg 0/1 Running 0 2m17s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/mysql-server
ClusterIP 10.103.160.211
service/zabbix-agent ClusterIP 10.99.68.135
service/zabbix-java-gateway ClusterIP 10.98.194.191
service/zabbix-proxy-mysql ClusterIP 10.103.8.208
service/zabbix-proxy-sqlite3
ClusterIP 10.109.172.46
这里services "zabbix-web" 和 "zabbix-server"not found
$ kubectl describe pod mysql-server-8hnv2
......
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 4m6s default-scheduler persistentvolumeclaim "zabbix-mysql-data-claim" not found
Warning FailedScheduling 4m6s default-scheduler persistentvolumeclaim "zabbix-mysql-data-claim" not found
Warning FailedScheduling 4m4s default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.
2、排查一:修改 kubernetes.yaml
1)将Service资源对象zabbix-web和mysql-server的默认type:ClusterIP( 集群内的私有ip)修改为type: NodePort( 在node 端口暴露服务,将向该端口的流量导入到kube-proxy,然后由kube-proxy进一步导给对应的pod),否则Win10主机无法访问。
2)注释掉externalIPs相关项:
在Service的Spec中,
当把IP地址填入
externalIPs字段后,
kube-proxy
会增加对应的
iptables
规则, 当有以对应IP为目标的流量发送到Node节点时,
iptables
将进行NAT,将流量转发到对应的服务上,
可以实现给Service绑定外部IP的效果。
3) 注释掉 ReplicationController资源对象 mysql-server的volumes:和volumeMounts:相关项,解决该Pod/mysql-server 状态Pending的问题。
4)为了能登录mysql,修改List/Secret资源对象db-secret的db-root-pass、db-zbx-user、db-zbx-pass密码为"emFiYml4",即zabbix(由命令得到:echo -n 'zabbix' | base64)
3、完成以上步骤,pod/mysql-server恢复running,但是pod/zabbix-server出现 CrashLoopBackOff状态!
$ kubectl get pod,service
NAME READY STATUS RESTARTS AGE
pod/mysql-server-xvtbn 1/1 Running 0 2m42s
pod/zabbix-agent-7dks2 1/1 Running 0 2m42s
pod/zabbix-java-gateway-bmn46 1/1 Running 0 2m42s
pod/zabbix-proxy-mysql-47wh6 1/1 Running 0 2m42s
pod/zabbix-proxy-sqlite3-qsxcb 1/1 Running 0 2m42s
pod/zabbix-server-sj584 1/2 CrashLoopBackOff 3 2m42s
pod/zabbix-web-8rbmc 1/1 Running 0 2m42s
pod/zabbix-web-9znhb 1/1 Running 0 2m42s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/mysql-server NodePort 10.110.160.252
service/zabbix-agent ClusterIP 10.111.34.4
service/zabbix-java-gateway ClusterIP 10.99.175.58
service/zabbix-proxy-mysql ClusterIP 10.101.232.209
service/zabbix-proxy-sqlite3 ClusterIP 10.105.63.0
service/zabbix-server
ClusterIP 10.108.177.103
service/zabbix-web
NodePort 10.99.166.170
而且浏览器localhost: 31153,出现Database error不能选择配置文件报错。
4、 排查二
$ kubectl logs zabbix-server-sj584 -c zabbix-server
......
8:20210314:123345.722 cannot use database "zabbix": its "users" table is empty (is this the Zabbix proxy database?)
$mysql -uzabbix -pzabbix -h 127.0.0.1 -P 32130 zabbix
mysql> use zabbix
Database changed
mysql> select *from users;
Empty set (0.02 sec)
判断原因是虽然mysql中创建了表结构,但是没有数据。下载源码包zabbix-5.2.5.tar.gz,在zabbix-5.2.5.tar.gz\zabbix-5.2.5\database\mysql解压出data.sql,导入zabbix数据库中:
$ mysql -uzabbix -pzabbix -h 127.0.0.1 -P 32130 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
检查 pod/zabbix-server-sj584状态恢复running, 浏览器localhost: 31153出现正常登录界面(Admin/zabbix)。
5、后续需解决数据库持久化存储的问题
在Kubernetes Pod中的容器系统存储文件是临时的,Pod如果异常重启将会恢复到镜像的原始状态从而会丢失所有的状态包括系统存储文件,或者同一个Pod中多个容器需要共享数据。数据卷诞生就是为了解决这一类数据持久化及数据共享的场景,并与容器的生命周期分离开。
PV(PersistentVolume): PV是定义存储数据的方式,例如存储类、存储实现等,是由集群管理员定义的集群资源中的对象。
PVC (PersistentVolumeClaim): 是声明定义存储数据使用的请求,被挂载到Pod中进行使用。通常由开发人员进行配置使用,不用关心数据存储底层具体的实现方式,只关心与业务相关的数据存储大小,访问方式等。
PV与PVC是一对一关系,一个PVC只能绑定到一个PV,如果PV被绑定后,其他PVC则无法在使用此PV。
$ kubectl get pv -o wide
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
VOLUMEMODE
zabbix-mysql-data 1Gi RWO Retain Available 33m Filesystem
Retain(保留) 当PVC与PV解除绑定关系后PV处于保留状态,如果有同样声明的PVC时PV将继续可以被绑定使用,期间数据不会被删除。
ReadWriteOnce(RWO)允许被单个节点以读写的模式进行挂载。 ReadWriteMany(RWX)允许被多个节点以读写的模式进行挂载。
PV Phase 运行状态:Available PV处于可用状态,可以被PVC绑定。
Bound PV已被PVC所绑定。
Released PVC已删除,但PV还未被集群回收。 Failed PV自动回收失败。
$ kubectl describe pv //
查看PV详细信息
查看PVC详细信息
$ kubectl describe pvc
Name: zabbix-mysql-data-claim
Namespace: zabbix
StorageClass: hostpath
Status: Pending
Volume: zabbix-mysql-data
Labels:
Annotations:
Finalizers: [kubernetes.io/pvc-protection]
Capacity: 0
Access Modes:
VolumeMode: Filesystem
Mounted By:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning VolumeMismatch 2m49s (x44 over 42m) persistentvolume-controller Cannot bind to requested volume "zabbix-mysql-data": storageClassName does not match