Popeye


概览与定位

Popeye 是由 derailed 团队开源的 Kubernetes 集群资源 “Sanitizer”,它以只读方式扫描集群内的各种资源(如 Pod、Service、Ingress、PVC、RBAC 等),并基于社区最佳实践给出问题等级修复建议,覆盖配置误区、资源浪费及失效对象等场景,帮助运维/SRE 团队快速定位隐患并闭环治理。

  • 轻量 & 多平台:支持 Linux/macOS/Windows
  • 多种输出格式:彩色终端、高亮 JSON、HTML 报表、Prometheus 指标
  • 可定制 SpinachYAML:细粒度调整 Linter 阈值、排除规则、自定义严重级别(测试未到到预期)
  • CronJob & 容器化:能以 Kubernetes CronJob、GitHub Actions、GitLab CI 等方式实现持续扫描

安装方式

1. 官方二进制包(跨平台)

从 GitHub Releases 页面下载适合平台的 tarball,解压后将 popeye 可执行文件放入 $PATH

curl -LO https://github.com/derailed/popeye/releases/download
tar zxvf popeye_X.Y.Z_Linux_x86_64.tar.gz
sudo mv popeye /usr/local/bin/
:contentReference[oaicite:5]{index=5}

2. Homebrew / Linuxbrew(macOS & Linux)

brew install derailed/popeye/popeye

自动拉取最新稳定版,安装更简洁。

3. Go Install (Go ≥1.21)

go install github.com/derailed/popeye@latest

可执行文件位于 $GOPATH/bin/popeye

4. 源码编译

git clone https://github.com/derailed/popeye.git
cd popeye
make build              # 或 go run main.go
sudo mv ./bin/popeye /usr/local/bin/

若需定制,也可在 go.mod 中添加 replace 语句后编译。

5. 容器化运行

docker run --rm \
  -v ~/.kube/config:/root/.kube/config \
  derailed/popeye:vX.Y.Z

适合 GitOps 流水线或 Kubernetes CronJob 场景。


基础使用

查看版本与环境

popeye version

输出版本号、Go 版本、日志目录、配置路径等。

扫描集群

  • 默认扫描(当前上下文 & 命名空间)

    popeye
    
  • 扫描所有命名空间

    popeye -A
    
  • 指定命名空间

    popeye -n kube-system
    
  • 按资源类型

    popeye -s pod,svc,ingress
    
  • 指定上下文

    popeye --context production-cluster
    
  • 输出 JSON / HTML 报表

    popeye --out json  # 终端打印 JSON
    POPEYE_REPORT_DIR=./reports popeye --save --out html --output-file report.html
    
  • 输出指标到 push-gateway

     popeye --push-gtwy-url http://172.30.80.207:9091
    

日志与调试

  • 调试级别日志

    popeye -v4 --logs /tmp/popeye.log
    
  • 查看命令行帮助

    popeye help
    

集成与自动化

1. Kubernetes CronJob(持续审计)

apiVersion: batch/v1
kind: CronJob
metadata:
  name: popeye
  namespace: popeye
spec:
  schedule: "0 * * * *"      # 每小时执行
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: popeye-sa
          restartPolicy: Never
          containers:
            - name: popeye
              image: derailed/popeye:vX.Y.Z
              args:
                - "-o"             
                - "yaml"          
                - "--force-exit-zero"
              volumeMounts:
                - name: config
                  mountPath: /root/.kube
          volumes:
            - name: config
              secret:
                secretName: kubeconfig-secret

Tip--force-exit-zero 可避免因发现问题而导致 CronJob 标记为失败。


结语

借助 Popeye,您的 Kubernetes 集群将实现全天候资源健康巡检安全审计自动化,帮助团队更高效、更稳健地运行生产系统。若需更深入的 Linter 代码说明或贡献指南,请前往 GitHub 仓库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

启明真纳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值