How can I filter events for the cluster autoscaler in kubernetes?

12/4/2019

I see the following event from kubectl get events:

  {
        "apiVersion": "v1",
        "count": 1,
        "eventTime": null,
        "firstTimestamp": "2019-12-04T19:52:51Z",
        "involvedObject": {
            "apiVersion": "v1",
            "kind": "Pod",
            "name": "example-deployment-55f789d54c-tlwnz",
            "namespace": "default",
            "resourceVersion": "82663",
            "uid": "2fdbd034-16cf-11ea-bc4a-42010a800186"
        },
        "kind": "Event",
        "lastTimestamp": "2019-12-04T19:52:51Z",
        "message": "Unable to mount volumes for pod \"example-deployment-55f789d54c-tlwnz_default(2fdbd034-16cf-11ea-bc4a-42010a800186)\": timeout expired waiting for volumes to attach or mount for pod \"default\"/\"example-deployment-55f789d54c-tlwnz\". list of unmounted volumes=[nfs-volume]. list of unattached volumes=[nfs-volume default-token-kc7ks]",
        "metadata": {
            "creationTimestamp": "2019-12-04T19:52:51Z",
            "name": "example-deployment-55f789d54c-tlwnz.15dd430deb31e8fd",
            "namespace": "default",
            "resourceVersion": "1529",
            "selfLink": "/api/v1/namespaces/default/events/example-deployment-55f789d54c-tlwnz.15dd430deb31e8fd",
            "uid": "a7c80266-16cf-11ea-bc4a-42010a800186"
        },
        "reason": "FailedMount",
        "reportingComponent": "",
        "reportingInstance": "",
        "source": {
            "component": "kubelet",
            "host": "gke-test-a2e50ea5b9f1dd9-my-node-pool-5a20b1ac-vk9q"
        },
        "type": "Warning"
    }

....

I've tried filtering by: kubectl get events --all-namespaces -o json --field-selector source.component=cluster-autoscaler but that errors with:

{
    "apiVersion": "v1",
    "items": [],
    "kind": "List",
    "metadata": {
        "resourceVersion": "",
        "selfLink": ""
    }
}
Error from server (BadRequest): Unable to find "/v1, Resource=events" that match label selector "", field selector "source.component=cluster-autoscaler": field label not supported: source.component

How can I filter this?

-- Chris Stryczynski
kubernetes

1 Answer

12/4/2019

Can be done using jq (though it does not return a JSON array - but individual JSON objects seperated by newlines):

kubectl get events --all-namespaces  -o json | jq '.items[]|select(.source.component=="cluster-autoscaler")'
-- Chris Stryczynski
Source: StackOverflow