Skip to content

Commit 5cc1040

Browse files
authored
Merge pull request #226125 from JnHs/jh-aks-ic
expand logging info
2 parents ae8d6fa + 8a4f163 commit 5cc1040

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

articles/aks/image-cleaner.md

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ ms.author: nickoman
55
author: nickomang
66
services: container-service
77
ms.topic: article
8-
ms.date: 12/14/2022
8+
ms.date: 02/03/2023
99
---
1010

1111
# Use Image Cleaner to clean up stale images on your Azure Kubernetes Service cluster (preview)
1212

13-
It's common to use pipelines to build and deploy images on Azure Kubernetes Service (AKS) clusters. While great for image creation, this process often doesn't account for the stale images left behind and can lead to image bloat on cluster nodes. These images can present security issues as they may contain vulnerabilities. By cleaning these unreferenced images, you can remove an area of risk in your clusters. When done manually, this process can be time intensive, which Image Cleaner can mitigate via automatic image identification and removal.
13+
It's common to use pipelines to build and deploy images on Azure Kubernetes Service (AKS) clusters. While great for image creation, this process often doesn't account for the stale images left behind and can lead to image bloat on cluster nodes. These images can present security issues as they may contain vulnerabilities. By cleaning these unreferenced images, you can remove an area of risk in your clusters. When done manually, this process can be time intensive, which Image Cleaner can mitigate via automatic image identification and removal.
1414

1515
> [!NOTE]
16-
> Image Cleaner is a feature based on [Eraser](https://github.com/Azure/eraser).
16+
> Image Cleaner is a feature based on [Eraser](https://github.com/Azure/eraser).
1717
> On an AKS cluster, the feature name and property name is `Image Cleaner` while the relevant Image Cleaner pods' names contain `Eraser`.
1818
1919
[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)]
@@ -92,8 +92,7 @@ When enabled, an `eraser-controller-manager` pod is deployed on each agent node,
9292

9393
Once an `ImageList` is generated, Image Cleaner will remove all the images in the list from node VMs.
9494

95-
96-
:::image type="content" source="./media/image-cleaner/image-cleaner.jpg" alt-text="A diagram showing ImageCleaner's workflow. The ImageCleaner pods running on the cluster can generate an ImageList, or manual input can be provided.":::
95+
:::image type="content" source="./media/image-cleaner/image-cleaner.jpg" alt-text="Screenshot of a diagram showing ImageCleaner's workflow. The ImageCleaner pods running on the cluster can generate an ImageList, or manual input can be provided.":::
9796

9897
## Configuration options
9998

@@ -167,7 +166,58 @@ az aks update -g MyResourceGroup -n MyManagedCluster
167166

168167
## Logging
169168

170-
The deletion logs are stored in the `image-cleaner-kind-worker` pods. You can check these via `kubectl logs` or via the Container Insights pod log table if the [Azure Monitor add-on](./monitor-aks.md) is enabled.
169+
Deletion image logs are stored in `eraser-aks-nodepool-xxx` pods for manually deleted images, and in `eraser-collector-xxx` pods for automatically deleted images.
170+
171+
You can view these logs by running `kubectl logs <pod name> -n kubesystem`. However, this command may return only the most recent logs, since older logs are routinely deleted. To view all logs, follow these steps to enable the [Azure Monitor add-on](./monitor-aks.md) and use the Container Insights pod log table.
172+
173+
1. Ensure that Azure monitoring is enabled on the cluster. For detailed steps, see [Enable Container Insights for AKS cluster](../azure-monitor/containers/container-insights-enable-aks.md#existing-aks-cluster).
174+
175+
1. Get the Log Analytics resource ID:
176+
177+
```azurecli
178+
az aks show -g <resourceGroupofAKSCluster> -n <nameofAksCluster>
179+
```
180+
181+
After a few minutes, the command returns JSON-formatted information about the solution, including the workspace resource ID:
182+
183+
```json
184+
"addonProfiles": {
185+
"omsagent": {
186+
"config": {
187+
"logAnalyticsWorkspaceResourceID": "/subscriptions/<WorkspaceSubscription>/resourceGroups/<DefaultWorkspaceRG>/providers/Microsoft.OperationalInsights/workspaces/<defaultWorkspaceName>"
188+
},
189+
"enabled": true
190+
}
191+
}
192+
```
193+
194+
1. In the Azure portal, search for the workspace resource ID, then select **Logs**.
195+
196+
1. Copy this query into the table, replacing `name` with either `eraser-aks-nodepool-xxx` (for manual mode) or `eraser-collector-xxx` (for automatic mode).
197+
198+
```kusto
199+
let startTimestamp = ago(1h);
200+
KubePodInventory
201+
| where TimeGenerated > startTimestamp
202+
| project ContainerID, PodName=Name, Namespace
203+
| where PodName contains "name" and Namespace startswith "kube-system"
204+
| distinct ContainerID, PodName
205+
| join
206+
(
207+
ContainerLog
208+
| where TimeGenerated > startTimestamp
209+
)
210+
on ContainerID
211+
// at this point before the next pipe, columns from both tables are available to be "projected". Due to both
212+
// tables having a "Name" column, we assign an alias as PodName to one column which we actually want
213+
| project TimeGenerated, PodName, LogEntry, LogEntrySource
214+
| summarize by TimeGenerated, LogEntry
215+
| order by TimeGenerated desc
216+
```
217+
218+
1. Select **Run**. Any deleted image logs will appear in the **Results** area.
219+
220+
:::image type="content" source="media/image-cleaner/eraser-log-analytics.png" alt-text="Screenshot showing deleted image logs in the Azure portal." lightbox="media/image-cleaner/eraser-log-analytics.png":::
171221

172222
<!-- LINKS -->
173223

91.8 KB
Loading

0 commit comments

Comments
 (0)