Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
After you install the Inspektor Gadget cluster extension, use the kubectl gadget plugin to run gadgets. A gadget is a purpose-built tool that captures a specific kind of system activity, such as DNS queries, file access, process execution, or network connections, and correlates it with Kubernetes metadata.
To install the extension, see Install and configure the Inspektor Gadget extension on AKS.
Tip
The examples in this article use a few common gadgets. To browse all available gadgets and choose the right one for your task, see the Inspektor Gadget gadget catalog.
Important
AKS preview features are available on a self-service, opt-in basis. Previews are provided "as is" and "as available," and they're excluded from the service-level agreements and limited warranty. AKS previews are partially covered by customer support on a best-effort basis. As such, these features aren't meant for production use. For more information, see the following support articles:
Prerequisites
The Inspektor Gadget extension installed on your AKS cluster. See Install and configure the Inspektor Gadget extension on AKS.
The
kubectl gadgetplugin to run gadgets. You can run gadgets without any local setup by using Azure Cloud Shell, which has thekubectl gadgetplugin preinstalled. Select Try it on any code block in this article to open Cloud Shell. To learn more, see Overview of Azure Cloud Shell.To run gadgets from your own workstation instead, install the
kubectl gadgetplugin with Krew:kubectl krew install gadgetAlternatively, download the
kubectl-gadgetbinary from the Inspektor Gadget releases page and add it to yourPATH. Verify the installation:kubectl gadget version
Tip
The kubectl gadget plug-in is also available from the Microsoft Cloud-Native package repository at packages.microsoft.com for Azure Linux and Ubuntu. After you add the repository, install it by using the OS package manager, such as tdnf install -y kubectl-gadget on Azure Linux or apt install -y kubectl-gadget on Ubuntu.
Scope a gadget
You can scope a gadget to a namespace, a pod, or the entire cluster:
- Use
--namespace <namespace>to limit a gadget to a single namespace. - Use
--all-namespacesto run a gadget across the whole cluster. - Use
--timeout <seconds>to stop the gadget after a set duration. - Use
--fields <field-list>to choose which columns appear in the output.
Trace DNS queries
Capture DNS queries and responses with the originating pod:
kubectl gadget run trace_dns \
--namespace default \
--timeout 30 \
--fields k8s.node,k8s.podName,id,qr,name,rcode,nameserver
Successful lookups show an rcode of NoError.
Trace file access
Record file open events, including the file name and access flags:
kubectl gadget run trace_open \
--namespace default \
--timeout 30 \
--fields k8s.node,k8s.podName,comm,fname,flags,error
The flags field shows the access mode, such as O_RDONLY for reads and O_WRONLY for writes.
Trace process execution
Report process creation events with the command, PID, and arguments:
kubectl gadget run trace_exec \
--namespace default \
--timeout 30 \
--fields k8s.node,k8s.podName,comm,pid,args
The comm field shows the name of the executed binary.
Trace TCP connections
Capture TCP accept and close events with source and destination addresses across all namespaces:
kubectl gadget run trace_tcp \
--all-namespaces \
--timeout 30