Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helm chart prom-rds-exporter #220

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions charts/prom-rds-exporter/.helmignore
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/
37 changes: 37 additions & 0 deletions charts/prom-rds-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: v2
name: prom-rds-exporter
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

home: https://github.com/dungpham91/rds_exporter
sources:
- https://github.com/dungpham91/rds_exporter

keywords:
- exporter
- prometheus
- rds

maintainers:
- email: [email protected]
name: dungpham91
118 changes: 118 additions & 0 deletions charts/prom-rds-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Use the chart `prom-rds-exporter` in the EKS

## 1. Create IAM role

Go to the IAM console and create a role name `prom-rds-exporter`, with:

- Attach 2 policies to this role:
- `AmazonRDSReadOnlyAccess`
- `CloudWatchReadOnlyAccess`

- Edit `Trust relationships` with below content. Replace:
- `region`: with your cluster's region
- `XXXXXXXXXXXX`: with your AWS account ID
- `XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`: with your EKS cluster's OIDC provider ID. Refer to this doc: [https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html)

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::XXXXXXXXXXXX:oidc-provider/oidc.eks.region.amazonaws.com/id/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.region.amazonaws.com/id/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:aud": "sts.amazonaws.com",
"oidc.eks.region.amazonaws.com/id/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:sub": "system:serviceaccount:prom-rds-exporter:prom-rds-exporter"
}
}
}
]
}
```

## 2. Enable Enhanced for the RDS instances

Follow this doc: [https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.Enabling.html](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.Enabling.html)

## 3. Install Helm chart

- Update the role in the file [values.yaml](./values.yaml) at the line `58` and `85`.

```yaml
...
aws:
role: arn:aws:iam::xxxxxxxxxxxx:role/prom-rds-exporter
...
```

```yaml
...
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::xxxxxxxxxxxx:role/prom-rds-exporter
...
```

- Update the configurations for your RDS instances.

```yaml
...
config: |-
# This is the default configuration for prom-rds-exporter
instances:
- region: us-east-2
instance: rds-name
disable_basic_metrics: true
disable_enhanced_metrics: false
...
```

- Connect to your EKS cluster and run this command to install the Helm chart.

```sh
# Install the chart
helm install prom-rds-exporter prom-rds-exporter/ --namespace prom-rds-exporter --values prom-rds-exporter/values.yaml

# Update the Helm chart when you update the file values.yaml
helm upgrade prom-rds-exporter prom-rds-exporter/ --namespace prom-rds-exporter --values prom-rds-exporter/values.yaml

# Uninstall the Helm chart from your cluster
helm uninstall prom-rds-exporter -n prom-rds-exporter
```

## 4. Check the result

- Check the pod is running.

```sh
kubectl get pods -n prom-rds-exporter
```

You should see something like this.

```console
time="2023-04-03T08:05:41Z" level=info msg="Starting RDS exporter (version=, branch=, revision=)" source="main.go:30"
time="2023-04-03T08:05:41Z" level=info msg="Build context (go=go1.19, user=, date=)" source="main.go:31"
time="2023-04-03T08:05:41Z" level=info msg="Creating sessions..." component=sessions source="sessions.go:48"
Region Instance Resource ID Interval
us-east-2 rds-name db-XXXXXXXXXXXXXXXXXXXXXXXXXX 1m0s
time="2023-04-03T08:05:41Z" level=info msg="Using 1 sessions." component=sessions source="sessions.go:166"
time="2023-04-03T08:05:41Z" level=info msg="Updating enhanced metrics every 1m0s." component=enhanced source="collector.go:49"
time="2023-04-03T08:05:41Z" level=info msg="Basic metrics : http://:9042/basic" source="main.go:65"
time="2023-04-03T08:05:41Z" level=info msg="Enhanced metrics: http://:9042/enhanced" source="main.go:66"
```

- Forwarding the service to your local machine with this command.

```sh
kubectl port-forward service/prom-rds-exporter 9042:9042 -n prom-rds-exporter
```

Then you can go to your browser and type this links to see the metrics:

- [http://localhost:9042/basic](http://localhost:9042/basic): see the basic metrics

- [http://localhost:9042/enhanced](http://localhost:9042/enhanced): see the enhanced metrics
22 changes: 22 additions & 0 deletions charts/prom-rds-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "prom-rds-exporter.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "prom-rds-exporter.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "prom-rds-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "prom-rds-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions charts/prom-rds-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "prom-rds-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 "prom-rds-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 "prom-rds-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "prom-rds-exporter.labels" -}}
helm.sh/chart: {{ include "prom-rds-exporter.chart" . }}
{{ include "prom-rds-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "prom-rds-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "prom-rds-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "prom-rds-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "prom-rds-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/prom-rds-exporter/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ template "prom-rds-exporter.fullname" . }}
labels:
app: {{ template "prom-rds-exporter.name" . }}
chart: {{ template "prom-rds-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
rules:
- apiGroups: [""]
resources: ["secrets","configmap"]
resourceNames: ["{{ template "prom-rds-exporter.fullname" . }}"]
verbs: ["get"]
{{- end }}
19 changes: 19 additions & 0 deletions charts/prom-rds-exporter/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ template "prom-rds-exporter.fullname" . }}
labels:
app: {{ template "prom-rds-exporter.name" . }}
chart: {{ template "prom-rds-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
subjects:
- kind: ServiceAccount
name: {{ template "prom-rds-exporter.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ template "prom-rds-exporter.fullname" . }}
apiGroup: rbac.authorization.k8s.io
{{ end }}
13 changes: 13 additions & 0 deletions charts/prom-rds-exporter/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "prom-rds-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "prom-rds-exporter.name" . }}
chart: {{ template "prom-rds-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
config.yml: |
{{ tpl .Values.config . | nindent 4 }}
Loading
Loading