Prerequisites

OpenCost 依赖于 Prometheus

1
2
helm install my-prometheus --repo https://prometheus-community.github.io/helm-charts prometheus \  
  --namespace prometheus --create-namespace \  --set pushgateway.enabled=false \  --set alertmanager.enabled=false \  -f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/prometheus/extraScrapeConfigs.yaml

部署

https://github.com/opencost/opencost-helm-chart

本质上就是一个后端应用和前端 UI 界面,以 Deployment 的形式部署

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Create a deployment for a single cost model pod  
#  
# See environment variables if you would like to add a Prometheus for  
# cost model to read from for full functionality.  
apiVersion: apps/v1  
kind: Deployment  
metadata:  
  name: {{ .Values.opencost.fullname }}  
  namespace: {{ .Values.opencost.namespace.name }}  
  labels:  
    app: opencost  
spec:  
  replicas: 1  
  selector:  
    matchLabels:  
      app: opencost  
  strategy:  
    rollingUpdate:  
      maxSurge: 1  
      maxUnavailable: 1  
    type: RollingUpdate  
  template:  
    metadata:  
      labels:  
        app: opencost  
    spec:  
      serviceAccountName: opencost  
      tolerations:  
        {{- toYaml .Values.opencost.tolerations | nindent 8 }}  
      containers:  
        - image: "{{ .Values.opencost.exporter.image.repository }}:{{ .Values.opencost.exporter.image.tag }}"  
          name: {{ .Values.opencost.exporter.name }}  
          resources:  
            {{- toYaml .Values.opencost.exporter.resources | nindent 12 }}  
          env:  
            - name: PROMETHEUS_SERVER_ENDPOINT  
              value: "http://{{ .Values.opencost.prometheus.serviceName }}.{{ .Values.opencost.prometheus.namespaceName }}.svc" # The endpoint should have the form http://<service-name>.<namespace-name>.svc  
            - name: CLOUD_PROVIDER_API_KEY  
              value: {{ .Values.opencost.exporter.cloudProviderApiKey | quote }}  
            - name: CLUSTER_ID  
              value: {{ .Values.opencost.exporter.defaultClusterId | quote }}  
          imagePullPolicy: Always  
        {{- if .Values.opencost.ui.enabled }}  
        - image: "{{ .Values.opencost.ui.image.repository }}:{{ .Values.opencost.ui.image.tag }}"  
          name: opencost-ui  
          resources:  
            {{- toYaml .Values.opencost.ui.resources | nindent 12 }}  
          imagePullPolicy: Always  
        {{- end -}}

后端 Docker Image: https://github.com/opencost/opencost/blob/develop/Dockerfile 前端 Docker Image: https://github.com/opencost/opencost/blob/develop/ui/Dockerfile

KubeCost 部署

KubeCost 的 helm chart 则要复杂的多,并且很多都是闭源的

https://github.com/kubecost/cost-analyzer-helm-chart