您好,登錄后才能下訂單哦!
安裝Grafana
$ docker pull grafana/grafana:5.3.4
1、準備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目錄的權限
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、創建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、創建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環境變量中設置的用戶名和密碼登錄
點擊Add data source進入添加數據源界面----數據源名字----數據源類型: Prometheus----url:http://prometheus:9090 ----訪問模式:server
訪問模式是用來控制如何處理對數據源的請求的,分兩種
服務器(Server)訪問模式(默認)
瀏覽器(Browser)訪問模式
導入dashboard:點擊左側加號----import----Grafana.com Dashboard:輸入162
導入配置好的dashboard:點擊左側加號----import----upload .json file----選擇本地文件mydashboard.json
2、安裝k8s插件grafana-kubernetes-app
要安裝這個插件,需要到 grafana 的 Pod 里面去執行安裝命令
$ 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
點擊Installed Apps下面的----kubernetes----enable----點擊鏈接Connect to your Kubernetes Cluster and deploy metric exporters,進入kubernetes / Cluster Config配置界面
未完待續
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。