Skip to content

Commit 8a070bc

Browse files
Svarrogh1337oliverbaehler
authored andcommitted
feat(docs): add opencost integration (#41)
* feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> * feat(docs): add opencost integration Signed-off-by: Hristo Hristov <me@hhristov.info> --------- Signed-off-by: Hristo Hristov <me@hhristov.info> Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
1 parent a40a83e commit 8a070bc

5 files changed

Lines changed: 388 additions & 165 deletions

File tree

content/en/docs/tenants/enforcement.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@ description: >
1111
### Namespaces
1212

1313
#### AdditionalMetadataList
14-
14+
{{% alert title="Information" color="info" %}}
15+
Starting from v0.10.8, it is possible to use templated values for labels and annotations.
16+
Currently, `{{ tenant.name }}` and `{{ namespace }}` placeholders are available.
17+
{{% /alert %}}
18+
```yaml
19+
apiVersion: capsule.clastix.io/v1beta2
20+
kind: Tenant
21+
metadata:
22+
name: solar
23+
spec:
24+
owners:
25+
- name: alice
26+
kind: User
27+
namespaceOptions:
28+
additionalMetadataList:
29+
- annotations:
30+
templated-annotation: {{ tenant.name }}
31+
labels:
32+
templated-label: {{ namespace }}
33+
```
1534
The cluster admin can "taint" the namespaces created by tenant owners with additional metadata as labels and annotations. There is no specific semantic assigned to these labels and annotations: they will be assigned to the namespaces in the tenant as they are created. However you have the option to be more specific by selecting to which namespaces you want to assign what kind of metadata:
1635
1736
```yaml

content/en/docs/whats-new.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ We have added new documentation for a better experience. See the following Topic
2424

2525
Newly added documentation to integrate Capsule with other applications:
2626

27+
* [OpenCost](/ecosystem/integrations/opencost/)
2728
* [Headlamp](/ecosystem/integrations/headlamp/)
2829
* [Gangplank](/ecosystem/integrations/gangplank/)
2930
* [Openshift](/docs/operating/setup/openshift/)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: OpenCost
3+
description: "OpenCost Integration for Tenants"
4+
logo: https://landscape.cncf.io/logos/ba27e92ddd22f942dde50f20b6d6d3f2ac7a0b78baf2471bdd89eb5d105c708f.svg
5+
type: single
6+
display: true
7+
integration: true
8+
---
9+
{{% pageinfo %}}
10+
This guide explains how to integrate OpenCost with Capsule to provide cost visibility and chargeback/showback per tenant.
11+
You can group workloads into tenants by annotating namespaces (for example, `opencost.projectcapsule.dev/tenant: {{ tenant.name }}`).
12+
OpenCost can use this annotation to aggregate costs, enabling accurate cost allocation across clusters, nodes, namespaces, controller kinds, controllers, services, pods, and containers for each tenant.
13+
{{% /pageinfo %}}
14+
15+
# Prerequisites
16+
- [Capsule](/docs/operating/setup/installation/) v0.10.8 or later
17+
- [Prometheus Operator](https://prometheus-operator.dev/docs/getting-started/installation/)
18+
- [Prometheus](https://opencost.io/docs/installation/prometheus)
19+
- [OpenCost](https://opencost.io/docs/installation/helm)
20+
21+
# Installation
22+
23+
## Capsule
24+
1. Create a tenant with spec.namespaceOptions.additionalMetadataList:
25+
```bash
26+
kubectl create -f - << EOF
27+
apiVersion: capsule.clastix.io/v1beta2
28+
kind: Tenant
29+
metadata:
30+
name: solar
31+
spec:
32+
namespaceOptions:
33+
additionalMetadataList:
34+
- annotations:
35+
opencost.projectcapsule.dev/tenant: "{{ tenant.name }}"
36+
owners:
37+
- name: alice
38+
kind: User
39+
EOF
40+
```
41+
42+
## OpenCost
43+
1. Create a basic OpenCost values file. Set emitNamespaceAnnotations: true because aggregation is based on the Capsule annotation.
44+
```yaml
45+
opencost:
46+
prometheus:
47+
internal:
48+
namespaceName: prometheus-system
49+
serviceName: prometheus-server
50+
port: 80
51+
52+
dataRetention:
53+
dailyResolutionDays: 30 # default: 15
54+
55+
exporter:
56+
defaultClusterId: kind-opencost-capsule
57+
replicas: 1
58+
resources:
59+
requests:
60+
cpu: "10m"
61+
memory: "55Mi"
62+
limits:
63+
memory: "1Gi"
64+
persistence:
65+
enabled: false
66+
67+
metrics:
68+
kubeStateMetrics:
69+
emitNamespaceAnnotations: true
70+
emitPodAnnotations: true
71+
emitKsmV1Metrics: false
72+
emitKsmV1MetricsOnly: false
73+
serviceMonitor:
74+
enabled: true
75+
additionalLabels:
76+
release: prometheus
77+
```
78+
2. Install OpenCost with the values above:
79+
```bash
80+
helm install opencost opencost-charts/opencost --namespace opencost --create-namespace -f values.yaml
81+
```
82+
83+
# Fetch data from OpenCost
84+
{{% alert title="Note!" color=warning %}}
85+
Aggregation is only possible via the API. There is no option to aggregate using the UI.
86+
{{% /alert %}}
87+
88+
1. Port-forward:
89+
```bash
90+
kubectl -n opencost port-forward deployment/opencost 9003:9003 9090:9090
91+
```
92+
2. Query the API:
93+
- Aggregate by namespace:
94+
```bash
95+
curl -G http://localhost:9003/allocation \
96+
-d window=1h \
97+
-d aggregate=namespace,annotation:opencost_projectcapsule_dev_tenant \
98+
-d resolution=1h
99+
```
100+
- Aggregate by pod:
101+
```bash
102+
curl -G http://localhost:9003/allocation \
103+
-d window=1h \
104+
-d aggregate=pod,annotation:opencost_projectcapsule_dev_tenant \
105+
-d resolution=1h
106+
```
107+
- Aggregate by deployment:
108+
```bash
109+
curl -G http://localhost:9003/allocation \
110+
-d window=1h \
111+
-d aggregate=deployment,annotation:opencost_projectcapsule_dev_tenant \
112+
-d resolution=1h
113+
```

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[build]
66
publish = "public"
7-
command = "npm install --save-dev autoprefixer && npm install --save-dev postcss-cli && npm install -D postcss && hugo --gc --minify --baseURL https://kyverno.io/"
7+
command = "npm install --save-dev autoprefixer && npm install --save-dev postcss-cli && npm install -D postcss && hugo --gc --minify --baseURL $DEPLOY_PRIME_URL"
88

99
[context.production.environment]
1010
HUGO_VERSION = "0.145.0"

0 commit comments

Comments
 (0)