CKA [Logging] – field selector的使用

Field Selector的官方文档:https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/

✅ K8s 的 field selector 有什么作用 ?

可以根据json的key的value来进行filter,那么就只会看到你想看到的资料。

根据官方文档来看的话,Operator可以使用的条件有:!= 或 == 或 =

== 和 = 是同样的意思。

✅ 实际操作

1. 可以从一个namespace当中获取这个namespace底下所有的events , 我们可以看到events相当凌乱,因为掺杂了非常多的资源。

kubectl get events -n pg 

2. 这个步骤是寻找json的key name , 比如我们可以让events 输出json 格式

我们可以获取 involvedObject.name=pg-live-cron8 这个filteration的条件

kubectl get events -o json -n pg

3. 执行get events 加上field-selector , 这次我选择的filteration condition 是用上kind

kubectl get events -n pg --field-selector=involvedObject.kind=Job  

Loading

Facebook评论