tr5*_*r53 10 grafana kubernetes kubernetes-helm configmap
我正在尝试了解掌舵,我想知道是否有人可以 ELI5 给我一些东西或帮助我做一些事情。
所以我确实在下面运行:
helm repo add coreos https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/
Run Code Online (Sandbox Code Playgroud)
然后我使用以下方法安装了 kube-prometheus:
helm install coreos/kube-prometheus --name kube-prometheus -f values.yaml --namespace monitoringtest
Run Code Online (Sandbox Code Playgroud)
一切正常,但我正在尝试从 json 文件添加一些自定义仪表板,我正在努力理解如何做到这一点。
我正在关注这个: https://blogcodevalue.wordpress.com/2018/09/16/automate-grafana-dashboard-import-process/
在我的 values.yaml 中,我在下面添加了
serverDashboardConfigmaps:
- example-dashboards
Run Code Online (Sandbox Code Playgroud)
我明白,如果我这样做:
helm upgrade --install kube-prometheus -f values.yaml --namespace monitoringtest coreos/kube-prometheus
Run Code Online (Sandbox Code Playgroud)
这应该会导致 grafana 获取下面的 configmap 调用example-dashboards并从custom-dashboards文件夹加载 * .json文件。
apiVersion: v1
kind: ConfigMap
metadata:
name: example-dashboards
data:
{{ (.Files.Glob "custom-dashboards/*.json").AsConfig | indent 2 }}
# Or
#
# data:
# custom-dashboard.json: |-
# {{ (.Files.Get "custom.json") | indent 4 }}
#
# The filename (and consequently the key under data) must be in the format `xxx-dashboard.json` or `xxx-datasource.json`
# for them to be picked up.
Run Code Online (Sandbox Code Playgroud)
现在两个问题:
如何将上述配置映射添加到此掌舵版本?
这个custom-dashboards文件夹在哪里?它是在我的笔记本电脑上然后发送到 grafana 吗?
我需要将所有内容复制https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/到我的笔记本电脑上吗?
抱歉解释了一切,但我只是想了解这一点。
您可以在此处的 prometheus-operator 图表中找到如何执行此操作的一个很好的示例:
https://github.com/helm/charts/tree/master/stable/prometheus-operator/templates/grafana
它是一个 ConfigMapList,从给定目录获取所有 JSON 并将它们存储到 Grafana 读取的 ConfigMap 中。
{{- $files := .Files.Glob "dashboards/*.json" }}
{{- if $files }}
apiVersion: v1
kind: ConfigMapList
items:
{{- range $path, $fileContents := $files }}
{{- $dashboardName := regexReplaceAll "(^.*/)(.*)\\.json$" $path "${2}" }}
- apiVersion: v1
kind: ConfigMap
metadata:
name: {{ printf "%s-%s" (include "prometheus-operator.fullname" $) $dashboardName | trunc 63 | trimSuffix "-" }}
namespace: {{ template "prometheus-operator.namespace" . }}
labels:
{{- if $.Values.grafana.sidecar.dashboards.label }}
{{ $.Values.grafana.sidecar.dashboards.label }}: "1"
{{- end }}
app: {{ template "prometheus-operator.name" $ }}-grafana
{{ include "prometheus-operator.labels" $ | indent 6 }}
data:
{{ $dashboardName }}.json: {{ $.Files.Get $path | toJson }}
{{- end }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)
请注意 ConfigMap 的大小可能受到限制: /sf/answers/3711103091/
在 2021 年最新版本的kube-prometheus-stack图表中,根据github 上的这个答案,您应该只创建一个包含仪表板数据和正确标签的配置映射,它将由 grafana pod 中的 sidecar 检查。
例子:
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-dashboards-custom-1
namespace: monitoring
labels:
grafana_dashboard: "1"
prometheus: my-value
release: prometheus
data:
app-status.json: |-
{
"annotations": {
"list": [
{
Run Code Online (Sandbox Code Playgroud)
prometheus: my-value来自这个舵图值:
prometheus:
prometheusSpec:
serviceMonitorSelector:
matchLabels:
prometheus: my-value
Run Code Online (Sandbox Code Playgroud)
我部分地弄清楚了。我可以从配置映射加载仪表板。还不是来自单独的 json 文件,但这是一个进步。
对于任何感兴趣的人,我将其放在我的 github 页面上: https: //github.com/tretos53/notes/blob/master/Grafana/Readme.MD
| 归档时间: |
|
| 查看次数: |
11494 次 |
| 最近记录: |