Kubernetes中的Event objects小结
Contents
一什么是Event objects?
Kubernetes一切皆对象,events事件也不例外。它是由Controller对象”监控”其它对象时产生的事件对象。
二Event objects是如何产生的?
它由Controller对象在调度、协调其它对象达到目标状态的过程中产生的。比如,扩容某个Deployment的过程中,就会由Deployment Controller在该Deployment对象上产生一些事件。
三Event objects作用?
它可以给我们提供帮助信息,用以查看和分析其它对象的状态。
四Event objects如何查查?
通过kuberctl get events;或者是简写的命令:kubectl get ev;如下:
[root@master-node ~]# kubectl get events LAST SEEN TYPE REASON OBJECT MESSAGE 108s Warning ImageGCFailed node/guoxin7 failed to get imageFs info: non-existent label "docker-images" 50s Warning EvictionThresholdMet node/master-node Attempting to reclaim ephemeral-storage 42s Warning ImageGCFailed node/ora12c (combined from similar events): wanted to free 13863891763 bytes, but freed 0 bytes space with errors in image deletion: rpc error: code = Unknown desc = Error response from daemon: conflict: unable to remove repository reference "rancher/rancher:latest" (must force) - container 7c48b6452b19 is using its referenced image c9fbb6293409 [root@master-node ~]# #一个截断之后的版本,单纯是为了页面展示好看。 [root@master-node ~]# kubectl get events LAST SEEN TYPE REASON OBJECT MESSAGE 3m11s Warning ImageGCFailed node/guoxin7 failed to get i 2m19s Warning EvictionThresholdMet node/master-node Attempting to r 2m5s Warning ImageGCFailed node/ora12c (combined from [root@master-node ~]#
五Event objects的分类
Kubernetes里的events object分为Normal和Warining两类。
六Event objects特征
自动清理:默认情况下,每间隔1个小时都会被自动清理,用以减轻etcd的存储压力。
yaml格式的manifest按字母先后顺序呈现,它不像其它Kubernetes object那样,在yaml格式的文件中,展现的很清晰。举例如下:
#通过kubectl get events -owide;获取events object的name:guoxin7.16e72cf8eb00a3f0 #查看指定events的yaml文件: [root@master-node ~]# kubectl get events guoxin7.16e72cf8eb00a3f0 -oyaml apiVersion: v1 count: 6323 eventTime: null firstTimestamp: "2022-04-19T03:00:36Z" involvedObject: kind: Node name: guoxin7 uid: guoxin7 kind: Event lastTimestamp: "2022-05-11T01:50:40Z" message: 'failed to get imageFs info: non-existent label "docker-images"' metadata: creationTimestamp: "2022-04-19T03:00:36Z" name: guoxin7.16e72cf8eb00a3f0 namespace: default resourceVersion: "16272720" uid: ef014c85-dec3-42a9-89eb-1da708a81fdf reason: ImageGCFailed reportingComponent: "" reportingInstance: "" source: component: kubelet host: guoxin7 type: Warning [root@master-node ~]#
七如何查看指定类型的Event objects
1命令是:kubectll get events –field-selector=type=Normal;
[root@master-node ~]# kubectl get events --field-selector=type=Normal No resources found in default namespace. [root@master-node ~]#
2或者是:kubectll get events –field-selector=type=Warning;
[root@master-node ~]# kubectl get events --field-selector=type=Warning LAST SEEN TYPE REASON OBJECT MESSAGE 4m1s Warning ImageGCFailed node/guoxin7 failed to get imageFs info: non-existent label "docker-images" 3m2s Warning EvictionThresholdMet node/master-node Attempting to reclaim ephemeral-storage 2m55s Warning ImageGCFailed node/ora12c (combined from similar events): wanted to free 13866877747 bytes, but freed 0 bytes space with errors in image deletion: rpc error: code = Unknown desc = Error response from daemon: conflict: unable to remove repository reference "rancher/rancher:latest" (must force) - container 7c48b6452b19 is using its referenced image c9fbb6293409 [root@master-node ~]#
问题是,我怎么知道这个命令需要这么写呢?
我们可以通过执行kubectl explain events;命令来获取关于events的文件结构说明,其中,我们看到有:
[root@master-node ~]# kubectl explain events KIND: Event VERSION: v1 DESCRIPTION: Event is a report of an event somewhere in the cluster. Events have a limited retention time and triggers and messages may evolve with time. Event consumers should not rely on the timing of an event with a given Reason reflecting a consistent underlying trigger, or the continued existence of events with that Reason. Events should be treated as informative, best-effort, supplemental data. FIELDS: ... type <string> Type of this event (Normal, Warning), new types could be added in the future [root@master-node ~]#
那么,我们就知道了可以用type=Normal|Warning来过滤了。
我们又怎么知道可以使用–field-selector命令行选项的呢?通过kubectl get –help命令来获取。
八Kubernetes object和Controller、Event objects的关系图
九参考
Kubernetes in Action Second Edition Marko luksa Chapter 04 P102.