forked from opencost/opencost-helm-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial import of the WIP from prometheus-community/helm-charts#3872
Signed-off-by: Matt Ray <[email protected]>
- Loading branch information
Showing
23 changed files
with
1,284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
appVersion: 1.106.3 | ||
version: 0.1.0 | ||
description: Prometheus OpenCost Exporter | ||
home: https://github.com/opencost/opencost-helm-chart | ||
name: prometheus-opencost-exporter | ||
sources: | ||
- https://github.com/prometheus-community/opencost_exporter | ||
apiVersion: v2 | ||
type: application | ||
keywords: | ||
- opencost | ||
- prometheus | ||
- exporter | ||
maintainers: | ||
- email: [email protected] | ||
name: mattray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Prometheus Opencost Exporter | ||
|
||
Prometheus exporter for [OpenCost](https://www.opencost.io) Kubernetes cost monitoring data. | ||
|
||
This chart bootstraps a Prometheus [OpenCost exporter](https://github.com/prometheus-community/opencost_exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. | ||
|
||
## Prerequisites | ||
|
||
- Kubernetes 1.23+ | ||
- Helm 3+ | ||
|
||
## Add Helm Chart Repository | ||
|
||
```console | ||
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts | ||
helm repo update | ||
``` | ||
|
||
_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._ | ||
|
||
## Install Chart | ||
|
||
```console | ||
helm install [RELEASE_NAME] prometheus-community/prometheus-opencost-exporter | ||
``` | ||
|
||
_See [configuration](#configuring) below._ | ||
|
||
_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ | ||
|
||
## Uninstall Chart | ||
|
||
```console | ||
helm uninstall [RELEASE_NAME] | ||
``` | ||
|
||
This removes all the Kubernetes components associated with the chart and deletes the release. | ||
|
||
_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ | ||
|
||
### Other minor version upgrade | ||
|
||
```console | ||
helm upgrade [RELEASE_NAME] [CHART] --install | ||
``` | ||
|
||
_See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._ | ||
|
||
## Configuring | ||
|
||
See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments, visit the chart's [values.yaml](./values.yaml), or run these configuration commands: | ||
|
||
```console | ||
helm show values prometheus-community/prometheus-opencost-exporter | ||
``` |
178 changes: 178 additions & 0 deletions
178
charts/prometheus-opencost-exporter/opencost-exporter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
--- | ||
|
||
# The namespace opencost will run in | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: opencost-exporter | ||
--- | ||
|
||
# Service account for permissions | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: opencost | ||
--- | ||
|
||
# Cluster role giving opencost to get, list, watch required resources | ||
# No write permissions are required | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: opencost | ||
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 | ||
|
||
--- | ||
|
||
# Bind the role to the service account | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: opencost | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: opencost | ||
subjects: | ||
- kind: ServiceAccount | ||
name: opencost | ||
namespace: opencost-exporter | ||
--- | ||
|
||
# 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: opencost | ||
labels: | ||
app: opencost | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: opencost | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 1 | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
labels: | ||
app: opencost | ||
spec: | ||
restartPolicy: Always | ||
serviceAccountName: opencost | ||
containers: | ||
- image: quay.io/kubecost1/kubecost-cost-model:latest | ||
name: opencost | ||
resources: | ||
requests: | ||
cpu: "10m" | ||
memory: "55M" | ||
limits: | ||
cpu: "999m" | ||
memory: "1G" | ||
env: | ||
- name: PROMETHEUS_SERVER_ENDPOINT | ||
value: "http://my-prometheus-server.prometheus.svc" # 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. | ||
- name: CLUSTER_ID | ||
value: "cluster-one" # Default cluster ID to use if cluster_id is not set in Prometheus metrics. | ||
imagePullPolicy: Always | ||
--- | ||
|
||
# Expose the cost model with a service | ||
# | ||
# Without a Prometheus endpoint configured in the deployment, | ||
# only opencost/metrics will have useful data as it is intended | ||
# to be used as just an exporter. | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: opencost | ||
spec: | ||
selector: | ||
app: opencost | ||
type: ClusterIP | ||
ports: | ||
- name: opencost | ||
port: 9003 | ||
targetPort: 9003 | ||
--- |
99 changes: 99 additions & 0 deletions
99
charts/prometheus-opencost-exporter/templates/_helpers.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{{/* vim: set filetype=mustache: */}} | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.fullname" -}} | ||
{{- if .Values.fullnameOverride -}} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} | ||
{{- else -}} | ||
{{- $name := default .Chart.Name .Values.nameOverride -}} | ||
{{- if contains $name .Release.Name -}} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" -}} | ||
{{- else -}} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.labels" -}} | ||
helm.sh/chart: {{ include "prometheus-opencost-exporter.chart" . }} | ||
{{ include "prometheus-opencost-exporter.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "prometheus-opencost-exporter.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create -}} | ||
{{ default (include "prometheus-opencost-exporter.fullname" .) .Values.serviceAccount.name }} | ||
{{- else -}} | ||
{{ default "default" .Values.serviceAccount.name }} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.prometheus.secretname" -}} | ||
{{- if .Values.opencost.prometheus.secret_name -}} | ||
{{- .Values.opencost.prometheus.secret_name -}} | ||
{{- else -}} | ||
{{- include "prometheus-opencost-exporter.fullname" . -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{/* | ||
Create the name of the controller service account to use | ||
*/}} | ||
{{- define "prometheus-opencost-exporter.prometheusServerEndpoint" -}} | ||
{{- if .Values.opencost.prometheus.external.enabled -}} | ||
{{ tpl .Values.opencost.prometheus.external.url . }} | ||
{{- else -}} | ||
{{- $host := tpl .Values.opencost.prometheus.internal.serviceName . }} | ||
{{- $ns := tpl .Values.opencost.prometheus.internal.namespaceName . }} | ||
{{- $port := .Values.opencost.prometheus.internal.port | int }} | ||
{{- printf "http://%s.%s.svc:%d" $host $ns $port -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
|
||
{{/* | ||
Check that either prometheus external or internal is defined | ||
*/}} | ||
{{- define "isPrometheusConfigValid" -}} | ||
{{- if and .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled -}} | ||
{{- fail "Only use one of the prometheus setups, internal or external" -}} | ||
{{- end -}} | ||
{{- end -}} |
Oops, something went wrong.