|
| 1 | +--- |
| 2 | +title: View Azure Kubernetes Service (AKS) container logs, events, and pod metrics in real time |
| 3 | +description: Learn how to view Azure Kubernetes Service (AKS) container logs, events, and pod metrics in real time using Container Insights. |
| 4 | +author: schaffererin |
| 5 | +ms.service: azure-kubernetes-service |
| 6 | +ms.topic: how-to |
| 7 | +ms.author: schaffererin |
| 8 | +ms.date: 11/01/2023 |
| 9 | +--- |
| 10 | + |
| 11 | +# View Azure Kubernetes Service (AKS) container logs, events, and pod metrics in real time |
| 12 | + |
| 13 | +In this article, you learn how to use the *live data* feature in Container Insights to view Azure Kubernetes Service (AKS) container logs, events, and pod metrics in real time. This feature provides direct access to `kubectl logs -c`, `kubectl get` events, and `kubectl top pods` to help you troubleshoot issues in real time. |
| 14 | + |
| 15 | +> [!NOTE] |
| 16 | +> AKS uses [Kubernetes cluster-level logging architectures][kubernetes-cluster-architecture]. The container logs are located inside `/var/log/containers` on the node. To access a node, see [Connect to Azure Kubernetes Service (AKS) cluster nodes][node-access]. |
| 17 | +
|
| 18 | +## Before you begin |
| 19 | + |
| 20 | +For help with setting up the *live data* feature, see [Configure live data in Container Insights][configure-live-data]. This feature directly accesses the Kubernetes API. For more information about the authentication model, see [Kubernetes API][kubernetes-api]. |
| 21 | + |
| 22 | +## View AKS resource live logs |
| 23 | + |
| 24 | +> [!NOTE] |
| 25 | +> To access logs from a private cluster, you need to be on a machine on the same private network as the cluster. |
| 26 | +
|
| 27 | +1. In the [Azure portal][azure-portal], navigate to your AKS cluster. |
| 28 | +2. Under **Kubernetes resources**, select **Workloads**. |
| 29 | +3. Select the *Deployment*, *Pod*, *Replica Set*, *Stateful Set*, *Job* or *Cron Job* that you want to view logs for, and then select **Live Logs**. |
| 30 | +4. Select the resource you want to view logs for. |
| 31 | + |
| 32 | + The following example shows the logs for a *Pod* resource: |
| 33 | + |
| 34 | + :::image type="content" source="./media/container-insights-live-data/live-data-deployment.png" alt-text="Screenshot that shows the deployment of live logs." lightbox="./media/container-insights-live-data/live-data-deployment.png"::: |
| 35 | + |
| 36 | +## View live logs |
| 37 | + |
| 38 | +You can view real time log data as it's generated by the container engine on the *Cluster*, *Nodes*, *Controllers*, or *Containers*. |
| 39 | + |
| 40 | +1. In the [Azure portal][azure-portal], navigate to your AKS cluster. |
| 41 | +2. Under **Monitoring**, select **Insights**. |
| 42 | +3. Select the *Cluster*, *Nodes*, *Controllers*, or *Containers* tab, and then select the object you want to view logs for. |
| 43 | +4. On the resource **Overview**, select **Live Logs**. |
| 44 | + |
| 45 | + > [!NOTE] |
| 46 | + > To view the data from your Log Analytics workspace, select **View Logs in Log Analytics**. To learn more about viewing historical logs, events, and metrics, see [How to query logs from Container Insights][log-query]. |
| 47 | +
|
| 48 | + After successful authentication, if data can be retrieved, it begins streaming to the Live Logs tab. You can view log data here in a continuous stream. The following image shows the logs for a *Container* resource: |
| 49 | + |
| 50 | + :::image type="content" source="./media/container-insights-live-data/container-live-logs.png" alt-text="Screenshot that shows the container Live Logs view data option." lightbox="./media/container-insights-live-data/container-live-logs.png"::: |
| 51 | + |
| 52 | +## View live events |
| 53 | + |
| 54 | +You can view real-time event data as it's generated by the container engine on the *Cluster*, *Nodes*, *Controllers*, or *Containers*. |
| 55 | + |
| 56 | +1. In the [Azure portal][azure-portal], navigate to your AKS cluster. |
| 57 | +2. Under **Monitoring**, select **Insights**. |
| 58 | +3. Select the *Cluster*, *Nodes*, *Controllers*, or *Containers* tab, and then select the object you want to view events for. |
| 59 | +4. On the resource **Overview** page, select **Live Events**. |
| 60 | + |
| 61 | + > [!NOTE] |
| 62 | + > To view the data from your Log Analytics workspace, select **View Events in Log Analytics**. To learn more about viewing historical logs, events, and metrics, see [How to query logs from Container Insights][log-query]. |
| 63 | +
|
| 64 | + After successful authentication, if data can be retrieved, it begins streaming to the Live Events tab. The following image shows the events for a *Container* resource: |
| 65 | + |
| 66 | + :::image type="content" source="./media/container-insights-live-data/container-live-events.png" alt-text="Screenshot that shows the container Live Events view data option." lightbox="./media/container-insights-live-data/container-live-events.png"::: |
| 67 | + |
| 68 | +## View metrics |
| 69 | + |
| 70 | +You can view real-time metrics data as it's generated by the container engine on the *Nodes* or *Controllers* by selecting a *Pod* resource. |
| 71 | + |
| 72 | +1. In the [Azure portal][azure-portal], navigate to your AKS cluster. |
| 73 | +2. Under **Monitoring**, select **Insights**. |
| 74 | +3. Select the *Nodes* or *Controllers* tab, and then select the *Pod* object you want to view metrics for. |
| 75 | +4. On the resource **Overview** page, select **Live Metrics**. |
| 76 | + |
| 77 | + > [!NOTE] |
| 78 | + > To view the data from your Log Analytics workspace, select **View Events in Log Analytics**. To learn more about viewing historical logs, events, and metrics, see [How to query logs from Container Insights][log-query]. |
| 79 | +
|
| 80 | + After successful authentication, if data can be retrieved, it begins streaming to the Live Metrics tab. The following image shows the metrics for a *Pod* resource: |
| 81 | + |
| 82 | + :::image type="content" source="./media/container-insights-live-data/pod-live-metrics.png" alt-text="Screenshot that shows the pod Live Metrics view data option." lightbox="./media/container-insights-live-data/pod-live-metrics.png"::: |
| 83 | + |
| 84 | +## Next steps |
| 85 | + |
| 86 | +For more information about monitoring on AKS, see the following articles: |
| 87 | + |
| 88 | +* [Azure Kubernetes Service (AKS) diagnose and solve problems][aks-diagnose-solve-problems] |
| 89 | +* [Monitor Kubernetes events for troubleshooting][aks-monitor-events] |
| 90 | + |
| 91 | +<!-- LINKS --> |
| 92 | +[kubernetes-cluster-architecture]: https://kubernetes.io/docs/concepts/cluster-administration/logging/#cluster-level-logging-architectures |
| 93 | +[node-access]: ./node-access.md |
| 94 | +[configure-live-data]: ../azure-monitor/containers/container-insights-livedata-setup.md |
| 95 | +[kubernetes-api]: https://kubernetes.io/docs/concepts/overview/kubernetes-api/ |
| 96 | +[azure-portal]: https://portal.azure.com/ |
| 97 | +[log-query]: ../azure-monitor/containers/container-insights-log-query.md |
| 98 | +[aks-diagnose-solve-problems]: ./aks-diagnostics.md |
| 99 | +[aks-monitor-events]: ./events.md |
0 commit comments