参考grafana官网文档:https://grafana.com/docs/grafana/latest/installation/?pg=docs
环境准备
- k8s集群
- k8s持久化存储卷1Gi(基于云存储)
安装
- 编写yml文件:
grafana.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: grafana-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grafana
name: grafana
spec:
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
securityContext: #pod安全策略
fsGroup: 472
supplementalGroups:
- 0
containers:
- name: grafana
image: grafana/grafana:7.5.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
name: http-grafana
protocol: TCP
readinessProbe: #pod就绪探针
failureThreshold: 3
httpGet:
path: /robots.txt
port: 3000
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 2
livenessProbe: #pod存活探针
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 3000
timeoutSeconds: 1
resources:
requests:
cpu: 250m
memory: 750Mi
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-pv
volumes:
- name: grafana-pv
persistentVolumeClaim:
claimName: grafana-pvc
---
apiVersion: v1
kind: Service
metadata:
name: grafana
spec:
ports:
- port: 3000
protocol: TCP
targetPort: http-grafana
selector:
app: grafana
sessionAffinity: None
type: LoadBalancer
grafana的数据目录:
/var/lib/grafana
,用于存储其数据库、用户、dashboard,所以创建了pvc挂载用于持久化。
不做持久化,当容器重启时前面的数据丢失。
- k8s部署
2.1 安装应用
kubectl apply -f grafana.yaml
2.2 本地端口映射
kubectl port-forward service/grafana 3000:3000
2.3 浏览器访问:localhost:3000
2.4 使用默认账号admin
登录,密码同账号名
总结
- 仅做记录,后续备查。来源于官网文档,里面配的登录账号都是默认的,安全性较弱。
账号密码的配置,可使用k8s的secret,然后挂载到pod的环境变量。
关于容器的配置参考:
https://grafana.com/docs/grafana/latest/administration/configure-docker/
- 关于granafa的配置、环境变量的配置,参考文档:
https://grafana.com/docs/grafana/latest/administration/configuration/