Răsfoiți Sursa

update links and install instructions

jesse goodier 3 ani în urmă
părinte
comite
a7934ff6b0

+ 1 - 67
PROMETHEUS.md

@@ -1,67 +1 @@
-Kubecost allows you to export pricing data to Prometheus and then write custom queries for cost insights. Below are instructions for accomplishing this and a set of example queries to get you started.
-
-## Configuration
-
-After deploying the Kubecost model (see [README](README.md) for more info on installation), configure Prometheus to scrape the `/metrics` endpoint exposed by Kubecost. Below is a sample scrape config:
-
-```
-- job_name: kubecost
-  honor_labels: true
-  scrape_interval: 1m
-  scrape_timeout: 10s
-  metrics_path: /metrics
-  scheme: http
-  static_configs:
-  - targets:
-    - < address of cost-model service> # example: <service-name>.<namespace>:<port>
-``` 
-
-## Example queries
-
-Below are a set of sample queries that can be run after Prometheus begins ingesting Kubecost data:
-
-__Monthly cost of top 5 containers__
-
-```
-topk( 5, 
-  container_memory_allocation_bytes* on(instance) group_left() node_ram_hourly_cost  / 1024 / 1024 / 1024 * 730
-  + 
-  container_cpu_allocation * on(instance) group_left() node_cpu_hourly_cost * 730
-)
-```
-
-__Hourly memory cost for the *default* namespace__
-
-```
-sum(
-  avg(container_memory_allocation_bytes{namespace="default"}) by (instance) / 1024 / 1024 / 1024
-  * 
-  on(instance) group_left() avg(node_ram_hourly_cost) by (instance)
-)
-```
-
-__Monthly cost of currently provisioned nodes__
-
-```
-sum(node_total_hourly_cost) * 730
-```
-
-
-## Available Metrics
-
-**Note:** metrics today have both *instance* and *node* labels. The *instance* label will be deprecated in a future version.
-
-| Metric       | Description                                                                                            |
-| ------------ | ------------------------------------------------------------------------------------------------------ |
-| node_cpu_hourly_cost | Hourly cost per vCPU on this node  |
-| node_gpu_hourly_cost | Hourly cost per GPU on this node  |
-| node_ram_hourly_cost   | Hourly cost per Gb of memory on this node                       |
-| node_total_hourly_cost   | Total node cost per hour                       |
-| kubecost_load_balancer_cost   | Hourly cost of a load balancer                 |
-| kubecost_cluster_management_cost | Hourly management fee per cluster                 |
-| pv_hourly_cost   | Hourly cost per GP on a persistent volume                 |
-| node_gpu_count | Number of GPUs available on node |
-| container_cpu_allocation   | Average number of CPUs requested/used over last 1m                      |
-| container_gpu_allocation   | Average number of GPUs requested over last 1m                      |
-| container_memory_allocation_bytes   | Average bytes of RAM requested/used over last 1m                 |
-| pod_pvc_allocation   | Bytes provisioned for a PVC attached to a pod                      |
+<https://www.opencost.io/docs/>

+ 4 - 4
README.md

@@ -27,10 +27,10 @@ Visit the full documentation for [recommended install options](https://www.openc
 
 
 ## Usage
 ## Usage
 
 
-- User interface
-- [Cost APIs](https://github.com/kubecost/docs/blob/master/apis.md)
-- [CLI / kubectl cost](https://github.com/kubecost/kubectl-cost)
-- [Prometheus metric exporter](kubecost-exporter.md)
+- [Cost APIs](https://www.opencost.io/docs/api)
+- [CLI / kubectl cost](https://www.opencost.io/docs/kubectl-cost)
+- [Prometheus Metrics](https://www.opencost.io/docs/prometheus)
+- Reference [User Interface](https://github.com/opencost/opencost/tree/develop/ui)
 
 
 ## Contributing
 ## Contributing
 
 

+ 0 - 134
kubecost-exporter.md

@@ -1,134 +0,0 @@
-# Running Kubecost as a Prometheus metric exporter
-
-Running Kubecost as a Prometheus metric exporter allows you to export various cost metrics to Prometheus without setting up any other Kubecost dependencies. Doing so lets you write PromQL queries to calculate the cost and efficiency of any Kubernetes concept, e.g. namespace, service, label, deployment, etc. You can also calculate the cost of different Kubernetes resources, e.g. nodes, PVs, LoadBalancers, and more. Finally, you can do other interesting things like create custom alerts via AlertManager and custom dashboards via Grafana.
-
-## Installing
-
-> Note: all deployments of Kubecost function as a Prometheus metric exporter. We strongly recommend helm as an install path to take advantage of Kubecost’s full potential. [View recommended install](http://docs.kubecost.com/install).
-
-If you would prefer to not use the recommended install option and just deploy the Kubecost open source cost model as a metric exporter, you can follow these steps:
-
-
-1. Apply the combined YAML:
-
-    1.a.
-
-      ```
-      wget https://raw.githubusercontent.com/kubecost/cost-model/develop/kubernetes/exporter/exporter.yaml
-      ```
-
-    1.b.
-      On the line
-
-      ```
-      value: "{{prometheusEndpoint}}" # The endpoint should have the form http://<service-name>.<namespace-name>.svc
-      ```
-
-      of `exporter.yaml`, substitute your own Prometheus URI for `{{prometheusEndpoint}}`
-
-    1.c.
-
-      ```
-      kubectl apply -f exporter.yaml --namespace cost-model
-      ```
-
-    > If you want to use a namespace other than `cost-model`, you will have to edit the `ClusterRoleBinding` after applying the YAML to change `subjects[0].namespace`. You can do this with `kubectl edit clusterrolebinding cost-model`.
-
-2. To verify that metrics are available:
-
-    ```
-    kubectl port-forward --namespace cost-model service/cost-model 9003
-    ```
-
-    Visit [http://localhost:9003/metrics](http://localhost:9003/metrics) to see exported metrics
-
-Add Kubecost scrape config to Prom ([more info](https://prometheus.io/docs/introduction/first_steps/#configuring-prometheus))
-```
-- job_name: cost-model
-  scrape_interval: 1m
-  scrape_timeout: 10s
-  metrics_path: /metrics
-  scheme: http
-  static_configs:
-    - targets: ['cost-model.cost-model.:9003']
-```
-
-Done! Kubecost is now exporting cost metrics. See the following sections for different metrics available and query examples.
-
-## Available Prometheus Metrics
-
-| Metric       | Description                                                                                            |
-| ------------ | ------------------------------------------------------------------------------------------------------ |
-| node_cpu_hourly_cost | Hourly cost per vCPU on this node  |
-| node_gpu_hourly_cost | Hourly cost per GPU on this node  |
-| node_ram_hourly_cost   | Hourly cost per Gb of memory on this node                       |
-| node_total_hourly_cost   | Total node cost per hour                       |
-| kubecost_load_balancer_cost   | Hourly cost of a load balancer                 |
-| kubecost_cluster_management_cost | Hourly management fee per cluster                 |
-| container_cpu_allocation   | Average number of CPUs requested over last 1m                      |
-| container_memory_allocation_bytes   | Average bytes of RAM requested over last 1m                 |
-
-By default, all cost metrics are based on public billing APIs. See the Limitations section below about reflecting your precise billing information. Supported platforms are AWS, Azure, and GCP. For on-prem clusters, prices are based on configurable defaults.
-
-More metrics are available in the recommended install path and are described in [PROMETHEUS.md](PROMETHEUS.md).
-
-## Dashboard examples
-
-Here’s an example dashboard using Kubecost Prometheus metrics:
-
-![sample dashboard](https://grafana.com/api/dashboards/8670/images/5480/image)
-
-You can find other example dashboards at https://grafana.com/orgs/kubecost
-
-## Example Queries
-
-Once Kubecost’s cost model is running in your cluster and you have added it in your Prometheus scrape configuration, you can hit Prometheus with useful queries like these:
-
-#### Monthly cost of all nodes
-
-```
-sum(node_total_hourly_cost) * 730
-```
-
-#### Hourly cost of all load balancers broken down by namespace
-
-```
-sum(kubecost_load_balancer_cost) by (namespace)
-```
-
-#### Monthly rate of each namespace’s CPU request
-
-```
-sum(container_cpu_allocation * on (node) group_left node_cpu_hourly_cost) by (namespace) * 730
-```
-
-#### Historical memory request spend for all `fluentd` pods in the `kube-system` namespace
-
-```
-avg_over_time(container_memory_allocation_bytes{namespace="kube-system",pod=~"fluentd.*"}[1d])
-  * on (pod,node) group_left
-avg(count_over_time(container_memory_allocation_bytes{namespace="kube-system"}[1d:1m])/60) by (pod,node)
-  * on (node) group_left
-avg(avg_over_time(node_ram_hourly_cost[1d] )) by (node)
-```
-
-
-## Setting Cost Alerts
-
-Custom cost alerts can be implemented with a set of Prometheus queries and can be used for alerting with AlertManager or Grafana alerts. Below are example alerting rules.
-
-#### Determine in real-time if the monthly cost of all nodes is > $1000
-
-```
-sum(node_total_hourly_cost) * 730 > 1000
-```
-
-## Limitations
-
-Running Kubecost in exporter-only mode by definition limits functionality. The following limitations of this install method are addressed by the [recommended install path](http://docs.kubecost.com/install).
-
-- Persistent volume metrics not available (coming soon!)
-- For large clusters, these Prometheus queries might not scale well over large time windows. We recommend using [Kubecost APIs](https://github.com/kubecost/docs/blob/master/apis.md) for these scenarios.
-- Allocation metrics, like `container_cpu_allocation` only contain _requests_ and do not take usage into account.
-- Related to the previous point, efficiency metrics are not available.
-- Public billing costs on default. The standard Kubecost install and a cloud integration gives you accurate pricing based on your bill.

+ 1 - 0
kubernetes/README.md

@@ -0,0 +1 @@
+<https://www.opencost.io/docs/>

+ 0 - 12
kubernetes/cluster-role-binding.yaml

@@ -1,12 +0,0 @@
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
-metadata:
-  name: cost-model
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: cost-model
-subjects:
-  - kind: ServiceAccount
-    name: cost-model
-    namespace: cost-model

+ 0 - 77
kubernetes/cluster-role.yaml

@@ -1,77 +0,0 @@
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRole
-metadata:
-  name: cost-model 
-rules:
-  - apiGroups:
-      - ''
-    resources:
-      - configmaps
-      - deployments
-      - nodes
-      - pods
-      - services
-      - resourcequotas
-      - replicationcontrollers
-      - limitranges
-      - persistentvolumeclaims
-      - persistentvolumes
-      - namespaces
-      - endpoints
-    verbs:
-      - get
-      - list
-      - watch
-  - apiGroups:
-      - extensions
-    resources:
-      - daemonsets
-      - deployments
-      - replicasets
-    verbs:
-      - get
-      - list
-      - watch
-  - apiGroups:
-      - apps
-    resources:
-      - statefulsets
-      - deployments
-      - daemonsets
-      - replicasets
-    verbs:
-      - list
-      - watch
-  - apiGroups:
-      - batch
-    resources:
-      - cronjobs
-      - jobs
-    verbs:
-      - get
-      - list
-      - watch
-  - apiGroups:
-      - autoscaling
-    resources:
-      - horizontalpodautoscalers
-    verbs:
-      - get
-      - list
-      - watch
-  - apiGroups:
-      - policy
-    resources:
-      - poddisruptionbudgets
-    verbs:
-      - get
-      - list
-      - watch
-  - apiGroups: 
-      - storage.k8s.io
-    resources: 
-      - storageclasses
-    verbs:
-      - get
-      - list
-      - watch

+ 0 - 36
kubernetes/deployment.yaml

@@ -1,36 +0,0 @@
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: cost-model
-  labels:
-    app: cost-model
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      app: cost-model
-  strategy:
-    rollingUpdate:
-      maxSurge: 1
-      maxUnavailable: 1
-    type: RollingUpdate
-  template:
-    metadata:
-      labels:
-        app: cost-model
-    spec:
-      restartPolicy: Always
-      serviceAccountName: cost-model
-      containers:
-        - image: quay.io/kubecost1/kubecost-cost-model:latest
-          name: cost-model
-          resources:
-            requests:
-              cpu: "10m"
-              memory: "55M"
-          env:
-            - name: PROMETHEUS_SERVER_ENDPOINT
-              value: "{{prometheusEndpoint}}"  #The endpoint should have the form http://<service-name>.<namespace-name>.svc
-            - name: CLOUD_PROVIDER_API_KEY
-              value: "AIzaSyD29bGxmHAVEOBYtgd8sYM2gM2ekfxQX4U" # The GCP Pricing API requires a key. This is supplied just for evaluation.
-          imagePullPolicy: Always

+ 1 - 11
kubernetes/exporter/README.md

@@ -1,11 +1 @@
-# Exporter Deployment
-
-This is the one YAML file that is the aggregation of the regular deployment files. This is done for easy distribution, allowing users to `kubectl apply` an exporter-only deployment without cloning the whole repository. Apply on the parent directory won't apply anything in this directory unless `kubectl apply --recursive=True` is used.
-
-## Usage
-
-Please be aware, you will have to change both the `Namespace` and `ClusterRoleBinding` resource if you want to deploy to a namespace other than `cost-model`.
-
-``` sh
-kubectl apply -f exporter.yaml --namespace cost-model
-```
+<https://www.opencost.io/docs/>

+ 30 - 33
kubernetes/exporter/exporter.yaml → kubernetes/opencost.yaml

@@ -1,29 +1,26 @@
-# Based on the split YAML files, this is aggregated for convenience of deployment.
-
+# <https://www.opencost.io/docs/>
 ---
 ---
 
 
-# The namespace cost-model will run in
+# The namespace opencost will run in
 apiVersion: v1
 apiVersion: v1
 kind: Namespace
 kind: Namespace
 metadata:
 metadata:
-    name: cost-model
-
+    name: opencost
 ---
 ---
 
 
 # Service account for permissions
 # Service account for permissions
 apiVersion: v1
 apiVersion: v1
 kind: ServiceAccount
 kind: ServiceAccount
 metadata:
 metadata:
-  name: cost-model
-
+  name: opencost
 ---
 ---
 
 
-# Cluster role so cost model can gather data about the cluster
-# No write permissions are allowed
+# Cluster role giving opencost to get, list, watch required recources
+# No write permissions are required
 apiVersion: rbac.authorization.k8s.io/v1
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRole
 kind: ClusterRole
 metadata:
 metadata:
-  name: cost-model 
+  name: opencost
 rules:
 rules:
   - apiGroups:
   - apiGroups:
       - ''
       - ''
@@ -89,9 +86,9 @@ rules:
       - get
       - get
       - list
       - list
       - watch
       - watch
-  - apiGroups: 
+  - apiGroups:
       - storage.k8s.io
       - storage.k8s.io
-    resources: 
+    resources:
       - storageclasses
       - storageclasses
     verbs:
     verbs:
       - get
       - get
@@ -104,33 +101,32 @@ rules:
 apiVersion: rbac.authorization.k8s.io/v1
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
 kind: ClusterRoleBinding
 metadata:
 metadata:
-  name: cost-model
+  name: opencost
 roleRef:
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
   kind: ClusterRole
-  name: cost-model
+  name: opencost
 subjects:
 subjects:
   - kind: ServiceAccount
   - kind: ServiceAccount
-    name: cost-model
-    namespace: cost-model
-
+    name: opencost
+    namespace: opencost
 ---
 ---
 
 
 # Create a deployment for a single cost model pod
 # Create a deployment for a single cost model pod
-# 
+#
 # See environment variables if you would like to add a Prometheus for
 # See environment variables if you would like to add a Prometheus for
 # cost model to read from for full functionality.
 # cost model to read from for full functionality.
 apiVersion: apps/v1
 apiVersion: apps/v1
 kind: Deployment
 kind: Deployment
 metadata:
 metadata:
-  name: cost-model
+  name: opencost
   labels:
   labels:
-    app: cost-model
+    app: opencost
 spec:
 spec:
   replicas: 1
   replicas: 1
   selector:
   selector:
     matchLabels:
     matchLabels:
-      app: cost-model
+      app: opencost
   strategy:
   strategy:
     rollingUpdate:
     rollingUpdate:
       maxSurge: 1
       maxSurge: 1
@@ -139,44 +135,45 @@ spec:
   template:
   template:
     metadata:
     metadata:
       labels:
       labels:
-        app: cost-model
+        app: opencost
     spec:
     spec:
       restartPolicy: Always
       restartPolicy: Always
-      serviceAccountName: cost-model
+      serviceAccountName: opencost
       containers:
       containers:
         - image: quay.io/kubecost1/kubecost-cost-model:latest
         - image: quay.io/kubecost1/kubecost-cost-model:latest
-          name: cost-model
+          name: opencost
           resources:
           resources:
             requests:
             requests:
               cpu: "10m"
               cpu: "10m"
               memory: "55M"
               memory: "55M"
+            limits:
+              cpu: "999m"
+              memory: "1G"
           env:
           env:
             - name: PROMETHEUS_SERVER_ENDPOINT
             - name: PROMETHEUS_SERVER_ENDPOINT
-              value: "{{prometheusEndpoint}}" # The endpoint should have the form http://<service-name>.<namespace-name>.svc
+              value: "http://my-prometheus-server.prom.svc" # The endpoint should have the form http://<service-name>.<namespace-name>.svc
             - name: CLOUD_PROVIDER_API_KEY
             - name: CLOUD_PROVIDER_API_KEY
               value: "AIzaSyD29bGxmHAVEOBYtgd8sYM2gM2ekfxQX4U" # The GCP Pricing API requires a key. This is supplied just for evaluation.
               value: "AIzaSyD29bGxmHAVEOBYtgd8sYM2gM2ekfxQX4U" # The GCP Pricing API requires a key. This is supplied just for evaluation.
             - name: CLUSTER_ID
             - name: CLUSTER_ID
               value: "cluster-one" # Default cluster ID to use if cluster_id is not set in Prometheus metrics.
               value: "cluster-one" # Default cluster ID to use if cluster_id is not set in Prometheus metrics.
           imagePullPolicy: Always
           imagePullPolicy: Always
-
 ---
 ---
 
 
 # Expose the cost model with a service
 # Expose the cost model with a service
-# 
+#
 # Without a Prometheus endpoint configured in the deployment,
 # Without a Prometheus endpoint configured in the deployment,
-# only cost-model/metrics will have useful data as it is intended
+# only opencost/metrics will have useful data as it is intended
 # to be used as just an exporter.
 # to be used as just an exporter.
 kind: Service
 kind: Service
 apiVersion: v1
 apiVersion: v1
 metadata:
 metadata:
-  name: cost-model
+  name: opencost
 spec:
 spec:
   selector:
   selector:
-    app: cost-model
+    app: opencost
   type: ClusterIP
   type: ClusterIP
   ports:
   ports:
-    - name: cost-model
+    - name: opencost
       port: 9003
       port: 9003
       targetPort: 9003
       targetPort: 9003
-
----
+---

+ 12 - 0
kubernetes/prometheus/extraScrapeConfigs.yaml

@@ -0,0 +1,12 @@
+extraScrapeConfigs: |
+  - job_name: opencost
+    honor_labels: true
+    scrape_interval: 1m
+    scrape_timeout: 10s
+    metrics_path: /metrics
+    scheme: http
+    dns_sd_configs:
+    - names:
+      - opencost.opencost
+      type: 'A'
+      port: 9003

+ 0 - 4
kubernetes/service-account.yaml

@@ -1,4 +0,0 @@
-apiVersion: v1
-kind: ServiceAccount
-metadata:
-  name: cost-model

+ 0 - 12
kubernetes/service.yaml

@@ -1,12 +0,0 @@
-kind: Service
-apiVersion: v1
-metadata:
-  name: cost-model
-spec:
-  selector:
-    app: cost-model
-  type: ClusterIP
-  ports:
-    - name: cost-model
-      port: 9003
-      targetPort: 9003