Prometheus -1-2

4 安装和配置可视化 UI 界面 Grafana

安装 Grafana 需要的镜像.   heapster-grafana-amd64_v5_0_4.tar.gz 

cat grafana.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: monitoring-grafana

  namespace: kube-system

spec:

  replicas: 1

  selector:

    matchLabels:

      task: monitoring

      k8s-app: grafana

  template:

    metadata:

      labels:

        task: monitoring

        k8s-app: grafana

    spec:

      containers:

      - name: grafana

        image: k8s.gcr.io/heapster-grafana-amd64:v5.0.4

        ports:

        - containerPort: 3000

          protocol: TCP

        volumeMounts:

        - mountPath: /etc/ssl/certs

          name: ca-certificates

          readOnly: true

        - mountPath: /var

          name: grafana-storage

        env:

        - name: INFLUXDB_HOST

          value: monitoring-influxdb

        - name: GF_SERVER_HTTP_PORT

          value: "3000"

          # 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

          # If you're only using the API Server proxy, set this value instead:

          # value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy

          value: /

      volumes:

      - name: ca-certificates

        hostPath:

          path: /etc/ssl/certs

      - name: grafana-storage

        emptyDir: {}

---

apiVersion: v1

kind: Service

metadata:

  labels:

    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)

    # If you are NOT using this as an addon, you should comment out this line.

    kubernetes.io/cluster-service: 'true'

    kubernetes.io/name: monitoring-grafana

  name: monitoring-grafana

  namespace: kube-system

spec:

  # In a production setup, we recommend accessing Grafana through an external Loadbalancer

  # or through a public IP.

  # type: LoadBalancer

  # You could also use NodePort to expose the service at a randomly-generated port

  # type: NodePort

  ports:

  - port: 80

    targetPort: 3000

  selector:

    k8s-app: grafana

  type: NodePort

kubectl get pods -n kube-system| grep monitor

monitoring-grafana-675798bf47-9l8f8        1/1    Running  0          9s

#查看 grafana 前端的 service

kubectl get svc -n kube-system | grep grafana

monitoring-grafana NodePort 10.97.239.168 80:31308/TCP 21h

#登陆 grafana,在浏览器访问

192.168.172.164:31308

#配置 grafana 界面

开始配置 grafana 的 web 界面: 选择 Create your first data source

Name: Prometheus

Type: Prometheus

HTTP 

处的 URL 如下: http://prometheus.monitor-sa.svc:9090 配置好的整体页面如下:

点击左下角 Save & Test,出现如下 Data source is working,说明 prometheus 数据源成功的 被 grafana 接入了:

导入监控模板,可在如下链接搜索 https://grafana.com/dashboards?dataSource=prometheus&search=kubernetes

可直接导入 node_exporter.json 监控模板,这个可以把 node 节点指标显示出来

也可直接导入 docker_rev1.json,这个可以把容器资源指标显示 出来,node_exporter.json 和 docker_rev1.json 

怎么导入监控模板,按如下步骤

上面 Save & Test 测试没问题之后,就可以返回 Grafana 主页面

点击左侧+号下面的 Import

选择 Upload json file,上传prometheus-cfg.yaml

选择一个本地的 json 文件,我们选择的是上面让大家下载的 node_exporter.json 这个文件,选择 之后出现如下:

注:箭头标注的地方 Name 后面的名字是 node_exporter.json 定义的

Prometheus 后面需要变成 Prometheus,然后再点击 Import,就可以出现如下界面:

导入 docker_rev1.json 监控模板,步骤和上面导入 node_exporter.json 步骤一样,导入之后显示 如下:

你可能感兴趣的:(Prometheus -1-2)