侧边栏壁纸
博主头像
背锅小王子博主等级

我从事运维工作有十年之久,主要从事云原生相关的工作,对k8s、devops、servicemesh、可观察性等较为熟悉!

  • 累计撰写 59 篇文章
  • 累计创建 64 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

OpenCost—你最喜欢的 Kubernetes 开源成本监控工具

背锅小王子
2023-03-22 / 0 评论 / 0 点赞 / 399 阅读 / 411 字
温馨提示:
本文最后更新于 2023-03-22,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

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
图片

0

评论区