Prometheus-grafana-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: grafana
  labels:
    app: grafana
    component: core
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: grafana
        component: core
    spec:
      containers:
        - image: grafana/grafana:3.1.1
          name: grafana
          # env:
          resources:
            # keep request = limit to keep this container in guaranteed class
            limits:
              cpu: 100m
              memory: 100Mi
            requests:
              cpu: 100m
              memory: 100Mi
          env:
            # This variable is required to setup templates in Grafana.
              # The following env variables are required to make Grafana accessible via
              # the kubernetes api-server proxy. On production clusters, we recommend
              # removing these env variables, setup auth for grafana, and expose the grafana
              # service using a LoadBalancer or a public IP.
            - name: GF_AUTH_BASIC_ENABLED
              value: "false"
            - name: GF_AUTH_ANONYMOUS_ENABLED
              value: "true"
            - name: GF_AUTH_ANONYMOUS_ORG_ROLE
              value: Admin
            # - name: GF_SERVER_ROOT_URL
            #   value: /api/v1/proxy/namespaces/kube-system/services/monitoring-grafana/
          volumeMounts:
          - name: grafana-persistent-storage
            mountPath: /var
        - name: grafana-import-dashboards
          image: docker
          command: ["/bin/sh", "-c"]
          workingDir: /opt/grafana-import-dashboards
          args:
            # FIXME use kubernetes probe instead of "until curl"
            - >
              apk --update add curl ;
              until $(curl --silent --fail --show-error --output /dev/null http://localhost:3000/api/datasources); do
                printf '.' ; sleep 1 ;
              done ;
              for file in *-datasource.json ; do
                if [ -e "$file" ] ; then
                  echo "importing $file" &&
                  curl --silent --fail --show-error \
                    --request POST http://localhost:3000/api/datasources \
                    --header "Content-Type: application/json" \
                    --data-binary "@$file" ;
                  echo "" ;
                fi
              done ;
              for file in *-dashboard.json ; do
                if [ -e "$file" ] ; then
                  # wrap exported Grafana dashboard into valid json
                  echo "importing $file" &&
                  (echo '{"dashboard":';cat "$file";echo ',"inputs":[{"name":"DS_PROMETHEUS","pluginId":"prometheus","type":"datasource","value":"prometheus"}]}') | curl --silent --fail --show-error \
                    --request POST http://localhost:3000/api/dashboards/import \
                    --header "Content-Type: application/json" \
                    --data-binary @-;
                  echo "" ;
                fi
              done ;
              while true; do
                sleep 1m ;
              done
          volumeMounts:
          - name: config-volume
            mountPath: /opt/grafana-import-dashboards
      volumes:
      - name: config-volume
        configMap:
          name: grafana-import-dashboards
      - name: grafana-persistent-storage
        emptyDir: {}

最后更新于