inspektor-gadget/inspektor-gadget
GitHub: inspektor-gadget/inspektor-gadget
一套利用 eBPF 在 Kubernetes 和 Linux 上进行系统级数据收集、故障排查和可观测性增强的框架与工具集。
Stars: 2895 | Forks: 359
[](https://github.com/inspektor-gadget/inspektor-gadget/actions/workflows/inspektor-gadget.yml)
[](https://pkg.go.dev/github.com/inspektor-gadget/inspektor-gadget)
[](https://goreportcard.com/report/github.com/inspektor-gadget/inspektor-gadget)
[](https://www.bestpractices.dev/projects/7962)
[](https://scorecard.dev/viewer/?uri=github.com/inspektor-gadget/inspektor-gadget)
[](https://inspektor-gadget.github.io/ig-test-reports)
[](https://inspektor-gadget.github.io/ig-benchmarks/dev/bench)
[](https://github.com/inspektor-gadget/inspektor-gadget/releases)
[](https://artifacthub.io/packages/search?repo=gadgets)
[](https://artifacthub.io/packages/helm/gadget/gadget)
[](https://kubernetes.slack.com/messages/inspektor-gadget/)
[](https://github.com/inspektor-gadget/inspektor-gadget/blob/main/LICENSE)
[](https://github.com/inspektor-gadget/inspektor-gadget/blob/main/LICENSE-bpf.txt)
Inspektor Gadget 是一套用于在 Kubernetes 集群和 Linux 主机上使用 [eBPF](https://ebpf.io/) 进行数据收集和系统检查的工具和框架。它负责打包、部署和执行 Gadgets(封装在 [OCI images](https://opencontainers.org/) 中的 eBPF 程序),并提供机制来自定义和扩展 Gadget 的功能。
**注意**:v0.31.0 版本发布了重大的新功能。请阅读[博客文章了解详细概述](https://inspektor-gadget.io/blog/2024/08/empowering-observability_the_advent_of_image_based_gadgets)。
## 功能
* 将 eBPF 程序构建并打包成称为 Gadgets 的 OCI images
* 目标涵盖 Kubernetes 集群和 Linux 主机
* 通过简单的命令和声明式配置收集数据并导出到可观测性工具
* 提供安全机制以限制和锁定可以运行的 Gadgets
* 自动[enrichment](#what-is-enrichment):将内核数据映射到 Kubernetes 和容器运行时等高级资源
* 支持 [WebAssembly](https://webassembly.org/) 模块对数据进行后处理并自定义 IG [operators](#what-is-an-operator);可使用任何支持 WASM 的语言
* 支持多种操作模式;cli、客户端-服务器、API、通过 Golang 库嵌入
## 快速开始
以下示例使用 [trace_open](https://www.inspektor-gadget.io/docs/latest/gadgets/trace_open) Gadget,它会在系统上打开文件时触发。
### Kubernetes
#### 部署到集群
[krew](https://sigs.k8s.io/krew) 是推荐的安装
`kubectl gadget` 的方式。您可以按照
[krew 的快速开始指南](https://krew.sigs.k8s.io/docs/user-guide/quickstart/)
进行安装,然后执行以下命令来安装 `kubectl gadget`。
```
kubectl krew install gadget
kubectl gadget deploy
kubectl gadget run trace_open:latest
```
查看[在 Kubernetes 上安装](https://www.inspektor-gadget.io/docs/latest/reference/install-kubernetes)以了解更多不同选项。
`kubectl-gadget` 也针对以下发行版进行了打包:
[](https://repology.org/project/kubectl-gadget/versions)
### Kubectl Node Debug
我们可以使用 [kubectl node debug](https://kubernetes.io/docs/tasks/debug/debug-cluster/kubectl-node-debug/) 在 Kubernetes 节点上运行 `ig`:
```
kubectl debug --profile=sysadmin node/minikube-docker -ti --image=ghcr.io/inspektor-gadget/ig:latest -- ig run trace_open:latest
```
有关如何在 Kubernetes 上免安装使用 `ig` 的更多信息,请参阅 [ig 文档](https://www.inspektor-gadget.io/docs/latest/reference/ig#using-ig-with-kubectl-debug-node)。
### Linux
#### 本地安装
在 Linux 上本地安装 `ig` 二进制文件并运行 Gadget:
```
IG_ARCH=amd64
IG_VERSION=$(curl -s https://api.github.com/repos/inspektor-gadget/inspektor-gadget/releases/latest | jq -r .tag_name)
curl -sL https://github.com/inspektor-gadget/inspektor-gadget/releases/download/${IG_VERSION}/ig-linux-${IG_ARCH}-${IG_VERSION}.tar.gz | sudo tar -C /usr/local/bin -xzf - ig
sudo ig run trace_open:latest
```
查看[在 Linux 上安装](https://www.inspektor-gadget.io/docs/latest/reference/install-linux)以了解更多。
`ig` 也针对以下发行版进行了打包:
[](https://repology.org/project/inspektor-gadget/versions)
#### 在容器中运行
```
docker run -ti --rm --privileged -v /:/host --pid=host ghcr.io/inspektor-gadget/ig:latest run trace_open:latest
```
有关如何在 Linux 上免安装使用 `ig` 的更多信息,请查看[在容器中使用 ig](https://www.inspektor-gadget.io/docs/latest/reference/ig#using-ig-in-a-container)。
### MacOS 或 Windows
通过使用 `gadgetctl` 二进制文件,可以从不同的操作系统控制运行在 Linux 上的 `ig`。
在 Linux 机器上运行以下命令,使 `ig` 对客户端可用。
```
sudo ig daemon --tls-insecure --host=tcp://0.0.0.0:1234
```
下载适用于 MacOS
([amd64](https://github.com/inspektor-gadget/inspektor-gadget/releases/download/v0.30.0/gadgetctl-darwin-amd64-v0.30.0.tar.gz),
[arm64](https://github.com/inspektor-gadget/inspektor-gadget/releases/download/v0.30.0/gadgetctl-darwin-arm64-v0.30.0.tar.gz))或 [windows](https://github.com/inspektor-gadget/inspektor-gadget/releases/download/v0.30.0/gadgetctl-windows-amd64-v0.30.0.tar.gz) 的 `gadgetctl` 工具,并指定该 Linux 机器的 IP 地址来运行 Gadget:
```
gadgetctl run trace_open:latest --remote-address=tcp://$IP:1234
```
***上面演示了最简单的命令。要了解如何进行过滤、导出等操作,请查阅 [run](https://www.inspektor-gadget.io/docs/latest/reference/run) 命令的文档***。
## 核心概念
### 什么是 Gadget?
Gadgets 是 Inspektor Gadget 框架的核心组件。Gadget 是一个 [OCI image](https://opencontainers.org/),包含一个或多个 eBPF 程序、元数据 YAML 文件,以及可选的用于后处理的 WASM 模块。
作为 OCI images,它们可以存储在容器仓库(符合 OCI 规范)中,从而易于分发和共享。
Gadgets 是使用 [`ig image build`](https://www.inspektor-gadget.io/docs/latest/gadget-devel/building) 命令构建的。
您可以在 [Artifact HUB](https://artifacthub.io/packages/search?kind=22) 上找到不断增长的 Gadgets 集合。这包括内置 Gadgets(托管在此 git 仓库的 [/gadgets](./gadgets/README.md) 目录中)以及第三方 Gadgets。
有关更多信息,请参阅 [Gadget 文档](https://www.inspektor-gadget.io/docs/latest/gadgets/)。
### 什么是 enrichment?
eBPF 从内核收集的数据不包含有关 Kubernetes、容器运行时或任何其他高级用户空间概念的知识。为了将这些数据与这些高级概念关联起来,并使 eBPF 数据直接变得更容易理解,Inspektor Gadget 会自动使用 mount namespaces、pids 或类似的内核原语来推断它们关联的是哪些高级概念:Kubernetes pods、容器名称、DNS 名称等。这种使用高级概念增强 eBPF 数据的过程称为 *enrichment*。
Enrichment 也可以反向流动。Inspektor Gadget 允许用户仅通过引用 Kubernetes pods、容器名称等高级概念来进行高性能的内核级过滤;并自动将这些概念转换为相应的低级内核资源。
### 什么是 operator?
在 Inspektor Gadget 中,operator 是指框架中执行特定操作的任何部分。一些 operator 是底层运行的(例如获取和加载 Gadgets),而其他则是面向用户暴露的(如 enrichment、过滤、导出等),并且可以被重新排序和覆盖。
### 进一步学习
使用[项目文档](https://www.inspektor-gadget.io/docs/latest/)了解更多关于:
* [参考](https://www.inspektor-gadget.io/docs/latest/reference)
* [Gadgets](https://www.inspektor-gadget.io/docs/latest/gadgets)
* [贡献](https://www.inspektor-gadget.io/docs/latest/devel/contributing/)
## 内核要求
内核要求很大程度上取决于 Gadget 所使用的特定 eBPF 功能。
Gadgets 可用的 eBPF 功能取决于加载 Gadget 的节点/机器上运行的内核的版本和配置。由 Inspektor Gadget 项目开发的 Gadgets 至少需要启用 [BTF](https://www.kernel.org/doc/html/latest/bpf/btf.html) 的 Linux 5.10。
有关要求的任何说明,请参阅[特定 Gadget 的文档](https://www.inspektor-gadget.io/docs/latest/gadgets)。
## 代码示例
[此](./examples/)文件夹中有一些示例,展示了 Inspektor Gadget 提供的 Golang 包的使用方法。这些示例专为想要直接使用 Inspektor Gadget 暴露的 Golang 包的开发者而设计。最终用户不需要这些,可以直接使用 `kubectl-gadget` 或 `ig`。
## 安全特性
Inspektor Gadget 提供了安全特性,详见以下文档:
* [验证资产](https://inspektor-gadget.io/docs/latest/reference/verify-assets):涵盖有关镜像和发布资产的签名和验证的所有内容。它还展示了我们生成的各种 SBOM,例如 [`ig`](https://github.com/inspektor-gadget/inspektor-gadget/releases/download/v0.38.0/ig-linux-amd64-v0.38.0.bom.json) 的 SBOM。
* [限制 Gadgets](https://inspektor-gadget.io/docs/latest/reference/restricting-gadgets):详细说明了用户如何根据不同的过滤器来限制可以运行的 Gadgets。
## 近期视频
- 演讲:[From Kernel To Cloud: Building a Complete Open Source Observability Pipeline, OpenSearch Con NA - 2025年9月](https://opensearchconna2025.sched.com/event/25Gp0/from-kernel-to-cloud-building-a-complete-open-source-observability-pipeline-anirudha-jadhav-shenoy-pratik-gurudatt-amazon-web-services) ([视频](https://www.youtube.com/watch?v=oWZnSS7mtK4), [幻灯片](https://static.sched.com/hosted_files/opensearchconna2025/a8/From%20Kernel%20To%20Cloud_%20Building%20a%20Complete%20Open%20Source%20Observability%20Pipeline_final.pdf))
- 演讲:[Demystifying DNS: A Guide to Understanding and Debugging Request Flows in Kubernetes Clusters, Container Days Hamburg - 2024年9月](https://www.youtube.com/watch?v=KQpZg_NqbZw)
- 演讲:[eBPF Data Collection for Everyone – empowering the community to obtain Linux insights using Inspektor Gadget](https://www.youtube.com/watch?v=tkKXdaqji9c)
- 演讲:[Collecting Low-Level Metrics with eBPF, KubeCon + CloudNativeCon North America 2023](https://kccncna2023.sched.com/event/a70c0a016973beb5705f5f72fa58f622) ([视频](https://www.youtube.com/watch?v=_ft3iTw5uv8), [幻灯片](https://static.sched.com/hosted_files/kccncna2023/91/Collecting%20Low-Level%20Metrics%20with%20eBPF.pdf))
- 访谈:[Kubernetes Security and Troubleshooting Multitool: Inspektor Gadget](https://www.youtube.com/watch?v=0GDYDYhPPRw)
- 访谈:[Enlightning - Go Go Gadget! Inspektor Gadget and Observability](https://www.youtube.com/watch?v=Io6vqHitTzQ)
- 演讲:[Misc - Feat. Kepler, Inspektor Gadget, k8sgpt, Perses, and Pixie (You Choose!, Ch. 04, Ep. 09)](https://youtu.be/OZE1hoT9-gs?t=1267)
## 致谢
* [BPF Compiler Collection (BCC)](https://github.com/iovisor/bcc):部分 Gadgets 是基于 BCC 工具的。
* [kubectl-trace](https://github.com/iovisor/kubectl-trace):Inspektor Gadget 的架构受到了 kubectl-trace 的启发。
* [cilium/ebpf](https://github.com/cilium/ebpf):Gadget 追踪器管理器和其他一些 Gadgets 使用了 cilium/ebpf 库。
## 许可证
Inspektor Gadget 用户空间组件采用 [Apache License, Version 2.0](LICENSE) 授权。BPF 代码模板采用 [General Public License, Version 2.0, with the Linux-syscall-note](LICENSE-bpf.txt) 授权。
标签:AI工具, API集成, Docker镜像, 可观测性, 子域名生成, 子域名突变, 客户端加密, 日志审计