1、概述
OpenCost 是一个供应商中立的开源项目,用于衡量和分配基础设施和容器成本。它是为 Kubernetes 成本监控而构建的,以支持实时成本监控。
2、功能介绍
- 按 Kubernetes 集群、节点、命名空间、控制器种类、控制器、服务或 Pod 进行实时成本分配
- 通过与 AWS、Azure 和 GCP 计费 API 的集成实现动态按需资产定价
- 支持具有自定义 CSV 定价的本地 k8s 集群
- 分配集群内资源,如 CPU、GPU、内存和持久卷。
- 使用 /metrics 端点轻松将定价数据导出到 Prometheus
- 免费和开源
3、安装部署
因为OpenCost 需要 Prometheus 来抓取指标和数据存储。具体按照以下步骤安装 OpenCost。
如果k8s集群中没有Prometheus,需要安装,具体如下:
helm install my-prometheus --repo https://prometheus-community.github.io/helm-charts prometheus \
--namespace monitoring --create-namespace \
--set pushgateway.enabled=false \
--set alertmanager.enabled=false \
-f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/prometheus/extraScrapeConfigs.yaml
通过kustomization来部署OpenCost
namespace: monitoring
helmCharts:
- name: opencost
version: 1.7.0
repo: https://opencost.github.io/opencost-helm-chart
valuesInline:
opencost:
exporter:
defaultClusterId: test-k8s # 自定义clusterID
prometheus:
external:
enabled: true # 开启外部Prometheus
url: 'http://prometheus-k8s:9090'
internal:
enabled: false # 关闭内部Prometheus
resources:
- ingress.yaml
创建ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: opencost
namespace: monitoring
spec:
rules:
- host: opencost.bgxwz.com
http:
paths:
- backend:
service:
name: opencost
port:
number: 9090
path: /
pathType: Prefix
部署opencost
kubectl apply -k opencost
查看Pod
kubectl get pod -n monitoring | grep opencost
opencost-5454d579fd-xvp67 2/2 Running 0 4m
查看UI,使用上面创建的ingress域名:https://opencost.bgxwz.com
评论区