Kubernetes 101

Sure! Here’s the blog post based on the information provided:

As a Site Reliability Engineer (SRE) working in the software-defined data center (SDDC), I have found that filtering events of specific objects can be a powerful tool for troubleshooting and monitoring. In this blog post, we will explore how to filter events using kubectl get event –field-selector involvedObject.name= -n .

In Kubernetes, events are generated when certain actions occur within the cluster, such as pods being created or deleted. These events can provide valuable information about what is happening in the cluster, but they can also be overwhelming and difficult to sift through. That’s where filtering comes in.

To filter events using kubectl get event –field-selector involvedObject.name= -n , we need to specify two things: the type of object we want to filter by, and the namespace we want to search in. The object name can be specified using the placeholder, and the namespace can be specified using the -n flag.

For example, let’s say we want to filter events that involve a specific pod, named “my-pod”. We can use the following command:

k get event –field-selector involvedObject.name=my-pod -n my-namespace

This command will return all events that involve the pod with the name “my-pod” in the “my-namespace” namespace.

But what if we want to filter events based on multiple objects? Maybe we want to see all events that involve either “my-pod” or “my-deployment”. We can use the –field-selector flag multiple times to specify multiple filters. For example:

k get event –field-selector involvedObject.name=my-pod,involvedObject.name=my-deployment -n my-namespace

This command will return all events that involve either “my-pod” or “my-deployment” in the “my-namespace” namespace.

In addition to filtering by object name, we can also filter by other fields such as time, type, and status. For example, to see all events that occurred within the last hour, we can use the following command:

k get event –field-selector time=1h -n my-namespace

This command will return all events that occurred within the last hour in the “my-namespace” namespace.

But what if we want to filter events based on a specific field that is not a built-in field like time or status? No problem! We can use the –field-path flag to specify a custom path to a field that we want to filter by. For example:

k get event –field-path involvedObject.labels=my-label -n my-namespace

This command will return all events that involve pods with the label “my-label” in the “my-namespace” namespace.

As an SRE, I have found that filtering events using kubectl get event –field-selector involvedObject.name= -n is a powerful tool for troubleshooting and monitoring the Kubernetes cluster. By specifying the object name and namespace we want to search in, we can quickly find the events that are most relevant to our needs.

In addition to filtering by object name, we can also filter by other fields such as time, type, and status. And if we need to filter based on a custom field, we can use the –field-path flag to specify a custom path to the field we want to filter by.

So the next time you need to troubleshoot or monitor your Kubernetes cluster, give filtering events a try using kubectl get event –field-selector involvedObject.name= -n . It might just become one of your go-to tools!