安装部署配置Grafana

WHAT:美观、强大的可视化监控指标展示工具
WHY:用来代替prometheus原生UI界面
# 200机器,准备镜像、资源配置清单:
~]# docker pull grafana/grafana:5.4.2
~]# docker images|grep grafana
~]# docker tag 6f18ddf9e552 harbor.od.com/infra/grafana:v5.4.2
~]# docker push harbor.od.com/infra/grafana:v5.4.2
~]# mkdir /data/k8s-yaml/grafana/ /data/nfs-volume/grafana
~]# cd /data/k8s-yaml/grafana/
grafana]# vi rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  name: grafana
rules:
- apiGroups:
  - "*"
  resources:
  - namespaces
  - deployments
  - pods
  verbs:
  - get
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  name: grafana
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: grafana
subjects:
- kind: User
  name: k8s-node
grafana]# vi dp.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: grafana
    name: grafana
  name: grafana
  namespace: infra
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 7
  selector:
    matchLabels:
      name: grafana
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: grafana
        name: grafana
    spec:
      containers:
      - name: grafana
        image: harbor.od.com/infra/grafana:v5.4.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
          protocol: TCP
        volumeMounts:
        - mountPath: /var/lib/grafana
          name: data
      imagePullSecrets:
      - name: harbor
      securityContext:
        runAsUser: 0
      volumes:
      - nfs:
          server: hdss7-200
          path: /data/nfs-volume/grafana
        name: data
grafana]# vi svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: infra
spec:
  ports:
  - port: 3000
    protocol: TCP
    targetPort: 3000
  selector:
    app: grafana
grafana]# vi ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: grafana
  namespace: infra
spec:
  rules:
  - host: grafana.od.com
    http:
      paths:
      - path: /
        backend:
          serviceName: grafana
          servicePort: 3000

# 11机器,解析域名:
~]# vi /var/named/od.com.zone
serial 前滚一位
grafana            A    10.4.7.10
~]# systemctl restart named
~]# ping grafana.od.com

# 22机器,应用配置清单:
~]# kubectl apply -f http://k8s-yaml.od.com/grafana/rbac.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/grafana/dp.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/grafana/svc.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/grafana/ingress.yaml

grafana.od.com

默认账户和密码都是admin

修改密码:admin123

修改配置,修改如下图

装插件

进入容器

# 第一个:kubenetes App
grafana# grafana-cli plugins install grafana-kubernetes-app
# 第二个:Clock Pannel
grafana# grafana-cli plugins install grafana-clock-panel
# 第三个:Pie Chart
grafana# grafana-cli plugins install grafana-piechart-panel
# 第四个:D3Gauge
grafana# grafana-cli plugins install briangann-gauge-panel
# 第五个:Discrete
grafana# grafana-cli plugins install natel-discrete-panel

装完后,可以在200机器查看

# 200机器:
cd /data/nfs-volume/grafana/plugins/
plugins]# ll

删掉让它重启

重启完成后,查看grafana.od.com,刚刚安装的5个插件都在里面了(记得检查是否在里面了)

添加数据源:Add data source

# 填入参数:
URL:http://prometheus.od.com
TLS Client Auth✔    With CA Cert✔

# 填入参数对应的pem参数:
# 200机器拿ca等:
~]# cat /opt/certs/ca.pem
~]# cat /opt/certs/client.pem
~]# cat /opt/certs/client-key.pem

保存,然后我们去配置plugins里面的kubernetes

右侧就多了个按钮,点击进去

# 按参数填入:
Name:myk8s
URL:https://10.4.7.10:7443
Access:Server
TLS Client Auth✔    With CA Cert✔

# 填入参数:
# 200机器拿ca等:
~]# cat /opt/certs/ca.pem
~]# cat /opt/certs/client.pem
~]# cat /opt/certs/client-key.pem

save后再点击右侧框的图标,并点击Name

可能抓取数据的时间会稍微慢些(两分钟左右)

点击右上角的K8s Cluster,选择你要看的东西

由于K8s Container里面数据不全,如下图

我们改下,把Cluster删了

container也删了

deployment也删了

node也删了

把我给你准备的dashboard的JSON文件import进来

用同样的方法把node、deployment、cluster、container这4个分别import进来

可以都看一下,已经正常了,然后把etcd、generic、traefik也import进来。

还有另外一种import的方法(使用官网的):grafana官网 找一个别人写好的点进去

这个编号可以直接用

如下图,我们装blackbox的编号是9965

把名字和Prometheus修改一下

或者,你也可以用我上传的(我用的是7587)

你可以两个都用,自己做对比,都留着也可以,就是占一些资源。JMX

这个里面还什么都没有

把Dubbo微服务数据弄到Grafana

dubbo-service

# Edit a Daemon Set,添加以下内容,注意给上一行加逗号
  "prometheus_io_scrape": "true",
  "prometheus_io_port": "12346",
  "prometheus_io_path": "/"
# 直接加进去update,会自动对齐,

dubbo-consumer

# Edit a Daemon Set,添加以下内容,注意给上一行加逗号
  "prometheus_io_scrape": "true",
  "prometheus_io_port": "12346",
  "prometheus_io_path": "/"
# 直接加进去update,会自动对齐,

刷新JMX(可能有点慢,我等了1分钟才出来service,我机器不行了)

此时你可以感受到,Grafana明显比K8S自带的UI界面更加人性化

下一节:WHAT: 从 Prometheus server 端接收到 alerts 后,会进行去除重复数据,分组,并路由到对方的接受方式,发出报警。常见的接收方式有:电子邮件,pagerduty 等。
WHY:使得系统的警告随时让我们知道