|
| 1 | +--- |
| 2 | +title: Use Kubernetes events for troubleshooting |
| 3 | +description: Learn about Kubernetes events, which provide details on pods, nodes, and other Kubernetes objects. |
| 4 | +ms.topic: article |
| 5 | +ms.author: nickoman |
| 6 | +author: nickomang |
| 7 | +ms.date: 09/07/2023 |
| 8 | +--- |
| 9 | + |
| 10 | +# Kubernetes events for troubleshooting |
| 11 | + |
| 12 | +Events are one of the most prominent sources for monitoring and troubleshooting issues in Kubernetes. They capture and record information about the lifecycle of various Kubernetes objects, such as pods, nodes, services, and deployments. By monitoring events, you can gain visibility into your cluster's activities, identify issues, and troubleshoot problems effectively. |
| 13 | + |
| 14 | +Kubernetes events do not persist throughout your cluster life cycle, as there is no mechanism for retention. They are short-lived, only available for one hour after the event is generated. To store events for a longer time period, enable [Container Insights][container-insights]. |
| 15 | + |
| 16 | +## Kubernetes event objects |
| 17 | + |
| 18 | +Below is a set of the important fields in a Kubernetes Event. For a comprehensive list of all fields, check the official [Kubernetes documentation][k8s-events]. |
| 19 | + |
| 20 | +|Field name|Significance| |
| 21 | +|----------|------------| |
| 22 | +|type |Significance changes based on the severity of the event:<br/>**Warning:** these events signal potentially problematic situations, such as a pod repeatedly failing or a node running out of resources. They require attention, but might not result in immediate failure.<br/>**Normal:** These events represent routine operations, such as a pod being scheduled or a deployment scaling up. They usually indicate healthy cluster behavior.| |
| 23 | +|reason|The reason why the event was generated. For example, *FailedScheduling* or *CrashLoopBackoff*.| |
| 24 | +|message|A human-readable message that describes the event.| |
| 25 | +|namespace|The namespace of the Kubernetes object that the event is associated with.| |
| 26 | +|firstSeen|Timestamp when the event was first observed.| |
| 27 | +|lastSeen|Timestamp of when the event was last observed.| |
| 28 | +|reportingController|The name of the controller that reported the event. For example, `kubernetes.io/kubelet`| |
| 29 | +|object|The name of the Kubernetes object that the event is associated with.| |
| 30 | + |
| 31 | +## Accessing events |
| 32 | + |
| 33 | +# [Azure CLI](#tab/azure-cli) |
| 34 | + |
| 35 | +You can find events for your cluster and its components by using `kubectl`. |
| 36 | + |
| 37 | +```azurecli-interactive |
| 38 | +kubectl get events |
| 39 | +``` |
| 40 | + |
| 41 | +To look at a specific pod's events, first find the name of the pod and then use `kubectl describe` to list events. |
| 42 | + |
| 43 | +```azurecli-interactive |
| 44 | +kubectl get pods |
| 45 | +
|
| 46 | +kubectl describe pods <pod-name> |
| 47 | +``` |
| 48 | + |
| 49 | +# [Portal](#tab/azure-portal) |
| 50 | + |
| 51 | +You can browse the events for your cluster by navigating to **Events** under **Kubernetes resources** from the Azure portal overview page for your cluster. By default, all events are shown. |
| 52 | + |
| 53 | +:::image type="content" source="./media/events/filter-all-inline.png" alt-text="Screenshot of the Azure portal page for the AKS cluster is shown. 'Events' is selected, and the filter 'Type equals all' is highlighted." lightbox="./media/events/filter-all.png"::: |
| 54 | + |
| 55 | +You can also filter by event type: |
| 56 | + |
| 57 | +:::image type="content" source="./media/events/filter-warning-inline.png" alt-text="Screenshot of the Azure portal page for the AKS cluster is shown. 'Events' is selected, and the filter 'Type equals warning' is highlighted." lightbox="./media/events/filter-warning.png"::: |
| 58 | + |
| 59 | +by reason: |
| 60 | + |
| 61 | +:::image type="content" source="./media/events/filter-reason-inline.png" alt-text="Screenshot of the Azure portal page for the AKS cluster is shown. 'Events' is selected, and the filter 'Reason equals all' is highlighted." lightbox="./media/events/filter-reason.png"::: |
| 62 | + |
| 63 | +or by pods or nodes: |
| 64 | + |
| 65 | +:::image type="content" source="./media/events/filter-pod-node-inline.png" alt-text="Screenshot of the Azure portal page for the AKS cluster is shown. 'Events' is selected, and the filter 'Object equals all' is highlighted." lightbox="./media/events/filter-pod-node.png"::: |
| 66 | + |
| 67 | +These filters can be combined to scope the query to your specific needs. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Best practices for troubleshooting with events |
| 72 | + |
| 73 | +### Filtering events for relevance |
| 74 | + |
| 75 | +In your AKS cluster, you might have various namespaces and services running. Filtering events based on object type, namespace, or reason can help you narrow down your focus to what's most relevant to your applications. For instance, you can use the following command to filter events within a specific namespace: |
| 76 | + |
| 77 | +```azurecli-interactive |
| 78 | +kubectl get events -n <namespace> |
| 79 | +``` |
| 80 | + |
| 81 | +### Automating event notifications |
| 82 | + |
| 83 | +To ensure timely response to critical events in your AKS cluster, set up automated notifications. Azure offers integration with monitoring and alerting services like [Azure Monitor][aks-azure-monitor]. You can configure alerts to trigger based on specific event patterns. This way, you're immediately informed about crucial issues that require attention. |
| 84 | + |
| 85 | +### Regularly reviewing events |
| 86 | + |
| 87 | +Make a habit of regularly reviewing events in your AKS cluster. This proactive approach can help you identify trends, catch potential problems early, and prevent escalations. By staying on top of events, you can maintain the stability and performance of your applications. |
| 88 | + |
| 89 | +## Next steps |
| 90 | + |
| 91 | +Now that you understand Kubernetes events, you can continue your monitoring and observability journey by [enabling Container Insights][container-insights]. |
| 92 | + |
| 93 | +<!-- LINKS --> |
| 94 | +[aks-azure-monitor]: ./monitor-aks.md |
| 95 | +[container-insights]: ../azure-monitor/containers/container-insights-enable-aks.md |
| 96 | +[k8s-events]: https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/event-v1/ |
0 commit comments