kube-prometheus+kube-thanos

背景

最近在做监控,选择了thanos架构,使用了kube-prometheus+kube-thanos,这里记录一下搭建过程。

原理

在这里插入图片描述
我选择的是sidecar的方式,这张图画的很好,thanos就理解为多个prometheus的汇合点,当一个query发到thanos后,一部分会从thanos的store查询,另一部分从每个prometheus查询,其中每个prometheus多了一个sidecar,sidecar主要就是把本地的prometheus数据上传到thanos store,另外也充当了一个网关的功能。

环境介绍

本次我是打算用两个集群来搭建,一个集群安装thanos,另外一个集群安装prometheus,这个也符合真实的生产环境。当然你只是为了学习做实验也可以都放在一个集群内。

安装thanos

搭建thanos就直接选择kube-thanos,选择在cluster A搭建。

1安装minio

kube-thanos/examples/development-minio这个目录下官方提供了一个minio的deploy直接部署

2安装thanos

kube-thanos/manifests这个文件就是thanos的所有安装文件,kubectl apply -f 一下。
现在thanos就安装好了,你可以把minio的svc改成nodeport暴露出来,把thanos-query也暴露出来。

3安装grafana

安装grafana选择用kube-prometheus修改一下kube-prometheus/manifests下的grafana-dashboardDatasources.yaml添加datasource

            {
                "access": "proxy",
                "editable": false,
                "name": "thanos",
                "orgId": 1,
                "type": "prometheus",
                "url": "http://thanos-query.thanos.svc.cluster.local:9090",
                "version": 1
            }

kubectl apply -f kube-prometheus/manifests 中的所有grafana开头的文件,这里只安装grafana,然后将grafana的svc改为nodeport。

安装prometheus

1安装prometheus

现在开始在cluster B集群安装prometheus,还是选择用kube-prometheus来安装,kubectl apply -f kube-prometheus/manifests 中的所有不是grafana开头的文件,原因是这个集群不需要安装grafana

2配置minio

因为之前说过,sidecar需要把prometheus本地的数据上传到minio中去,所以肯定是需要配置一个包含minio连接信息的secret

apiVersion: v1
kind: Secret
metadata:
  name: thanos-objectstorage
  namespace: monitoring
stringData:
  thanos.yaml: |
    type: s3
    config:
      bucket: thanos
      endpoint: minio的地址
      insecure: true
      access_key: minio
      secret_key: minio123
type: Opaque

修改其中的minio的地址,这个地址就是cluster A的暴露出来的minio的地址,如果你只是做实验,都安装在一个集群内了地址就是minio.thanos.svc.cluster.local:9000

2配置sidecar

修改prometheus-prometheus.yaml

2.1添加sidecar配置
  thanos:
    baseImage: quay.io/thanos/thanos:v0.30.2
    version: v0.30.2
    objectStorageConfig:
      key: thanos.yaml
      name: thanos-objectstorage
2.2添加sidecar配置

修改externalLabels: {},修改这个的原因是为了知道数据属于哪个集群,因为thanos提供了统一的查询入口,需要通过一些标签做筛选,我这里写的就是externalLabels: {clusterId: A}.

3配置endpoints

如果一切正常,此时你就需要最后一步了,回到cluster A,修改一下thanos-query-deployment.yaml,这一步的原因是为了让thanos知道cluster B的prometheus的地址,这样thanos在查询的时候就会到cluster B的prometheus来查询了,这个地址是cluster B中prometheus-operator svc的地址,我这里是把它改成了nodeport。

  - --endpoint=172.0.5.23:10901```

如果你是做实验都在一个集群内就是

  - --endpoint=dnssrv+_grpc._tcp.prometheus-operated.monitoring.svc.cluster.local:10901```

总结

如果一切正常你就可以在grafana看到如下的数据了
在这里插入图片描述
参考:
https://ost.51cto.com/posts/12545
https://mp.weixin.qq.com/s/ImUAfXEY1sdvGc6IgmF8IQ

  • 19
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值