Thanos

启用 Thanos - 图1

1. 部署 thanos-sidecar

修改 values.yaml

  1. ## thanos 信息
  2. thanos:
  3. image: quay.io/thanos/thanos:v0.17.2
  4. logLevel: debug
  5. objectStorageConfig: # 后端对象存储服务配置
  6. key: thanos.yaml
  7. name: thanos-objstore-config

添加 objectStorageConfig 配置后,thanos-sidecar 会以 2h 为间隔,将 prometheus 产生的新数据块备份到对象存储中。
注意:开启该配置后,会禁用本地 prometheus 压缩,这意味着 thanos-compactor 是负责在全局对象存储级别上进行压缩的主要单例组件。

部署后结果:

  1. thanos-sidecar:
  2. Args:
  3. sidecar
  4. --prometheus.url=http://127.0.0.1:9090/
  5. --tsdb.path=/prometheus
  6. --grpc-address=[$(POD_IP)]:10901
  7. --http-address=[$(POD_IP)]:10902
  8. --objstore.config=$(OBJSTORE_CONFIG)
  9. --log.level=debug
  10. --log.format=logfmt
  11. State: Running
  12. Started: Fri, 11 Dec 2020 16:03:00 +0800
  13. Ready: True

2. 部署 thanos-ruler

thanos-ruler 可以跨多个 prometheus 实例,处理 recording/alerting 规则。
它需要至少一个 query endpoints,该 endpoint 指向 thanos-querier、prometheus。

  1. ...
  2. apiVersion: monitoring.coreos.com/v1
  3. kind: ThanosRuler
  4. metadata:
  5. name: thanos-ruler-demo
  6. labels:
  7. example: thanos-ruler
  8. namespace: monitoring
  9. spec:
  10. image: quay.io/thanos/thanos
  11. ruleSelector: #select from prometheusrules(CRD)
  12. matchLabels:
  13. role: my-thanos-rules
  14. queryEndpoints:
  15. - dnssrv+_http._tcp.my-thanos-querier.monitoring.svc.cluster.local

3. 部署 thanos-query

deployment 部署 query,并创建 service, servicemonitor:

  1. kubectl apply -f querier-deployment.yaml
  2. kubectl apply -f querier-service.yaml
  3. kubectl apply -f querier-servicemonitor.yaml

访问对应 svc 即可查看 thanos-query 统一控制台。

4. 部署 thanos-store

创建 cm 保存对象存储的详细配置,并以 statefulset 方式安装 store:

  1. kubectl apply -f thanos-stroe.yaml

5. 部署 thanos-compact

①. thanos.yaml

  1. type: s3
  2. config:
  3. bucket: prom-remote-store
  4. endpoint: ${CEPH-RGW-SVC-IP}:${CEPH-RGW-SVC-PORT}

创建 secret,保存后端对象存储服务信息:

  1. kubectl -n monitoring create secret generic thanos-objstore-config --from-file=thanos.yaml

②. thanos-store.yaml

  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4. name: thanos-store
  5. namespace: monitoring
  6. labels:
  7. app: thanos-store
  8. thanos-peer: "true"
  9. spec:
  10. serviceName: "thanos-store"
  11. replicas: 1
  12. selector:
  13. matchLabels:
  14. app: thanos-store
  15. thanos-peer: "true"
  16. template:
  17. metadata:
  18. labels:
  19. app: thanos-store
  20. thanos-peer: "true"
  21. annotations:
  22. prometheus.io/scrape: "true"
  23. prometheus.io/port: "10902"
  24. spec:
  25. containers:
  26. - name: thanos-store
  27. # Always use explicit image tags (release or master-<date>-sha) instead of ambigous `latest` or `master`.
  28. image: quay.io/thanos/thanos:v0.17.2
  29. args:
  30. - "store"
  31. - "--log.level=debug"
  32. - "--data-dir=/var/thanos/store"
  33. - "--objstore.config-file=/config/thanos-store.yml"
  34. ports:
  35. - name: http
  36. containerPort: 10902
  37. - name: grpc
  38. containerPort: 10901
  39. - name: cluster
  40. containerPort: 10900
  41. volumeMounts:
  42. - name: config
  43. mountPath: /config/
  44. readOnly: true
  45. - name: data
  46. mountPath: /var/thanos/store
  47. volumes:
  48. - name: data
  49. emptyDir: {}
  50. - name: config
  51. configMap:
  52. name: thanos-store-config
  53. ---
  54. apiVersion: v1
  55. kind: ConfigMap
  56. metadata:
  57. name: thanos-store-config
  58. namespace: monitoring
  59. data:
  60. thanos-store.yml: |-
  61. type: S3
  62. config:
  63. bucket: prom-remote-store
  64. endpoint: "${CEPH-RGW-SVC-IP}:${CEPH-RGW-SVC-PORT}$():32276"
  65. region: ""
  66. access_key: "A33UKGTXRBGVT12343W0"
  67. insecure: false
  68. signature_version2: false
  69. secret_key: "zgH8BbFsoNyk6xJj6cd435Bbbu1uYhQ3HytvMLza"
  70. put_user_metadata: {}
  71. http_config:
  72. idle_conn_timeout: 1m30s
  73. response_header_timeout: 2m
  74. insecure_skip_verify: false
  75. trace:
  76. enable: false
  77. list_objects_version: ""
  78. part_size: 134217728
  79. sse_config:
  80. type: ""
  81. kms_key_id: ""
  82. kms_encryption_context: {}
  83. encryption_key: ""

④. thanos-query.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: thanos-query
  5. namespace: monitoring
  6. labels:
  7. app: thanos-query
  8. thanos-peers: "true"
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: thanos-query
  14. thanos-peers: "true"
  15. template:
  16. metadata:
  17. labels:
  18. app: thanos-query
  19. thanos-peers: "true"
  20. spec:
  21. containers:
  22. - name: thanos-query
  23. image: quay.io/thanos/thanos:v0.17.2
  24. args:
  25. - "query"
  26. - "--log.level=debug"
  27. - "--store=${PROM-SERVER-POD-IP}:10901"
  28. - "--store=${PROM-SERVER-POD-IP}:10901"
  29. ports:
  30. - name: http
  31. containerPort: 10902
  32. - name: grpc
  33. containerPort: 10901
  34. - name: cluster
  35. containerPort: 10900
  36. ---
  37. apiVersion: v1
  38. kind: Service
  39. metadata:
  40. annotations:
  41. prometheus.io/path: /metrics
  42. prometheus.io/port: "10902"
  43. prometheus.io/scrape: "true"
  44. name: thanos-query
  45. labels:
  46. app: thanos-query
  47. release: prometheus-operator
  48. jobLabel: thanos
  49. namespace: monitoring
  50. spec:
  51. selector:
  52. app: thanos-query
  53. ports:
  54. - port: 9090
  55. protocol: TCP
  56. targetPort: http
  57. name: http-query
  58. ---
  59. apiVersion: monitoring.coreos.com/v1
  60. kind: ServiceMonitor
  61. metadata:
  62. name: prom-thanos-query
  63. namespace: monitoring
  64. labels:
  65. release: prometheus
  66. spec:
  67. jobLabel: jobLabel
  68. selector:
  69. matchLabels:
  70. app: thanos-query
  71. namespaceSelector:
  72. matchNames:
  73. - "monitoring"
  74. endpoints:
  75. - port: http-query
  76. interval: 15s