美文网首页
Grafana on Kubernetes

Grafana on Kubernetes

作者: 林高山野 | 来源:发表于2023-01-25 21:32 被阅读0次

参考资料Grafana on kubernetes

前置条件:nfs已准备就绪,参考:K8S通过NFS实现共享存储

1、定义grafana-pv.yml

apiVersion:  v1
kind:  PersistentVolume
metadata:
  name:  grafana-pv
  labels:
    pv: grafana-pv
spec:
  capacity:
    storage:  2Gi
  accessModes:
   - ReadWriteOnce
  persistentVolumeReclaimPolicy:  Recycle
  storageClassName:  nfs
  nfs:
    path:  /data/k8s/grafana-pv
    server:  192.168.1.20

2、创建 grafana.yml

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName:  nfs
  selector:
    matchLabels:
      pv:  grafana-pv
---
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、拷贝grafana-pv.yml 和 grafana.yml 到master节点

4、执行以下命令

#kubectl apply -f grafana-pv.yml
#kubectl apply -f grafana.yml

5、检查服务状态

[root@bigdata02 soft]# kubectl get service
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
grafana      LoadBalancer   10.109.168.172   <pending>     3000:30989/TCP   48m
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP          5h27m
[root@bigdata02 soft]# kubectl get pod
NAME                       READY   STATUS    RESTARTS   AGE
grafana-5f986967b4-g8ksf   1/1     Running   0          19m
[root@bigdata02 soft]# 

6、Navigate to localhost:30989 in your browser. You should see a Grafana login page.

相关文章

网友评论

      本文标题:Grafana on Kubernetes

      本文链接:https://www.haomeiwen.com/subject/nbdjhdtx.html