k8s 中的 Prometheus(指标)

Prometheus in k8s (metrics)

我在 kubernetes 中部署 prometheus this 手册

发明了一种存储方案: kubernetes 中的 Prometeus 在 24 小时内存储指标。 不在 kubernetes 中的 Prometheus 在 1 周内存储指标。 他们之间建立了联盟。

在删除 pods 一段时间后(远少于 24 小时)指标丢失的事实。

如果您没有为您的 prometheus pod 配置持久存储,这是完全正常的。你应该使用 PV/PVC 来定义一个稳定的地方来保存你的普罗米修斯数据,否则如果你的 pod 被重新创建,它会从一个干净的平板开始。

PV/PVC 需要集群中的专用存储服务器。如果没钱买存储服务器,这里有一个更便宜的方法:

  1. 标记一个节点:

    $ kubectl label nodes <node name> prometheus=yes
    
  2. 使用 nodeSelector:

    强制在同一个标​​签节点上创建所有 prometheus pods
    nodeSelector:
        prometheus: yes
    
  3. 为每个 prometheus pod 创建一个 emptyDir 卷。 emptyDir 卷在 Prometheus pod 分配给标记节点时首先创建,只要该 pod 在该节点上 运行ning 就存在,并且在容器崩溃和 pod 重新启动时是安全的。

    spec:
      containers:
      - image: <prometheus image>
        name: <prometheus  pod name>
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}
    

这种方法使所有 Prometheus pods 运行 都在同一个节点上,并为指标提供持久存储 - 一种更便宜的方法,希望 Prometheus 节点不会崩溃。