cognis-digital/k8scost

GitHub: cognis-digital/k8scost

无需 Prometheus 依赖的 Kubernetes 成本分析与资源规格优化工具,支持 CI 集成和 AI 代理驱动。

Stars: 0 | Forks: 0

K8SCOST # K8SCOST ### 无需 Prometheus 依赖的 Kubernetes 成本与资源规格优化顾问 [![PyPI](https://img.shields.io/pypi/v/cognis-k8scost.svg?color=6b46c1)](https://pypi.org/project/cognis-k8scost/) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/ad5386c2ea060905.svg)](https://github.com/cognis-digital/k8scost/actions) [![License: COCL 1.0](https://img.shields.io/badge/License-COCL%201.0-2b6cb0.svg)](LICENSE) [![Suite](https://img.shields.io/badge/Cognis-Neural%20Suite-6b46c1.svg)](https://github.com/cognis-digital) *DevOps 与可观测性 — 状态、可用性合成检查、告警与云成本。*
``` pip install cognis-k8scost k8scost scan . # → prioritized findings in seconds ``` ## 使用说明 — 分步指南 1. **安装** (Python 3.8+,仅使用标准库): pip install k8scost 输入为一个 workload JSON 文件(无需 Prometheus 或集群访问权限)。 2. **分析 workloads** 以获取成本和资源规格优化建议: k8scost analyze workloads.json 3. **覆盖默认定价并获取详细的容器级建议**: k8scost --cpu-price 0.031 --mem-price 0.004 analyze workloads.json --advise 4. **以 JSON 格式读取输出**(或通过 `-` 利用 stdin 流式传输 workloads): kubectl get deploy -A -o json | k8scost --format json analyze - | jq '.summary' JSON 包含一个 `summary`(总成本/建议成本、潜在节省金额、节省百分比 savings_pct)以及各个 workload 的 `workloads[]`。 5. **在 CI 中使用** — 在每次基础设施变更时展示每月可节省的成本: k8scost --format json analyze workloads.json | jq '.summary.potential_monthly_savings' ## 目录 - [为什么选择 k8scost?](#why) · [功能](#features) · [快速开始](#quick-start) · [示例](#example) · [架构](#architecture) · [AI 技术栈](#ai-stack) · [功能对比](#how-it-compares) · [集成](#integrations) · [随处安装](#install-anywhere) · [相关项目](#related) · [参与贡献](#contributing) ## 为什么选择 k8scost? k8s FinOps `k8scost` 具有单一用途、可脚本化且支持自托管:将其指向目标,以您的工作流已有的格式(表格 · JSON · SARIF)获取优先级排序后的结果,将其作为 CI 的门禁,并让 AI 代理通过 MCP 进行驱动。
↑ 回到顶部
## 功能 - ✅ 解析 Cpu - ✅ 解析 Mem - ✅ 解析 Workloads - ✅ 分析 - ✅ 汇总 - ✅ 支持 Linux/macOS/Windows · Docker · devcontainer 运行 - ✅ 提供 Python、JavaScript、Go 和 Rust 版本移植 (`ports/`)
↑ 回到顶部
## 快速开始 ``` pip install cognis-k8scost k8scost --version k8scost scan . # scan current project k8scost scan . --format json # machine-readable k8scost scan . --fail-on high # CI gate (non-zero exit) ```
↑ 回到顶部
## 示例 ``` $ k8scost scan . [HIGH ] K8S-001 example finding (./src/app.py) [MEDIUM ] K8S-002 another signal (./config.yaml) 2 findings · risk score 5 · 38ms ```
↑ 回到顶部
## 架构 ``` flowchart LR IN[addresses + transactions] --> P[k8scost
cluster + trace] P --> OUT[sanctions xref / report] ```
↑ 回到顶部
## 从任何 AI 技术栈中使用 `k8scost` 可与当前所有主流的 AI 使用方式互操作: - **MCP server** — `k8scost mcp` (Claude Desktop, Cursor, Cognis.Studio, [uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet)) - **兼容 OpenAI / JSON** — 通过管道将 `k8scost scan . --format json` 传输给任何代理或 LLM - **LangChain · CrewAI · AutoGen · LlamaIndex** — 一行代码即可将 CLI/JSON 封装为工具 - **CI / 脚本** — 为非 AI 流水线提供退出码 + SARIF 支持
↑ 回到顶部
## 功能对比 | | **Cognis k8scost** | Kubecost 3.0 | |---|:---:|:---:| | 支持自托管,无需账号 | ✅ | 视情况而定 | | 单一命令,零配置 | ✅ | ⚠️ | | 针对_CI_提供 JSON + SARIF | ✅ | 视情况而定 | | MCP 原生支持 (AI 代理) | ✅ | ❌ | | 多语言移植 (JS/Go/Rust) | ✅ | ❌ | | 开源许可 | ✅ COCL | 视情况而定 | *秉承 **Kubecost 3.0** 的精神构建,并以 Cognis 的方式重新塑造。遗漏了致谢?欢迎提交 PR。*
↑ 回到顶部
## 集成 可无缝接入您的技术栈:用于代码扫描的 **SARIF**,用于任何场景的 **JSON**,用于 AI 代理的 **MCP server** (`k8scost mcp`),以及用于 SIEM/Slack/Jira 的 webhook 转发器。详见 [`docs/INTEGRATIONS.md`](docs/INTEGRATIONS.md)。
↑ 回到顶部
## 安装 — 全平台、全方式指南 ``` pip install "git+https://github.com/cognis-digital/k8scost.git" # pip (works today) pipx install "git+https://github.com/cognis-digital/k8scost.git" # isolated CLI uv tool install "git+https://github.com/cognis-digital/k8scost.git" # uv pip install cognis-k8scost # PyPI (when published) docker run --rm ghcr.io/cognis-digital/k8scost:latest --help # Docker brew install cognis-digital/tap/k8scost # Homebrew tap curl -fsSL https://raw.githubusercontent.com/cognis-digital/k8scost/main/install.sh | sh ``` | Linux | macOS | Windows | Docker | 云平台 | |---|---|---|---|---| | `scripts/setup-linux.sh` | `scripts/setup-macos.sh` | `scripts/setup-windows.ps1` | `docker run ghcr.io/cognis-digital/k8scost` | [DEPLOY.md](docs/DEPLOY.md) (AWS/Azure/GCP/k8s) |
↑ 回到顶部
## 相关 Cognis 工具 - [`statuskit`](https://github.com/cognis-digital/statuskit) — 自托管的状态页面,包含故障时间线和订阅者功能 - [`probesite`](https://github.com/cognis-digital/probesite) — 合成的可用性监控与 Playwright 检查,并导出至 Prometheus - [`alertmux`](https://github.com/cognis-digital/alertmux) — 位于 Grafana / PagerDuty 前端的告警去重、关联与路由工具 - [`cloudbill`](https://github.com/cognis-digital/cloudbill) — 多云成本报告、异常检测与 FOCUS 导出 - [`otelbox`](https://github.com/cognis-digital/otelbox) — 一键式的 OpenTelemetry collector + dashboards 套件 **探索全套工具 →** [🗂️ 全部 170+ 工具](https://github.com/cognis-digital/cognis-neural-suite) · [⭐ awesome-cognis](https://github.com/cognis-digital/awesome-cognis) · [🔗 cognis-sources](https://github.com/cognis-digital/cognis-sources) · [🤖 uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet) · [🧠 engram](https://github.com/cognis-digital/engram)
↑ 回到顶部
## 互操作性 `{}` 与包含 300+ 工具的 Cognis 套件完美融合 — 统一的 JSON 输入/输出以及共享的 兼容 OpenAI 的 `/v1` 骨干网络。请参阅 **[INTEROP.md](INTEROP.md)** 获取 完整的套件图谱、组合模式和参考技术栈。 ## 许可证 源码可见,基于 **Cognis Open Collaboration License (COCL) v1.0** — 个人使用、内部评估、研究和教育用途免费;**商业 / 生产环境使用需要获得许可** (licensing@cognis.digital)。详见 [LICENSE](LICENSE)。
Cognis Digital · Cognis Neural Suite 中 170+ 工具之一 · 让明天更美好
标签:FinOps, 可视化界面, 成本优化, 数据可视化, 日志审计, 请求拦截, 资源建议, 逆向工具