有这么个场景,想在同一命名空间下部署promethus与grafana,数据源想默认配置为promethus服务的地址,如

http://prometheus-server:9090

emmmm,由于使用应用模板部署的话,会在原有服务名的基础上,拼接应用名

大家有比较优雅的解决方案吗?

  • shaowenchen 回复了此帖
  • shaowenchen
    通过sidecar实现了。

    新增prometheus/templates/server/datasource-cm.yaml

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{ template "prometheus.server.fullname" . }}-datasource
    {{ include "prometheus.namespace" . | indent 2 }}
      labels:
        grafana_datasource: {{ template "prometheus.server.fullname" . }}
    data:
      #datasource.yaml: |-
      {{ template "prometheus.server.fullname" . }}.yaml: |-
        apiVersion: 1
        datasources:
        - access: proxy
          editable: false
          name: {{ template "prometheus.server.fullname" . }}
          type: prometheus
          url: http://{{ template "prometheus.server.fullname" . }}:80

    grafana/values.yaml核心配置

    sidecar:
      image:
        repository: harbor.wl.com/kiwigrid/k8s-sidecar
        tag: 1.10.6
        sha: ""
      imagePullPolicy: IfNotPresent
      resources: {}
    #   limits:
    #     cpu: 100m
    #     memory: 100Mi
    #   requests:
    #     cpu: 50m
    #     memory: 50Mi
      # skipTlsVerify Set to true to skip tls verification for kube api calls
      # skipTlsVerify: true
      enableUniqueFilenames: false
      dashboards:
        enabled: false
        SCProvider: true
        # label that the configmaps with dashboards are marked with
        label: grafana_dashboard
        # value of label that the configmaps with dashboards are set to
        labelValue: null
        # folder in the pod that should hold the collected dashboards (unless `defaultFolderName` is set)
        folder: /tmp/dashboards
        # The default folder name, it will create a subfolder under the `folder` and put dashboards in there instead
        defaultFolderName: null
        # If specified, the sidecar will search for dashboard config-maps inside this namespace.
        # Otherwise the namespace in which the sidecar is running will be used.
        # It's also possible to specify ALL to search in all namespaces
        searchNamespace: null
        # If specified, the sidecar will look for annotation with this name to create folder and put graph here.
        # You can use this parameter together with `provider.foldersFromFilesStructure`to annotate configmaps and create folder structure.
        folderAnnotation: null
        # provider configuration that lets grafana manage the dashboards
        provider:
          # name of the provider, should be unique
          name: sidecarProvider
          # orgid as configured in grafana
          orgid: 1
          # folder in which the dashboards should be imported in grafana
          folder: ''
          # type of the provider
          type: file
          # disableDelete to activate a import-only behaviour
          disableDelete: false
          # allow updating provisioned dashboards from the UI
          allowUiUpdates: false
          # allow Grafana to replicate dashboard structure from filesystem
          foldersFromFilesStructure: false
      datasources:
        enabled: true
        # label that the configmaps with datasources are marked with
        label: grafana_datasource
        # value of label that the configmaps with datasources are set to
        labelValue: null
        # If specified, the sidecar will search for datasource config-maps inside this namespace.
        # Otherwise the namespace in which the sidecar is running will be used.
        # It's also possible to specify ALL to search in all namespaces
        searchNamespace: null
      notifiers:
        enabled: false
        # label that the configmaps with notifiers are marked with
        label: grafana_notifier
        # If specified, the sidecar will search for notifier config-maps inside this namespace.
        # Otherwise the namespace in which the sidecar is running will be used.
        # It's also possible to specify ALL to search in all namespaces
        searchNamespace: null

    weiliang-ms

    我看到官方默认 chart 的服务都有拼接,可能不太好改。不如换个思路,新创建一个 service。拷贝一份现在的,改下 name 。

      shaowenchen
      通过sidecar实现了。

      新增prometheus/templates/server/datasource-cm.yaml

      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: {{ template "prometheus.server.fullname" . }}-datasource
      {{ include "prometheus.namespace" . | indent 2 }}
        labels:
          grafana_datasource: {{ template "prometheus.server.fullname" . }}
      data:
        #datasource.yaml: |-
        {{ template "prometheus.server.fullname" . }}.yaml: |-
          apiVersion: 1
          datasources:
          - access: proxy
            editable: false
            name: {{ template "prometheus.server.fullname" . }}
            type: prometheus
            url: http://{{ template "prometheus.server.fullname" . }}:80

      grafana/values.yaml核心配置

      sidecar:
        image:
          repository: harbor.wl.com/kiwigrid/k8s-sidecar
          tag: 1.10.6
          sha: ""
        imagePullPolicy: IfNotPresent
        resources: {}
      #   limits:
      #     cpu: 100m
      #     memory: 100Mi
      #   requests:
      #     cpu: 50m
      #     memory: 50Mi
        # skipTlsVerify Set to true to skip tls verification for kube api calls
        # skipTlsVerify: true
        enableUniqueFilenames: false
        dashboards:
          enabled: false
          SCProvider: true
          # label that the configmaps with dashboards are marked with
          label: grafana_dashboard
          # value of label that the configmaps with dashboards are set to
          labelValue: null
          # folder in the pod that should hold the collected dashboards (unless `defaultFolderName` is set)
          folder: /tmp/dashboards
          # The default folder name, it will create a subfolder under the `folder` and put dashboards in there instead
          defaultFolderName: null
          # If specified, the sidecar will search for dashboard config-maps inside this namespace.
          # Otherwise the namespace in which the sidecar is running will be used.
          # It's also possible to specify ALL to search in all namespaces
          searchNamespace: null
          # If specified, the sidecar will look for annotation with this name to create folder and put graph here.
          # You can use this parameter together with `provider.foldersFromFilesStructure`to annotate configmaps and create folder structure.
          folderAnnotation: null
          # provider configuration that lets grafana manage the dashboards
          provider:
            # name of the provider, should be unique
            name: sidecarProvider
            # orgid as configured in grafana
            orgid: 1
            # folder in which the dashboards should be imported in grafana
            folder: ''
            # type of the provider
            type: file
            # disableDelete to activate a import-only behaviour
            disableDelete: false
            # allow updating provisioned dashboards from the UI
            allowUiUpdates: false
            # allow Grafana to replicate dashboard structure from filesystem
            foldersFromFilesStructure: false
        datasources:
          enabled: true
          # label that the configmaps with datasources are marked with
          label: grafana_datasource
          # value of label that the configmaps with datasources are set to
          labelValue: null
          # If specified, the sidecar will search for datasource config-maps inside this namespace.
          # Otherwise the namespace in which the sidecar is running will be used.
          # It's also possible to specify ALL to search in all namespaces
          searchNamespace: null
        notifiers:
          enabled: false
          # label that the configmaps with notifiers are marked with
          label: grafana_notifier
          # If specified, the sidecar will search for notifier config-maps inside this namespace.
          # Otherwise the namespace in which the sidecar is running will be used.
          # It's also possible to specify ALL to search in all namespaces
          searchNamespace: null