forked from m-yosefpor/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md.gotmpl
158 lines (114 loc) · 7.72 KB
/
README.md.gotmpl
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Cloud Pricing API
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}
{{ template "chart.description" . }}
## TL;DR
Installing the chart will create three pods: PostgreSQL DB, Cloud Pricing API, and an init job that loads the pricing data. The init job will take a few minutes and exit after the logs show `Completed: downloading DB data` -- you should **wait** for that before running the Infracost CLI. A weekly cronjob is also created to update the prices. Our resource request/limit recommendations are commented-out in the [values.yaml](values.yaml) file per Helm best practices.
```sh
helm repo add infracost https://infracost.github.io/helm-charts/
helm repo update
# Run `infracost register` to create an API key, this is used by the weekly job to download the latest cloud pricing data from us.
helm install cloud-pricing-api infracost/cloud-pricing-api \
--set infracostAPIKey="YOUR_INFRACOST_API_KEY_HERE" \
--set postgresql.postgresqlPassword="STRONG_PASSWORD_HERE"
```
We recommend you create an [ingress route](#install-in-aws-with-alb-ingress) so your Infracost CLI users can connect to your self-hosted Cloud Pricing API.
Regardless of you using ingress or port-forward, the home page for the Cloud Pricing API, [**http://localhost:4000**](http://localhost:4000), shows if prices are up-to-date and some statistics.
Uninstalling the chart will not delete the PVC used by the PostgreSQL DB.
```sh
helm uninstall cloud-pricing-api
```
## Configure CLI to use self-hosted Cloud Pricing API
The best way to get instructions for configuring Infracost to use the self-hosted Cloud Pricing API is to check the output at the end of the `helm install` step since this contains the exact commands you need to run. If these are not available, you can:
1. If you don't have ingress enabled you can port-forward the Cloud Pricing API to your local machine by doing this:
```sh
export NAMESPACE=my-namespace
echo "Your self-hosted Infracost API key is $(kubectl get secret --namespace $NAMESPACE cloud-pricing-api --template="{{"{{"}} index .data \"self-hosted-infracost-api-key\" {{"}}"}}" | base64 -D)"
export POD_NAME=$(kubectl get pods --namespace $NAMESPACE -l "app.kubernetes.io/name=cloud-pricing-api,app.kubernetes.io/instance=cloud-pricing-api" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace $NAMESPACE $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
kubectl --namespace $NAMESPACE port-forward $POD_NAME 4000:$CONTAINER_PORT
```
2. When using the CLI locally, run the following two required commands to point your CLI to your self-hosted Cloud Pricing API. Your Infracost CLI users will use the API key to authenticate when calling your self-hosted Cloud Pricing API.
```sh
infracost configure set pricing_api_endpoint http://localhost:4000
infracost configure set api_key API_KEY_FROM_ABOVE
infracost breakdown --path /path/to/code
```
3. In CI/CD systems, set the following two required environment variables:
```sh
export INFRACOST_PRICING_API_ENDPOINT=http://endpoint
export INFRACOST_API_KEY=API_KEY_FROM_ABOVE
```
## Prerequisites
* Kubernetes 1.12+ with Beta APIs enabled
* Helm >= 3.1.0
* PV provisioner support in the underlying infrastructure
{{ template "chart.requirementsSection" . }}
{{ template "chart.valuesSection" . }}
See the [values.yaml](values.yaml) file for parameters that our chart uses. The full list of parameters are in the [Bitnami PostgreSQL chart](https://github.com/bitnami/charts/blob/master/bitnami/postgresql/README.md); you can specify the values for this chart by prefixing them with `postgresql.`
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example:
```sh
helm install cloud-pricing-api infracost/cloud-pricing-api \
--set api.selfHostedInfracostAPIKey=CUSTOM_API_KEY
```
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example:
```sh
helm install -f my-values.yaml cloud-pricing-api infracost/cloud-pricing-api
```
## PostgreSQL
By default, PostgreSQL is installed as part of the chart using the [Bitnami PostgreSQL chart](https://github.com/bitnami/charts/blob/master/bitnami/postgresql/README.md). You can specify the values for this chart by prefixing them with `postgresql.`. To avoid issues when upgrading this chart, provide `postgresql.postgresqlPassword` for subsequent installs and upgrades. This is due to an issue in the PostgreSQL chart where password will be overwritten with randomly generated passwords otherwise. See [here](https://github.com/helm/charts/tree/master/stable/postgresql#upgrade) for more detail.
To use an external PostgreSQL server (such as AWS RDS or Azure Database for PostgreSQL), set `postgresql.enabled` to `false` and set the `postgresql.external.*` values:
sh
```
helm install cloud-pricing-api infracost/cloud-pricing-api \
--set infracostAPIKey="YOUR_INFRACOST_API_KEY_HERE" \
--set postgresql.enabled="false" \
--set postgresql.external.host="MY_HOST" \
--set postgresql.external.port="MY_PORT" \
--set postgresql.external.database="MY_DATABASE" \
--set postgresql.external.user="MY_USER" \
--set postgresql.external.password="MY_PASSWORD"
```
## Examples
### Install in AWS with ALB ingress
This is how the Infracost team deploys the Cloud Pricing API on our EKS cluster to test it.
```sh
export DOMAIN=cloud-pricing.api.dev.infracost.io
export CERTIFICATE_DOMAIN=*.api.dev.infracost.io
export CERTIFICATE_ARN=$(aws acm list-certificates --query 'CertificateSummaryList[].[CertificateArn,DomainName]' --output text | grep ${CERTIFICATE_DOMAIN} | cut -f1)
helm install cloud-pricing-api infracost/cloud-pricing-api \
--set ingress.enabled=true \
--set ingress.hosts\[0\].host=${DOMAIN} \
--set ingress.hosts\[0\].paths\[0\].path=/\* \
--set ingress.extraPaths\[0\].path=/\* \
--set ingress.extraPaths\[0\].backend.serviceName=ssl-redirect \
--set ingress.extraPaths\[0\].backend.servicePort=use-annotation \
--set ingress.annotations."kubernetes\.io/ingress\.class"=alb \
--set ingress.annotations."alb\.ingress\.kubernetes\.io/scheme"=internet-facing \
--set ingress.annotations."alb\.ingress\.kubernetes\.io/target-type"=ip \
--set ingress.annotations."alb\.ingress\.kubernetes\.io/certificate-arn"=${CERTIFICATE_ARN} \
--set ingress.annotations."alb\.ingress\.kubernetes\.io/healthcheck-path"=/health
--set-string ingress.annotations."alb\.ingress\.kubernetes\.io/listen-ports"="\[\{\"HTTP\": 80\}\, \{\"HTTPS\":443\}\]" \
--set-string ingress.annotations."alb\.ingress\.kubernetes\.io/ssl-redirect"="\{\"Type\": \"redirect\"\, \"RedirectConfig\": \{ \"Protocol\": \"HTTPS\"\, \"Port\": \"443\"\, \"StatusCode\": \"HTTP_301\"\}\}"
```
## Upgrade to latest version
Use the following commands to upgrade to the latest released version of the Cloud Pricing API and Helm chart; you should pass-in any variables that you set during install with `--set`:
```
kubectl delete job -n my-namespace hosted-cloud-pricing-api-init-job
helm upgrade cloud-pricing-api infracost/cloud-pricing-api \
--set infracostAPIKey="YOUR_INFRACOST_API_KEY_HERE" \
--set postgresql.postgresqlPassword="STRONG_PASSWORD_HERE"
```
## Development
To install the chart from your local repository with the name `my-release`:
```sh
helm install my-release .
```
To uninstall `my-release` deployment:
```sh
helm uninstall my-release
```
To debug issues, such as `job-cron.yaml: error converting YAML to JSON: yaml: line X`, use the following:
```sh
helm template cloud-pricing-api charts/cloud-pricing-api/ --debug > out.yaml
cat out.yaml # look for issues in the YAML in the erroring resource
```