/
kubecost_eks_amp.go
157 lines (147 loc) · 4.77 KB
/
kubecost_eks_amp.go
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
package kubecost_eks_amp
import (
"github.com/awslabs/eksdemo/pkg/application"
"github.com/awslabs/eksdemo/pkg/cmd"
"github.com/awslabs/eksdemo/pkg/installer"
"github.com/awslabs/eksdemo/pkg/resource"
"github.com/awslabs/eksdemo/pkg/resource/amp_workspace"
"github.com/awslabs/eksdemo/pkg/resource/irsa"
"github.com/awslabs/eksdemo/pkg/template"
)
// Docs: https://docs.aws.amazon.com/eks/latest/userguide/cost-monitoring.html
// Docs: https://guide.kubecost.com/
// Helm: https://github.com/kubecost/cost-analyzer-helm-chart/tree/develop/cost-analyzer
// Values: https://github.com/kubecost/cost-analyzer-helm-chart/blob/develop/cost-analyzer/values.yaml
// Values: https://github.com/kubecost/cost-analyzer-helm-chart/blob/develop/cost-analyzer/values-eks-cost-monitoring.yaml
// Values: https://github.com/kubecost/cost-analyzer-helm-chart/blob/develop/cost-analyzer/values-amp.yaml
// Repo: https://gallery.ecr.aws/kubecost/cost-model
// Repo: https://gallery.ecr.aws/kubecost/frontend
// Repo: https://gallery.ecr.aws/kubecost/prometheus
// Repo: https://gallery.ecr.aws/bitnami/configmap-reload
// Version: Latest is Chart/App 1.103.3 (as of 5/24/23)
func NewApp() *application.Application {
options, flags := newOptions()
app := &application.Application{
Command: cmd.Command{
Parent: "kubecost",
Name: "eks-amp",
Description: "EKS optimized Kubecost using Amazon Managed Prometheus",
},
Dependencies: []*resource.Resource{
irsa.NewResourceWithOptions(&irsa.IrsaOptions{
CommonOptions: resource.CommonOptions{
Name: "kubecost-cost-analyzer-irsa",
},
PolicyType: irsa.PolicyARNs,
Policy: []string{
"arn:aws:iam::aws:policy/AmazonPrometheusQueryAccess",
"arn:aws:iam::aws:policy/AmazonPrometheusRemoteWriteAccess",
},
}),
irsa.NewResourceWithOptions(&irsa.IrsaOptions{
CommonOptions: resource.CommonOptions{
Name: "kubecost-prometheus-server-irsa",
ServiceAccount: "kubecost-prometheus-server",
},
PolicyType: irsa.PolicyARNs,
Policy: []string{
"arn:aws:iam::aws:policy/AmazonPrometheusQueryAccess",
"arn:aws:iam::aws:policy/AmazonPrometheusRemoteWriteAccess",
},
}),
amp_workspace.NewResourceWithOptions(options.AmpWorkspaceOptions),
},
Flags: flags,
Options: options,
Installer: &installer.HelmInstaller{
ChartName: "cost-analyzer",
ReleaseName: "kubecost-eks-amp",
RepositoryURL: "oci://public.ecr.aws/kubecost/cost-analyzer",
ValuesTemplate: &template.TextTemplate{
Template: valuesTemplate,
},
},
}
return app
}
const valuesTemplate = `---
fullnameOverride: kubecost-cost-analyzer
global:
amp:
enabled: true
prometheusServerEndpoint: http://localhost:8005/workspaces/{{ .AmpId }}
remoteWriteService: {{ .AmpEndpoint }}api/v1/remote_write
sigv4:
region: {{ .Region }}
grafana:
# If false, Grafana will not be installed
enabled: false
# If true, the kubecost frontend will route to your grafana through its service endpoint
proxy: false
prometheus:
enabled: {{ not .DisablePrometheus }}
sigV4Proxy:
region: {{ .Region }}
host: aps-workspaces.{{ .Region }}.amazonaws.com
imageVersion: prod-{{ .Version }}
kubecostFrontend:
image: public.ecr.aws/kubecost/frontend
kubecostModel:
image: public.ecr.aws/kubecost/cost-model
# The total number of days the ETL storage will build
etlStoreDurationDays: 120
serviceAccount:
name: {{ .ServiceAccount }}
annotations:
{{ .IrsaAnnotation }}
{{- if .IngressHost }}
ingress:
enabled: true
className: {{ .IngressClass }}
annotations:
{{- .IngressAnnotations | nindent 4 }}
pathType: Prefix
hosts:
- {{ .IngressHost }}
tls:
- hosts:
- {{ .IngressHost }}
{{- if ne .IngressClass "alb" }}
secretName: cost-analyzer-tls
{{- end }}
{{- end }}
service:
type: {{ .ServiceType }}
annotations:
{{- .ServiceAnnotations | nindent 4 }}
prometheus:
serviceAccounts:
server:
annotations:
{{ .IrsaAnnotationFor "kubecost-prometheus-server" }}
kube-state-metrics:
fullnameOverride: kubecost-kube-state-metrics
server:
fullnameOverride: kubecost-prometheus-server
image:
repository: public.ecr.aws/kubecost/prometheus
tag: v2.35.0
global:
# overrides kubecost default of 60s, sets to prom default of 10s
scrape_timeout: 10s
external_labels:
cluster_id: {{ .ClusterName }} # Each cluster should have a unique ID
configmapReload:
prometheus:
enabled: false
image:
repository: public.ecr.aws/bitnami/configmap-reload
tag: 0.7.1
nodeExporter:
enabled: {{ .EnableNodeExporter }}
fullnameOverride: kubecost-prometheus-node-exporter
reporting:
productAnalytics: false
kubecostProductConfigs:
clusterName: {{ .ClusterName }}
`