以下是一种常见的错误操作方法:
[centos@k8s-master ~]$ kubectl get po consul-0 -ojson|jq '.status.conditions[]|{lastTransitionTime:.lastTransitionTime}' { "lastTransitionTime": "2019-05-14T07:19:28Z" } { "lastTransitionTime": "2019-05-14T07:25:06Z" } { "lastTransitionTime": "2019-05-14T07:25:06Z" } { "lastTransitionTime": "2019-05-14T07:19:28Z" }我们可以看到,我们实际上是取到了多个对象,但是它们并不是一个数组,想要获取一个数组对象,正确的操作如下:
[centos@k8s-master ~]$ kubectl get po consul-0 -ojson|jq '[.status.conditions[]|{lastTransitionTime:.lastTransitionTime}]' [ { "lastTransitionTime": "2019-05-14T07:19:28Z" }, { "lastTransitionTime": "2019-05-14T07:25:06Z" }, { "lastTransitionTime": "2019-05-14T07:25:06Z" }, { "lastTransitionTime": "2019-05-14T07:19:28Z" } ]大家仔细看看其中的差别在哪里