Grafana - k8s环境安装部署grafana,测试正常,推荐使用!
kind: DeploymentapiVersion: apps/v1beta2metadata:labels:app: grafananame: grafananamespace: defaultspec:replicas: 1revisionHistoryLimit: 10selector:matchLabels:app: grafanatemplate:metadata:labels:.
这里有一个小问题,截图中的name默认使Prometheus,我在这里需要改成prometheus,否则在导入dashboard的时候会报错,‘not found the datasource Prometheus’ ;
使用helm chart方式来创建grafana容器,在k8s环境中管理容器更加方便一些。 grafana-deployment.yaml :
首先要先准备好grafana的docker 镜像:
docker search grafana/grafana ##查找公共的grafana docker 镜像
docker pull grafana/grafana ##拉取想要的grafana的镜像版本
docker tag grafana/grafana:latest docker.io/cpro/grafana-grafana:20210223 #将拉取到本地的grafana镜像修改成我们自定义的名字(docker.io/cpro/grafana-grafana:20210223)
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
app: grafana
name: grafana
namespace: default
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
securityContext:
runAsNonRoot: true
runAsUser: 10555
fsGroup: 10555
containers:
- name: grafana
image: docker.io/cpro/grafana-grafana:20210223
imagePullPolicy: IfNotPresent
env:
- name: GF_AUTH_BASIC_ENABLED
value: "true"
- name: GF_AUTH_ANONYMOUS_ENABLED
value: "false"
readinessProbe:
httpGet:
path: /login
port: 3000
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-data-volume
ports:
- containerPort: 3000
protocol: TCP
volumes:
- name: grafana-data-volume
emptyDir: {}
---
kind: Service
apiVersion: v1
metadata:
labels:
app: grafana
name: grafana-service
namespace: default
spec:
ports:
- port: 3000
targetPort: 3000
selector:
app: grafana
type: NodePort
使用kubectl create -f grafana-deployment.yaml创建容器,使用下面命令查看部署的情况;
kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
grafana 1/1 1 1 14m
kubectl get po
NAME READY STATUS RESTARTS AGE
grafana-64c4bc9485-8ztn7 1/1 Running 0 14m
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana-service NodePort 10.254.122.112 <none> 3000:31266/TCP 14m
更多推荐
所有评论(0)