当前位置: 首页 > article >正文

15.9 grafana-deployment-yaml讲解

本节重点介绍 :

  • grafana yaml讲解

grafana 需要的pv

  • 对应的路径为 /var/lib/grafana,主要存放的内容有
    • 本地sqlit db存放 grafana.db
    • 本地插件
    • 本地告警截图
  • yaml如下
---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: grafana-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: grafana-storageclass
  local:
    path: /data/grafana
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - k8s-node01

grafana-storageclass

  • WaitForFirstConsumer 延迟挂载
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: grafana-storageclass
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

pvc

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: grafana-storageclass
  resources:
    requests:
      storage: 1Gi

对外暴露服务的nodeport

---
apiVersion: v1
kind: Service
metadata:
  name: grafana-node-port
  labels:
    name: grafana-node-port
spec:
  type: NodePort      #这里代表是NodePort类型的
  ports:
  - port: 80          #这里的端口和clusterIP 对应,即80,供内部访问。
    targetPort: 3000  #端口一定要和container暴露出来的端口对应,nodejs暴露出来的端口是8081,所以这里也应是8081
    protocol: TCP
    nodePort: 30000   # 所有的节点都会开放此端口,此端口供外部调用。
  selector:
    app: grafana           #这里选择器一定要选择容器的标签,之前写name:kube-node是错的。

grafana deployment

---
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:7.5.2
          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
  • 就绪探针使用 /robots.txt
  • 存活探针使用 tcp 3000端口的检测
  • securityContext.fsGroup= 472 表示允许id=472的 用户组使用卷
  • supplementalGroups:0 控制容器可以添加的组 ID

完整的grafana deployment yaml如下

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: grafana-storageclass
  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:7.5.2
          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-node-port
  labels:
    name: grafana-node-port
spec:
  type: NodePort      #这里代表是NodePort类型的
  ports:
  - port: 80          #这里的端口和clusterIP 对应,即80,供内部访问。
    targetPort: 3000  #端口一定要和container暴露出来的端口对应,nodejs暴露出来的端口是8081,所以这里也应是8081
    protocol: TCP
    nodePort: 30000   # 所有的节点都会开放此端口,此端口供外部调用。
  selector:
    app: grafana           #这里选择器一定要选择容器的标签,之前写name:kube-node是错的。
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: grafana-storageclass
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: grafana-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: grafana-storageclass
  local:
    path: /data/grafana
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - k8s-node01


本节重点总结 :

  • grafana yaml讲解

http://www.kler.cn/a/314310.html

相关文章:

  • Unity安装后点击登录没反应
  • 使用 Keras 训练一个卷积神经网络(CNN)(入门篇)
  • 基于微信小程序的乡村研学游平台设计与实现,LW+源码+讲解
  • 【练习案例】30个 CSS Javascript 加载器动画效果
  • 微服务架构面试内容整理-API 网关-Gateway
  • MacOS 本地生成SSH key并关联Github
  • 掌上高考爬虫逆向分析
  • [Python数据可视化]探讨数据可视化的实际应用:三个案例分析
  • lvs-nat模式实验详解
  • 【全网最全】2024年华为杯研赛A题成品论文获取入口(后续会更新)
  • 面试时被问的问题
  • 后台数据管理系统 - 项目架构设计-Vue3+axios+Element-plus(0917)
  • 新版ssh客户端无法连接旧版服务器sshd的方法
  • PHP基础语法入门指南
  • CMake中的PUBLIC、PRIVATE 和 INTERFACE用法
  • C++ | Leetcode C++题解之第423题从英文中重建数字
  • 【CPU】CPU的物理核、逻辑核、超线程判断及L1、L2、L3缓存、CacheLine和CPU的TBL说明
  • vue-入门速通
  • C++_数据结构详解
  • MATLAB入门基础篇
  • 一个安卓鸿蒙化工具
  • SpringBoot环境配置(Spring Boot Profile)
  • sql执行流程经典案例分析
  • 从Profinet到Ethernet IP网关技术重塑工业网络,数据传输更流畅
  • Go语言并发编程中的超时与取消机制解析
  • 基于菜鸟教程的flask学习记录 —— Flask视图函数