1. 系统要求
最小化的软硬件要求
最小化硬件要求
- 磁盘空间: 1 GB
- 内存: 750 MiB (approx 750 MB)
- CPU: 250m (approx 2.5 cores)
2. k8s部署grafana步骤
1) 创建名字空间
kubectl create namespace my-grafana
2) 创建yaml
vim grafana.yaml
yaml包含如下三个资源对象
Object | Description |
---|---|
Persistent Volume Claim (PVC) | 存储声明 |
Service | 提供pod的网络访问 |
Deployment | 负责创建pod,并确保可以滚动更新和管理副本集 |
---
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:
fsGroup: 472
supplementalGroups:
- 0
containers:
- name: grafana
image: grafana/grafana:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
name: http-grafana
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /robots.txt
port: 3000
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 2
livenessProbe:
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
3) 执行yaml
这里并没有创建pv,所以要确保有可用的pv使用(至少要有1Gi的pv可用),才可以执行如下的命令
kubectl apply -f grafana.yaml --namespace=my-grafana
4) 查看结果
kubectl get pv,pvc,deployment -n my-grafana
5) 访问grafana
kubectl get svc -n my-grafana
grafana的service采用的是NodePort方式暴露服务,因此可以通过映射的随机端口31483进行访问:
这里k8s部署grafana就算成功了