您好,登录后才能下订单哦!
安装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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。