溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

配置Grafana用于prometheus

發(fā)布時(shí)間:2020-07-23 16:29:44 來源:網(wǎng)絡(luò) 閱讀:573 作者:dongyali521521 欄目:云計(jì)算

安裝Grafana
$ docker pull grafana/grafana:5.3.4
1、準(zhǔn)備pvc

apiVersion: v1
kind: PersistentVolume
metadata:
  name: grafana
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    server: 192.168.1.244
    path: /data/k8s
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana
  namespace: kube-ops
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

2、修改/var/lib/grafana目錄的權(quán)限

apiVersion: batch/v1
kind: Job
metadata:
  name: grafana-chown
  namespace: kube-ops
spec:
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: grafana-chown
        command: ["chown", "-R", "472:472", "/var/lib/grafana"]
        image: busybox
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: storage
          subPath: grafana
          mountPath: /var/lib/grafana
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: grafana

3、創(chuàng)建grafana pod

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: grafana
  namespace: kube-ops
  labels:
    app: grafana
spec:
  revisionHistoryLimit: 10
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
      - name: grafana
        image: grafana/grafana:5.3.4
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
          name: grafana
        env:
        - name: GF_SECURITY_ADMIN_USER
          value: admin         #登錄用戶名
        - name: GF_SECURITY_ADMIN_PASSWORD
          value: admin321        #登錄密碼
        readinessProbe:
          failureThreshold: 10
          httpGet:
            path: /api/health
            port: 3000
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 30
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /api/health
            port: 3000
            scheme: HTTP
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            cpu: 100m
            memory: 256Mi
          requests:
            cpu: 100m
            memory: 256Mi
        volumeMounts:
        - mountPath: /var/lib/grafana
          subPath: grafana
          name: storage
      securityContext:
        fsGroup: 472
        runAsUser: 472
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: grafana

$ kubectl get pod -n kube-ops |grep grafana
grafana-bbfd776d6-w9xf7 1/1 Running 1 111m
grafana-chown-26wmr 0/1 Completed 0 111m
$ kubectl logs grafana-bbfd776d6-w9xf7 -n kube-ops
4、創(chuàng)建svc

apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: kube-ops
  labels:
    app: grafana
spec:
  type: NodePort
  ports:
    - port: 3000
  selector:
    app: grafana

$ kubectl get svc -n kube-ops |grep grafana
grafana NodePort 10.107.208.176 <none> 3000:31171/TCP

使用grafana
1、基本配置
http://192.168.1.243:31171
使用grafana pod環(huán)境變量中設(shè)置的用戶名和密碼登錄
點(diǎn)擊Add data source進(jìn)入添加數(shù)據(jù)源界面----數(shù)據(jù)源名字----數(shù)據(jù)源類型: Prometheus----url:http://prometheus:9090 ----訪問模式:server
訪問模式是用來控制如何處理對(duì)數(shù)據(jù)源的請(qǐng)求的,分兩種
服務(wù)器(Server)訪問模式(默認(rèn))
瀏覽器(Browser)訪問模式
導(dǎo)入dashboard:點(diǎn)擊左側(cè)加號(hào)----import----Grafana.com Dashboard:輸入162
導(dǎo)入配置好的dashboard:點(diǎn)擊左側(cè)加號(hào)----import----upload .json file----選擇本地文件mydashboard.json
2、安裝k8s插件grafana-kubernetes-app
要安裝這個(gè)插件,需要到 grafana 的 Pod 里面去執(zhí)行安裝命令
$ kubectl get pods -n kube-ops |grep grafana
grafana-bbfd776d6-w9xf7 1/1 Running 1
$ kubectl exec -it grafana-bbfd776d6-w9xf7 bash
grafana-kubernetes-app6d6-w9xf7:/usr/share/grafana$ grafana-cli plugins install grafana-kubernetes-app
$ kubectl delete -f grafana-deploy.yaml
$ kubectl apply -f grafana-deploy.yaml
重新打開garfana
http://192.168.1.243:31171
點(diǎn)擊Installed Apps下面的----kubernetes----enable----點(diǎn)擊鏈接Connect to your Kubernetes Cluster and deploy metric exporters,進(jìn)入kubernetes / Cluster Config配置界面

未完待續(xù)

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI