首页 > 其他分享 >15.7 创建prometheus的statsfulset配置

15.7 创建prometheus的statsfulset配置

时间:2024-09-24 14:26:15浏览次数:3  
标签:name etc -- 15.7 statsfulset prometheus 设置 config


本节重点介绍 : prometheus statsfulset yaml配置

  • 设置statsfulset副本反亲和性
  • 设置pod运行优先级
  • 设置volumeClaimTemplates
  • 设置配置文件热更新容器 configmap-reload
  • 设置prometheus主容器

statsfulset

设置元信息

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: prometheus
  namespace: kube-system
  labels:
    k8s-app: prometheus
    kubernetes.io/cluster-service: "true"

设置定义标签和标签选择器

spec:
  serviceName: "prometheus"
  podManagementPolicy: "Parallel"
  replicas: 1
  selector:
    matchLabels:
      k8s-app: prometheus
  template:
    metadata:
      labels:
        k8s-app: prometheus
    
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''

设置副本反亲和性

  • spec.template.spec.affinity
  • 多个statsfulset副本不要调度到同一个节点上

spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: k8s-app
                operator: In
                values:
                - prometheus
            topologyKey: "kubernetes.io/hostname"

设置为 Pod 提供的卷 volumes

  • spec.template.spec.volumes
  • 挂载etcd证书和配置文件
volumes:
        - name: config-volume
          configMap:
            name: prometheus-config
        - name: secret-volume
          secret:
            secretName: etcd-certs

关键插件 Pod 的调度保证 priorityClassName

  • 设置如下
priorityClassName: system-cluster-critical
  • priorityClassName设置pod 的优先级
  • system-cluster-critical代表将 pod 标记为关键性(critical)
  • 这样设置可以 使当Pod 无法被调度,调度程序会尝试抢占(驱逐)较低优先级的 Pod, 以使悬决 Pod 可以被调度。.

为了访问prometheus更方便,设置主机网络

hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
  • 代表prometheus可以使用和主机一样的网络
  • 同时设置 dns策略为 hostNetwork

设置serviceAccountName

serviceAccountName: prometheus

设置volumeClaimTemplates

volumeClaimTemplates:
    - metadata:
        name: prometheus-data
      spec:
        accessModes: [ "ReadWriteOnce" ]
        storageClassName: "prometheus-lpv"
        resources:
          requests:
            storage: 5Gi

设置第一个容器 prometheus-server-configmap-reload

  • configmap-reload项目地址
  • 它监视已安装的卷目录并通知目标进程配置的configmap已更改,然后发送http请求
  • 我们使用它来做prometheus热更新配置
containers:
      - name: prometheus-server-configmap-reload
        image: "jimmidyson/configmap-reload:v0.4.0"
        imagePullPolicy: "IfNotPresent"
        args:
          - --volume-dir=/etc/config
          - --webhook-url=http://localhost:8091/-/reload
        volumeMounts:
          - name: config-volume
            mountPath: /etc/config
            readOnly: true
        resources:
          limits:
            cpu: 10m
            memory: 10Mi
          requests:
            cpu: 10m
            memory: 10Mi
  • imagePullPolicy=IfNotPresent代表 镜像不存在时再拉取
  • args代表启动的命令行参数
  • volumeMounts代表 声明卷在容器中的挂载位置
  • resources代表cpu内存资源情况
  • requests请求量
  • limits限制量

设置第二个容器 prometheus

- image: prom/prometheus:v2.29.1
        imagePullPolicy: IfNotPresent
        name: prometheus
        command:
          - "/bin/prometheus"
        args:
          - "--config.file=/etc/prometheus/prometheus.yml"
          - "--storage.tsdb.path=/prometheus"
          - "--storage.tsdb.retention=24h"
          - "--web.console.libraries=/etc/prometheus/console_libraries"
          - "--web.console.templates=/etc/prometheus/consoles"
          - "--web.enable-lifecycle"
          - "--web.listen-address=0.0.0.0:8091"
        ports:
          - containerPort: 8091
            protocol: TCP
        volumeMounts:
          - mountPath: "/prometheus"
            name: prometheus-data
          - mountPath: "/etc/prometheus"
            name: config-volume
          - name: secret-volume
            mountPath: "/etc/prometheus/secrets/etcd-certs"
            #readOnly: true
        readinessProbe:
          httpGet:
            path: /-/ready
            port: 8091
          initialDelaySeconds: 30
          timeoutSeconds: 30
        livenessProbe:
          httpGet:
            path: /-/healthy
            port: 8091
          initialDelaySeconds: 30
          timeoutSeconds: 30
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 1000m
            memory: 2500Mi
        securityContext:
            runAsUser: 65534
            privileged: true

readinessProbe 就绪探针

  • kubelet 使用就绪探测器可以知道容器什么时候准备好了并可以开始接受请求流量
  • 当一个 Pod 内的所有容器都准备好了,才能把这个 Pod 看作就绪了
  • 这种信号的一个用途就是控制哪个 Pod 作为 Service 的后端
  • 在 Pod 还没有准备好的时候,会从 Service 的负载均衡器中被剔除的。

livenessProbe 存活探针

  • kubelet 使用存活探测器来知道什么时候要重启容器
  • 例如,存活探测器可以捕捉到死锁(应用程序在运行,但是无法继续执行后面的步骤)
  • 这样的情况下重启容器有助于让应用程序在有问题的情况下更可用。

securityContext 为 Pod 或容器配置安全性上下文

  • runAsUser 以特定user运行容器
  • privileged 运行特权容器

全部的配置 写入 statsfulset.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: prometheus
  namespace: kube-system
  labels:
    k8s-app: prometheus
    kubernetes.io/cluster-service: "true"
spec:
  serviceName: "prometheus"
  podManagementPolicy: "Parallel"
  replicas: 1
  selector:
    matchLabels:
      k8s-app: prometheus
  template:
    metadata:
      labels:
        k8s-app: prometheus
      
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: k8s-app
                operator: In
                values:
                - prometheus
            topologyKey: "kubernetes.io/hostname"
      priorityClassName: system-cluster-critical
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      containers:
      - name: prometheus-server-configmap-reload
        image: "jimmidyson/configmap-reload:v0.4.0"
        imagePullPolicy: "IfNotPresent"
        args:
          - --volume-dir=/etc/config
          - --webhook-url=http://localhost:8091/-/reload
        volumeMounts:
          - name: config-volume
            mountPath: /etc/config
            readOnly: true
        resources:
          limits:
            cpu: 10m
            memory: 10Mi
          requests:
            cpu: 10m
            memory: 10Mi
      - image: prom/prometheus:v2.29.1
        imagePullPolicy: IfNotPresent
        name: prometheus
        command:
          - "/bin/prometheus"
        args:
          - "--config.file=/etc/prometheus/prometheus.yml"
          - "--storage.tsdb.path=/prometheus"
          - "--storage.tsdb.retention=24h"
          - "--web.console.libraries=/etc/prometheus/console_libraries"
          - "--web.console.templates=/etc/prometheus/consoles"
          - "--web.enable-lifecycle"
          - "--web.listen-address=0.0.0.0:8091"
        ports:
          - containerPort: 8091
            protocol: TCP
        volumeMounts:
          - mountPath: "/prometheus"
            name: prometheus-data
          - mountPath: "/etc/prometheus"
            name: config-volume
          - name: secret-volume
            mountPath: "/etc/prometheus/secrets/etcd-certs"
            #readOnly: true
        readinessProbe:
          httpGet:
            path: /-/ready
            port: 8091
          initialDelaySeconds: 30
          timeoutSeconds: 30
        livenessProbe:
          httpGet:
            path: /-/healthy
            port: 8091
          initialDelaySeconds: 30
          timeoutSeconds: 30
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 1000m
            memory: 2500Mi
        securityContext:
            runAsUser: 65534
            privileged: true
      serviceAccountName: prometheus
      volumes:
        - name: config-volume
          configMap:
            name: prometheus-config
        - name: secret-volume
          secret:
            secretName: etcd-certs   
  volumeClaimTemplates:
    - metadata:
        name: prometheus-data
      spec:
        accessModes: [ "ReadWriteOnce" ]
        storageClassName: "prometheus-lpv"
        resources:
          requests:
            storage: 5Gi

本节重点总结 : prometheus statsfulset yaml配置

  • 设置statsfulset副本反亲和性
  • 设置pod运行优先级
  • 设置volumeClaimTemplates
  • 设置配置文件热更新容器 configmap-reload
  • 设置prometheus主容器


标签:name,etc,--,15.7,statsfulset,prometheus,设置,config
From: https://blog.51cto.com/moonfdd/12099426

相关文章

  • 15.6 创建prometheus使用的配置configmap
    本节重点介绍:config简介prometheusconfigmap编写configmap作用ConfigMap是一种API对象,用来将非机密性的数据保存到键值对中使用时,Pods可以将其用作环境变量、命令行参数或者存储卷中的配置文件。为何prometheus需要configmapprometheus的配置文件需要以configmap形式挂载编......
  • prometheus学习笔记之PushGateway
    一、pushgateway简介pushgateway是采用被动推送的方式,而不是类似于prometheusserver主动连接exporter获取监控数据。pushgateway可以单独运行在一个节点,然后需要自定义监控脚本把需要监控的主动推送给pushgateway的API接口,然后pushgateway再等待prometheusser......
  • Python实战:为Prometheus开发自定义Exporter
    Python实战:为Prometheus开发自定义Exporter在当今的微服务架构和容器化部署环境中,监控系统的重要性不言而喻。Prometheus作为一款开源的系统监控和警报工具,以其强大的功能和灵活性受到了广泛的欢迎。然而,Prometheus本身并不直接监控所有类型的服务或应用,这就需要我们为其开发自定......
  • 搭建基于Grafana+Prometheus+Nvidia_gpu_exploter的GPU监控平台
    搭建基于Grafana+Prometheus+Nvidia_gpu_exploter的英伟达GPU监控平台在现代数据科学和机器学习领域,GPU已成为不可或缺的硬件资源。为了高效管理和监控GPU的使用情况,构建一个实时、直观的监控系统变得尤为重要。本文将详细介绍如何使用Grafana、Prometheus以及Nvidia_gpu_explote......
  • ​​Prometheus监控之服务发现
    1.Prometheus服务发现1.1为什么需要服务发现Prometheus采⽤Pull模型来抓取⽬标主机的指标数据,这就意味着Prometheus必须事先知道每个要监控的⽬标的端点地址。然后才能从对应的Exporter或Instrumentation进⾏数据抓取。对于规模较⼩,且监控的⽬标不会频繁的发⽣变动,直接使⽤但......
  • Prometheus 监控系统
    目录1.Prometheus概述(1)TSDB作为Prometheus的存储引擎完美契合了监控数据的应用场景(2)Prometheus的特点(3)Prometheus的主要组件(1)prometheusserver(2)exporter(3)alertmanager(4)pushgateway(5)grafana(4)Prometheus的局限性2.Zabbix和Prometheus的区别?如何选择?(1)Zabbix(2)Prometheus3.Prome......
  • prometheus学习笔记之alertmanager告警配置
    一、安装alertmanager项目地址:https://github.com/prometheus/alertmanager帮助文档:https://prometheus.io/docs/alerting/latest/alertmanager/配置文档:https://prometheus.io/docs/alerting/latest/configuration/wgethttps://github.com/prometheus/alertmanager/release......
  • 基于Prometheus和Grafana的现代服务器监控体系构建
    引言随着云计算和微服务架构的迅速发展,服务器监控已成为保障系统稳定性和性能的重要手段。Prometheus和Grafana作为两个非常受欢迎的开源项目,为构建现代监控体系提供了强有力的支持。本文将详细探讨如何使用Prometheus和Grafana构建现代服务器监控体系,并结合实际案例进行技术......
  • 云原生周刊:Prometheus 3.0 Beta 发布|2024.09.16
    开源项目推荐KumaKuma是一个现代化的基于Envoy的服务网格,能够在每个云平台上运行,支持单区域或多区域部署,兼容Kubernetes和虚拟机。凭借其广泛的通用工作负载支持,以及对Envoy数据平面代理技术的原生支持(但无需Envoy专业知识),Kuma提供了现代化的L4-L7服务连接、发现、......
  • Prometheus修改数据存储位置
    Prometheus修改数据存储位置Prometheus的数据存储位置可以通过配置文件中的--storage.tsdb.path参数来指定。默认情况下,数据存储在Prometheus安装目录下的data文件夹中。要修改数据存储位置,可以在Prometheus启动命令中添加或修改该参数。步骤1:修改Prometheus启动命令接......