환경
- helm 3.1
- k8s 1.30
- EKS
원하는 것
- Grafana pod가 처음 생성될 때, user 계정들을 provision 하길 원함
- 생성된 user들을 적절히 그룹화하고 권한 등을 부여하고자 함.
문제 상황
- Grafana community에서는
admin
계정만 provision 가능함.
https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml#L482-L491
helm-charts/charts/grafana/values.yaml at main · grafana/helm-charts
Contribute to grafana/helm-charts development by creating an account on GitHub.
github.com
- RABC api는 Enterprise / Cloud 기능임.
https://grafana.com/docs/grafana/latest/administration/roles-and-permissions/access-control/
Grafana Role-based access control (RBAC) | Grafana documentation
Role-based access control (RBAC) RBAC provides a standardized way of granting, changing, and revoking access when it comes to viewing and modifying Grafana resources, such as dashboards, reports, and administrative settings. About RBAC Role-based access co
grafana.com
- Grafana 신규 생성 시 '유저 생성' 직접 하기엔 몹시 번거롭게 느껴짐.
해결 방법
- values.yaml에 적절한 값들을 작성한다.
- 예시 yaml 에서는
Grafana > provisionUsers > users
에 목록으로 기입했다.
- 예시 yaml 에서는
- helm의
post install
hook 에 job 을 생성한다. - image는 http post 요청을 보낼 수 있는 적절한 pod를 생성한다. (ex:
azure-cli
) - pod가 실행된 이후 user 생성 api를 호출, 적절한 유저 계정을 생성한다..
{{- if .Values.grafana.provisionUsers.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: provision-grafana-users
namespace: {{ .Release.Namespace | quote }}
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-delete-policy": before-hook-creation # Delete the hook before creating a new one
spec:
template:
spec:
containers:
- name: provision-grafana-users
image: mcr.microsoft.com/azure-cli
command: ["sh", "-c"]
args:
- |
# 1. 유저 생성
{{- range .Values.grafana.provisionUsers.users }}
AUTH=$(echo -n '{{ $.Values.grafana.adminUser }}:{{ $.Values.grafana.adminPassword }}' | base64) && \
curl -X POST http://{{ $.Release.Name | quote }}-grafana.{{ $.Release.Namespace | quote }}.svc:80/api/admin/users \
-H "Content-Type: application/json" \
-H "Authorization: Basic $AUTH" \
-d '{"name":"{{ .name }}", "email":"{{ .email }}", "login":"{{ .userId }}", "password":"{{ .password }}", "OrgId": 1}' && \
echo "Created user {{ .userId }}" || echo "Failed to create user {{ .userId }}" && \
{{- end }}
echo "User creation done!"\
restartPolicy: Never
backoffLimit: 4
{{- end }}
부연 설명
- user provisioning 자체는 위 방법으로 가능하다.
- 다만 RBAC API 역시 Enterprise 기능이라, 계정별로 권한을 부여한다던가 하는 기능은 사용하기 어렵다.
- Enterprise 기능을 사용하지 않고 유저들을 적절히 provision 하려면 아래 방법을 사용할 수 있을 것으로 보인다.
- Grafana 자체 DB(sqlite)가 아닌 DB(ex: postgreSQL) 설치
- Grafana와 해당 DB 연결
- SQL로 직접 provision 할 값들을 관리.
참고 자료들
* Grafana DB 마이그레이션 필요 시 해당 블로그 참고할 것.
https://tistory-cloud.tistory.com/22
Grafana Migration
Grafana를 사용 중 Grafana에 설정이 점점 많아져서 DB를 RDS로 옮겨야 할 필요성을 느꼈다. Grafana는 grafana.ini 에 [database] 설정을 하지 않았을 경우 기본 DB 인 sqlite3을 사용하게 된다 데이터가 적을 때
tistory-cloud.tistory.com
* Grafana 의 helm chart
https://github.com/grafana/helm-charts/tree/main/charts/grafana
helm-charts/charts/grafana at main · grafana/helm-charts
Contribute to grafana/helm-charts development by creating an account on GitHub.
github.com
차트 훅(hooks)
차트 훅을 이용하여 작업하는 방법을 설명한다.
helm.sh
'TIL > Monitoring(k8s, grafana)' 카테고리의 다른 글
Prometheus - exporter들의 정확성 테스트 (0) | 2025.02.21 |
---|---|
[모니터링, k8s]RKE2 기반 k8s 모니터링 (0) | 2025.02.21 |
[AI, Kubeflow] Kubeflow bootstrap 소개 (0) | 2025.01.24 |
[Loki, K8s] 원인 불명의 Loki - CrashLoopBackOff 문제 해결 (EBS 용량 ) (0) | 2025.01.07 |
[K8s, Grafana] Loki 데이터량 확인 및 유지기간 설정 방법 확인(2.6.1) (0) | 2024.12.10 |