[MUSIC PLAYING]
SPEAKER: In this video, you will learn about Kubernetes events,
their use cases, how to view them,
and how to use them to troubleshoot
a common issue with Google Kubernetes Engine,
or GKE, clusters.
Let's get started by understanding
what Kubernetes events are.
Kubernetes events are objects that
give insights about what's happening inside a GKE cluster.
They are usually generated when a cluster's resources,
such as nodes, Pods, or containers, change state.
These events can be used to monitor your application
and cluster state, respond to failures,
and perform diagnostics.
Remember, events have a limited retention time
and will eventually be deleted.
So you must monitor and collect events as they happen.
Kubernetes events can be useful in multiple scenarios.
Here are a couple common use cases.
Pods not running within your cluster--
viewing the Kubernetes events for a Pod
can reveal why it is not running,
leading to a quick resolution.
For example, you may see ImagePullBackOff,
indicating the cluster or node is
unable to access the repository where the container image is
hosted.
A node in your cluster with a Not Ready status--
viewing the Kubernetes events can indicate
why the node is not ready.
For example, a node might have disk pressure,
indicating that the underlying node is running out
of disk space.
Kubernetes events can be viewed in three different ways
with a GKE cluster--
in the Kubernetes Engine Console,
Logging Console, and within the Terminal using Kubectl.
Before you can view the Kubernetes events,
ensure that users are granted with the appropriate identity
and access management or IAM roles.
Viewing events using the Kubernetes Engine
Console requires the following IAM roles--
Kubernetes Engine Viewer, Kubernetes Engine Cluster
Viewer, and Logging Logs Viewer.
Viewing events using the Logging Console requires
only the following IAM roles--
Logging Logs Viewer.
To view Kubernetes events in the Terminal using Kubectl,
your credentials must have at least the default cluster role
view or a cluster role that allows access
to the Resource Events and the ability
to call get, list, and watch.
Let's now look at how to view Kubernetes events.
Within Google Cloud, you can view events
across all levels of the Kubernetes hierarchy,
including cluster, nodes, and workloads.
Remember, for Kubernetes clusters,
events are only available for about 60 minutes.
For GKE, events are exported and are available using the Logging
Console.
Next, you can view Kubernetes events
in Cloud Logging with the following query--
log_ID("events") and resource.label.cluster
name="CLUSTER NAME".
Finally, you can view Kubernetes events from Kubectl
by running kubectl events -A or, for a specific resource,
kubectl events --for the resource
forward slash the resource name.
For example, kubectl events --for pod/ubuntu.
Another useful way to view events
is with the describe command for a specific resource.
For example, kubectl describe pod ubuntu.
The Kubernetes events for the specific resource
are included at the bottom of the output.
Let's dive into a demo and check out
how to use Kubernetes events for troubleshooting a common issue
in the GKE cluster.
This cluster has a number of workloads running,
but there appears to be one workload with no Pods running.
Let's get the Kubernetes events for the Pod in this deployment
by running the following command--
kubectl events -n k8sevents --for the Pod, forward slash,
and the Pod name.
Oh, it looks like there's insufficient memory
in the cluster for the Pod to be scheduled.
The solution here is to scale up.
So let's add more nodes.
Now that the additional notes are ready,
let's check the status of the workload.
Hm, eventsdeployment workload still has no Pods running.
Let's view the events again.
The pods are unscheduled, as they could not
meet the taint and toleration requirement to be
scheduled on the new node.
Let's add the toleration to the workload.
Success.
All the Pods in the workload are running.
This is just one scenario where Kubernetes events assisted us
in quickly identifying and resolving
our issue of a deployment not running.
The next time you see a problem with your cluster,
try using Kubernetes events to identify and resolve issues.
For more details about Kubernetes events,
check out the following documentation.
Thanks for watching.
[MUSIC PLAYING]