Skip to content

Commit 20a3464

Browse files
authored
Merge pull request #9198 from blanquicet/jose/update-ig-baseline-tsg
AB#6429: Update Inspektor Gadget baseline TSG
2 parents 45ffb19 + 196b65b commit 20a3464

File tree

1 file changed

+168
-32
lines changed

1 file changed

+168
-32
lines changed

support/azure/azure-kubernetes/logs/capture-system-insights-from-aks.md

Lines changed: 168 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,52 @@ description: Learn how to use Inspektor Gadget to capture useful information f
44
author: blanquicet
55
ms.author: josebl
66
editor: v-jsitser
7-
ms.reviewer: cssakscic, josebl, v-leedennis
7+
ms.reviewer: cssakscic, josebl, v-leedennis, mayasingh
88
ms.service: azure-kubernetes-service
99
ms.topic: how-to
10-
ms.date: 08/09/2024
10+
ms.date: 07/02/2025
1111
ms.custom: sap:Monitoring and Logging
1212
---
1313

1414
# Capture real-time system insights from an AKS cluster
1515

1616
This article discusses the process of gathering real-time system insights from your Microsoft Azure Kubernetes Service (AKS) cluster by using Inspektor Gadget. The article contains step-by-step instructions for installing this tool on your AKS environment. It also explores practical examples that show how Inspektor Gadget helps you gather valuable information to do effective debugging of real-world issues.
1717

18-
## Demo
18+
## Demo: Real-time DNS troubleshooting and critical file-access alerting
1919

20-
To begin, consider the following quick demo. Suppose that you have to figure out why the DNS requests from an application fail. By using Inspektor Gadget, you can capture the DNS traffic in the Kubernetes namespace in which your application is running:
20+
To begin, consider the following quick demo. Suppose that you have to figure out why the DNS requests from an application fail. By using Inspektor Gadget, you can run the [trace_dns gadget](https://go.microsoft.com/fwlink/?linkid=2260317) to capture the DNS traffic in the Kubernetes namespace in which your application is running:
2121

2222
```bash
23-
kubectl gadget trace dns --namespace my-ns --output columns=+nameserver
23+
kubectl gadget run trace_dns \
24+
--namespace my-ns \
25+
--fields k8s.node,k8s.podName,id,qr,name,rcode,nameserver
2426
```
2527

2628
```output
27-
K8S.NODE K8S.NAMESPACE K8S.POD PID TID COMM QR TYPE QTYPE NAME RCODE NUMANSWERS NAMESERVER
28-
aks-agentpool-97833681-vmss000001 my-ns my-app 1349264 1349264 nslookup Q OUTGOING A www.example.com. 0 1.2.3.4
29-
aks-agentpool-97833681-vmss000001 my-ns my-app 1349264 1349264 nslookup Q OUTGOING AAAA www.example.com. 0 1.2.3.4
30-
aks-agentpool-97833681-vmss000001 my-ns my-app 1349264 1349264 nslookup Q OUTGOING A www.example.com. 0 1.2.3.4
31-
aks-agentpool-97833681-vmss000001 my-ns my-app 1349264 1349264 nslookup Q OUTGOING AAAA www.example.com. 0 1.2.3.4
29+
K8S.NODE K8S.PODNAME ID QR NAME RCODE NAMESERVER
30+
aks-nodepool-41788306-vmss000002 demo-pod 13cc Q example.com. 1.2.3.4
31+
aks-nodepool-41788306-vmss000002 demo-pod 13cc Q example.com. 1.2.3.4
3232
```
3333

34-
From this information, you can see that the DNS requests are directed to the DNS server at IP address `1.2.3.4`, but the server never responds.
34+
From this information, we can see that the DNS requests are directed to the DNS server at IP address `1.2.3.4` (as indicated in the `NAMESERVER` column), but we only see the queries (`Q` in the `QR` column) and no responses (`R` in the `QR` column). This means that the DNS server didn't respond to the queries, which is why the application can't resolve the domain name `www.example.com`.
3535

36-
Now, suppose that `1.2.3.4` isn't the default name server configuration, and you suspect that a suspicious process is modifying the configuration at runtime. In these kinds of cases, Inspektor Gadget goes beyond DNS diagnostics. It also enables you to monitor processes that access critical files (such as */etc/resolv.conf*) and have the intention of modifying those files. To use this monitoring feature, filter the flags in the output to show any of the [writing file access modes](https://linux.die.net/man/3/open) (`O_WRONLY` to open for writing only, or `O_RDWR` to open for reading and writing):
36+
Now, suppose that `1.2.3.4` isn't the default name server configuration, and you suspect that a malicious process is modifying the configuration at runtime. In these kinds of cases, Inspektor Gadget goes beyond DNS diagnostics. It also enables you to monitor processes that access critical files (such as */etc/resolv.conf*) and have the intention of modifying those files. To do that, run the [trace_open gadget](https://go.microsoft.com/fwlink/?linkid=2260318) in the same namespace and filter the results by the file name and the flags that indicate [the intention to write to the file](https://linux.die.net/man/3/open) (`O_WRONLY` to open for writing only, or `O_RDWR` to open for reading and writing):
3737

3838
```bash
39-
kubectl gadget trace open --namespace my-ns \
40-
--filter path:/etc/resolv.conf,flags:'~(O_WRONLY|O_RDWR)' \
41-
--output columns=+flags
39+
kubectl gadget run trace_open \
40+
--namespace my-ns \
41+
--filter fname==/etc/resolv.conf,flags~'(O_WRONLY|O_RDWR)' \
42+
--fields k8s.node,k8s.podName,comm,fname,flags,error
4243
```
4344

4445
```output
45-
K8S.NODE K8S.NAMESPACE K8S.POD K8S.CONTAINER PID COMM FD ERR PATH FLAGS
46-
aks-agentpool-97833681-vmss000001 my-ns my-app my-app 1365052 vi 3 0 /etc/resolv.conf O_WRONLY|O_CREAT
46+
K8S.NODE K8S.PODNAME COMM FNAME FLAGS ERROR
47+
aks-nodepool-41788306-vmss000002 demo-pod malicious-proc /etc/resolv.conf O_WRONLY
4748
```
4849

4950
## What is Inspektor Gadget?
5051

51-
[Inspektor Gadget](https://go.microsoft.com/fwlink/?linkid=2260072) is a framework that's designed for building, packaging, deploying, and running tools that are dedicated to debugging and inspecting Linux and Kubernetes systems. These tools ("gadgets") are implemented as [eBPF](https://go.microsoft.com/fwlink/?linkid=2259866) programs. Their primary goal is to gather low-level kernel data to provide insights into specific system scenarios. The Inspektor Gadget framework manages the association of the collected data by using high-level references, such as Kubernetes resources. This integration makes sure that a seamless connection exists between low-level insights and their corresponding high-level context. The integration streamlines the troubleshooting process and the collection of relevant information.
52+
[Inspektor Gadget](https://go.microsoft.com/fwlink/?linkid=2260072) is a framework that makes it easy to monitor, troubleshoot, and secure workloads running on Linux and Kubernetes. It consists of tools (*Gadgets*) that leverage [eBPF](https://go.microsoft.com/fwlink/?linkid=2259866) programs. Their primary goal is to gather low-level kernel data to provide insights into specific system scenarios. The Inspektor Gadget framework manages the association of the collected data by using high-level references, such as Kubernetes resources. This integration makes sure that a seamless connection exists between low-level insights and their corresponding high-level context. The integration streamlines the troubleshooting process and the collection of relevant information.
5253

5354
## Gadgets
5455

@@ -60,7 +61,6 @@ Inspektor Gadget provides a set of built-in tools that are designed to debug and
6061

6162
The gadgets present the information that they collected by using different mechanisms. For instance, some gadgets can inform you about the system status at specific times. Other gadgets can report every time a given event occurs, or they can provide periodic updates.
6263

63-
6464
These are just a few examples. The [official documentation](https://go.microsoft.com/fwlink/?linkid=2260507) provides detailed descriptions and examples of each gadget so that you can determine the most suitable gadget for your specific use case. However, if you find a use case that the existing gadgets don't currently cover, Inspektor Gadget allows you to run your own eBPF programs by using the [run command](https://go.microsoft.com/fwlink/?linkid=2259865). Because the Inspektor Gadget framework handles the building, packaging, and deployment of your custom programs, it streamlines the process for your unique requirements. Also, it gathers high-level metadata to enrich the data that you collect in your program.
6565

6666
## Use cases
@@ -70,7 +70,7 @@ To complement the demo that's presented at the beginning of this article, we com
7070
| Problem area | Symptoms | Troubleshooting |
7171
|--|--|--|
7272
| **Disk-intensive applications** | High memory or CPU usage, or inconsistent node readiness | An application might consistently engage in disk read/write operations, such as extensive logging. By using Inspektor Gadget, you can identify in real time which containers generate more [block I/O](https://go.microsoft.com/fwlink/?linkid=2260070). Or, more specifically, you can find the container that causes more reads and writes into a ⁠[file](https://go.microsoft.com/fwlink/?linkid=2260071). |
73-
| **"It's always DNS"** | High application latency, time-outs, or poor end-user experience | <p>By using Inspektor Gadget, you can [trace all the DNS](https://go.microsoft.com/fwlink/?linkid=2260317) queries and responses in the cluster. In particular, Inspektor Gadget provides the following information that helps you to determine whether the DNS is affecting your application's performance:</p> <ul> <li>Query success</li> <li>Whether the response contains an error</li> <li>The name server that's used for the lookup</li> <li>The query-response latency</li> </ul> |
73+
| **"It's always DNS"** | High application latency, timeouts, or poor end-user experience | <p>By using Inspektor Gadget, you can [trace all the DNS](https://go.microsoft.com/fwlink/?linkid=2260317) queries and responses in the cluster. In particular, Inspektor Gadget provides the following information that helps you to determine whether the DNS is affecting your application's performance:</p> <ul> <li>Query success</li> <li>Whether the response contains an error</li> <li>The name server that's used for the lookup</li> <li>The query-response latency</li> </ul> |
7474
| **File system access** | Application misbehaves or can't function correctly | <p>The application might be unable to access specific configurations, logs, or other vital files in the file system. In such scenarios, Inspektor Gadget enables you to [trace all the opened files](https://go.microsoft.com/fwlink/?linkid=2260318) inside pods to diagnose access issues. Whenever your application tries to open a file, you can discover the following information:</p> <ul> <li>The flags that are used to open the file (for example, [O_RDONLY, O_WRONLY, O_RDWR](https://linux.die.net/man/3/open), and so on)</li> <li>Whether the file opening attempt succeeds</li> <li>The returned error (if the file opening attempt fails)</li> </ul> <p>For instance, if the attempt to open the file fails because of error 2 ([ENOENT](https://man7.org/linux/man-pages/man3/errno.3.html)), the application is probably trying to open a file that doesn’t exist. This means that you might have a typo in the code, or the file is available in a different path.</p> |
7575
| **Remote code execution (RCE)** | Unauthorized code execution such as [cryptojacking](https://en.wikipedia.org/wiki/Cryptojacking) that's evident in high CPU usage during application idle periods | When attackers try to make this kind of attack on a system, they usually have to run the code by using `bash`. Inspektor Gadget enables you to [trace the creation of new processes](https://go.microsoft.com/fwlink/?linkid=2260319), particularly processes that involve critical commands such as `bash`. |
7676

@@ -86,46 +86,164 @@ By selecting the following button, an AKS cluster will be automatically created,
8686

8787
This section outlines the steps for installing Inspektor Gadget in your AKS cluster by running the `kubectl gadget` plug-in. The installation consists of two parts:
8888

89-
- Installing the `kubectl gadget` plug-in on your computer
89+
1. Installing the `kubectl gadget` plug-in on your workstation
9090

91-
- Running the `kubectl gadget` plug-in to install Inspektor Gadget in the cluster
91+
2. Running the `kubectl gadget` plug-in to deploy Inspektor Gadget in the cluster
9292

9393
> [!WARNING]
94-
> Many mechanisms are available to deploy and use Inspektor Gadget. Each of these mechanisms is tailored to specific use cases and requirements. You can use the kubectl gadget plug-in to apply several of these mechanisms, but not all of them. For instance, deploying Inspektor Gadget by using the `kubectl gadget` plug-in depends on the availability of the Kubernetes API server. If you can’t depend on such a component because its availability might be occasionally compromised, we recommend that you avoid using the `kubectl gadget`deployment mechanism. For more information about this and other use cases, see the [Inspektor Gadget documentation](https://go.microsoft.com/fwlink/?linkid=2260072).
94+
> Many mechanisms are available to deploy and use Inspektor Gadget. Each of these mechanisms is tailored to specific use cases and requirements. You can use the kubectl gadget plug-in to apply several of these mechanisms, but not all of them. For instance, deploying Inspektor Gadget by using the `kubectl gadget` plug-in depends on the availability of the Kubernetes API server. If you can’t depend on such a component because its availability might be occasionally compromised, we recommend that you avoid using the `kubectl gadget` deployment mechanism. For more information about this and other use cases, see the [Inspektor Gadget documentation](https://go.microsoft.com/fwlink/?linkid=2326106).
9595
9696
#### Prerequisites
9797

9898
- The Kubernetes [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) command-line tool. If you have [Azure CLI](/cli/azure/install-azure-cli-linux), you can run the [az aks install-cli](/cli/azure/aks#az-aks-install-cli) command to install kubectl.
9999

100100
- An AKS cluster. If you don't have an AKS cluster, [create one by using Azure CLI](/azure/aks/learn/quick-kubernetes-deploy-cli) or [by using the Azure portal](/azure/aks/learn/quick-kubernetes-deploy-portal).
101101

102-
- The [krew](https://sigs.k8s.io/krew) package manager for plug-ins in kubectl. You can follow the [krew quickstart guide](https://krew.sigs.k8s.io/docs/user-guide/quickstart/) to install this package manager.
102+
#### Part 1: Install the kubectl gadget plug-in on your workstation
103103

104-
#### Part 1: Install the kubectl plug-in gadget on your computer
104+
Use the instructions for your OS:
105105

106-
We recommend that you use `krew` to install the `kubectl gadget` plug-in.
106+
- Azure Linux 3.0
107+
- Ubuntu 18.04 / 20.04 / 22.04
107108

108109
> [!NOTE]
109-
> To install a specific release or compile it from the source, see [Install kubectl gadget](https://go.microsoft.com/fwlink/?linkid=2260075#installing-kubectl-gadget) on GitHub.
110+
> To install a specific release or compile it from the source, see [Install kubectl gadget](https://go.microsoft.com/fwlink/?linkid=2260075#installing-the-kubectl-gadget-client) on GitHub.
110111
111-
```bash
112-
kubectl krew install gadget
113-
```
112+
##### [Azure Linux 3.0](#tab/azurelinux30)
113+
114+
1. Add the Microsoft Cloud-Native repository to your system:
115+
116+
```bash
117+
echo "[azurelinux-cloud-native]
118+
name=Azure Linux Cloud Native 3.0
119+
baseurl=https://packages.microsoft.com/azurelinux/3.0/prod/cloud-native/$(uname -i)
120+
gpgkey=file:///etc/pki/rpm-gpg/MICROSOFT-RPM-GPG-KEY
121+
gpgcheck=1
122+
repo_gpgcheck=1
123+
enabled=1
124+
skip_if_unavailable=True
125+
sslverify=1
126+
" > /etc/yum.repos.d/azurelinux-cloud-native.repo
127+
```
128+
129+
2. Install the `kubectl gadget` plug-in:
130+
131+
```bash
132+
tdnf install --refresh -y kubectl-gadget
133+
```
134+
135+
##### [Ubuntu 22.04](#tab/ubuntu2204)
136+
137+
1. Get `curl` if you don't have it installed:
138+
139+
```bash
140+
apt update && apt install -y curl
141+
```
142+
143+
2. Download the Microsoft GNU Privacy Guard (GPG) public key:
144+
145+
```bash
146+
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | tee /usr/share/keyrings/microsoft.asc
147+
```
148+
149+
3. Add the Microsoft Cloud-Native repository to your system:
150+
151+
```bash
152+
echo "deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft.asc] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" | tee /etc/apt/sources.list.d/packages-microsoft-prod.list
153+
```
154+
155+
4. Update the package index:
156+
157+
```bash
158+
apt update
159+
```
160+
161+
5. Install the `kubectl gadget` plug-in:
162+
163+
```bash
164+
apt install -y kubectl-gadget
165+
```
166+
167+
##### [Ubuntu 20.04](#tab/ubuntu2004)
168+
169+
1. Get `curl` if you don't have it installed:
170+
171+
```bash
172+
apt update && apt install -y curl
173+
```
174+
175+
2. Download the Microsoft GNU Privacy Guard (GPG) public key:
176+
177+
```bash
178+
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | tee /usr/share/keyrings/microsoft.asc
179+
```
180+
181+
3. Add the Microsoft Cloud-Native repository to your system:
182+
183+
```bash
184+
echo "deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft.asc] https://packages.microsoft.com/ubuntu/20.04/prod focal main" | tee /etc/apt/sources.list.d/packages-microsoft-prod.list
185+
```
186+
187+
4. Update the package index:
188+
189+
```bash
190+
apt update
191+
```
192+
193+
5. Install the `kubectl gadget` plug-in:
194+
195+
```bash
196+
apt install -y kubectl-gadget
197+
```
198+
199+
##### [Ubuntu 18.04](#tab/ubuntu1804)
200+
201+
1. Get `curl` if you don't have it installed:
202+
203+
```bash
204+
apt update && apt install -y curl
205+
```
206+
207+
2. Download the Microsoft GNU Privacy Guard (GPG) public key:
208+
209+
```bash
210+
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | tee /usr/share/keyrings/microsoft.asc
211+
```
212+
213+
3. Add the Microsoft Cloud-Native repository to your system:
214+
215+
```bash
216+
echo "deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft.asc] https://packages.microsoft.com/ubuntu/18.04/prod bionic main" | tee /etc/apt/sources.list.d/packages-microsoft-prod.list
217+
```
218+
219+
4. Update the package index:
220+
221+
```bash
222+
apt update
223+
```
224+
225+
5. Install the `kubectl gadget` plug-in:
226+
227+
```bash
228+
apt install -y kubectl-gadget
229+
```
230+
231+
---
114232
115233
Now, verify the installation by running the `version` command:
116234
117235
```bash
118236
kubectl gadget version
119237
```
120238
121-
The `version` command shows you the version of the client (`kubectl gadget` plug-in), but it also tells you that it isn't installed yet on the server (the cluster):
239+
The command output shows you the version of the client (`kubectl gadget` plug-in) and that it isn't installed yet on the server (the cluster):
122240

123241
```output
124242
Client version: vX.Y.Z
125243
Server version: not installed
126244
```
127245

128-
#### Part 2: Install Inspektor Gadget in the cluster
246+
#### Part 2: Deploy Inspektor Gadget in the cluster
129247

130248
The following command deploys the [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) controller.
131249

@@ -155,6 +273,24 @@ Client version: vX.Y.Z
155273
Server version: vX.Y.Z
156274
```
157275

276+
When deploying Inspektor Gadget with the `kubectl gadget` plug-in available in the Microsoft Cloud-Native repository, the container image used for the DaemonSet is automatically pulled from the Microsoft Container Registry (MCR):
277+
278+
```bash
279+
kubectl get daemonset gadget -n gadget -o jsonpath='{.spec.template.spec.containers[*].image}'
280+
```
281+
282+
```output
283+
mcr.microsoft.com/oss/v2/inspektor-gadget/inspektor-gadget:vX.Y.Z
284+
```
285+
286+
> [!NOTE]
287+
> If you use the [krew](https://sigs.k8s.io/krew) package manager to install kubectl plug-ins and prefer to install Inspektor Gadget directly from its GitHub repository, you can easily install the `kubectl gadget` plug-in and deploy Inspektor Gadget in your cluster using the following commands:
288+
>
289+
> ```bash
290+
> kubectl krew install gadget
291+
> kubectl gadget deploy
292+
> ```
293+
158294
[!INCLUDE [Third-party disclaimer](../../../includes/third-party-disclaimer.md)]
159295

160296
[!INCLUDE [Third-party contact disclaimer](../../../includes/third-party-contact-disclaimer.md)]

0 commit comments

Comments
 (0)