Thanos

1. 部署 thanos-sidecar
修改 values.yaml:
## thanos 信息thanos:image: quay.io/thanos/thanos:v0.17.2logLevel: debugobjectStorageConfig: # 后端对象存储服务配置key: thanos.yamlname: thanos-objstore-config
添加 objectStorageConfig 配置后,thanos-sidecar 会以 2h 为间隔,将 prometheus 产生的新数据块备份到对象存储中。
注意:开启该配置后,会禁用本地 prometheus 压缩,这意味着 thanos-compactor 是负责在全局对象存储级别上进行压缩的主要单例组件。
部署后结果:
thanos-sidecar:Args:sidecar--prometheus.url=http://127.0.0.1:9090/--tsdb.path=/prometheus--grpc-address=[$(POD_IP)]:10901--http-address=[$(POD_IP)]:10902--objstore.config=$(OBJSTORE_CONFIG)--log.level=debug--log.format=logfmtState: RunningStarted: Fri, 11 Dec 2020 16:03:00 +0800Ready: True
2. 部署 thanos-ruler
thanos-ruler 可以跨多个 prometheus 实例,处理 recording/alerting 规则。
它需要至少一个 query endpoints,该 endpoint 指向 thanos-querier、prometheus。
...apiVersion: monitoring.coreos.com/v1kind: ThanosRulermetadata:name: thanos-ruler-demolabels:example: thanos-rulernamespace: monitoringspec:image: quay.io/thanos/thanosruleSelector: #select from prometheusrules(CRD)matchLabels:role: my-thanos-rulesqueryEndpoints:- dnssrv+_http._tcp.my-thanos-querier.monitoring.svc.cluster.local
3. 部署 thanos-query
deployment 部署 query,并创建 service, servicemonitor:
kubectl apply -f querier-deployment.yamlkubectl apply -f querier-service.yamlkubectl apply -f querier-servicemonitor.yaml
访问对应 svc 即可查看 thanos-query 统一控制台。
4. 部署 thanos-store
创建 cm 保存对象存储的详细配置,并以 statefulset 方式安装 store:
kubectl apply -f thanos-stroe.yaml
5. 部署 thanos-compact
①. thanos.yaml
type: s3config:bucket: prom-remote-storeendpoint: ${CEPH-RGW-SVC-IP}:${CEPH-RGW-SVC-PORT}
创建 secret,保存后端对象存储服务信息:
kubectl -n monitoring create secret generic thanos-objstore-config --from-file=thanos.yaml
②. thanos-store.yaml
apiVersion: apps/v1kind: StatefulSetmetadata:name: thanos-storenamespace: monitoringlabels:app: thanos-storethanos-peer: "true"spec:serviceName: "thanos-store"replicas: 1selector:matchLabels:app: thanos-storethanos-peer: "true"template:metadata:labels:app: thanos-storethanos-peer: "true"annotations:prometheus.io/scrape: "true"prometheus.io/port: "10902"spec:containers:- name: thanos-store# Always use explicit image tags (release or master-<date>-sha) instead of ambigous `latest` or `master`.image: quay.io/thanos/thanos:v0.17.2args:- "store"- "--log.level=debug"- "--data-dir=/var/thanos/store"- "--objstore.config-file=/config/thanos-store.yml"ports:- name: httpcontainerPort: 10902- name: grpccontainerPort: 10901- name: clustercontainerPort: 10900volumeMounts:- name: configmountPath: /config/readOnly: true- name: datamountPath: /var/thanos/storevolumes:- name: dataemptyDir: {}- name: configconfigMap:name: thanos-store-config---apiVersion: v1kind: ConfigMapmetadata:name: thanos-store-confignamespace: monitoringdata:thanos-store.yml: |-type: S3config:bucket: prom-remote-storeendpoint: "${CEPH-RGW-SVC-IP}:${CEPH-RGW-SVC-PORT}$():32276"region: ""access_key: "A33UKGTXRBGVT12343W0"insecure: falsesignature_version2: falsesecret_key: "zgH8BbFsoNyk6xJj6cd435Bbbu1uYhQ3HytvMLza"put_user_metadata: {}http_config:idle_conn_timeout: 1m30sresponse_header_timeout: 2minsecure_skip_verify: falsetrace:enable: falselist_objects_version: ""part_size: 134217728sse_config:type: ""kms_key_id: ""kms_encryption_context: {}encryption_key: ""
④. thanos-query.yaml
apiVersion: apps/v1kind: Deploymentmetadata:name: thanos-querynamespace: monitoringlabels:app: thanos-querythanos-peers: "true"spec:replicas: 1selector:matchLabels:app: thanos-querythanos-peers: "true"template:metadata:labels:app: thanos-querythanos-peers: "true"spec:containers:- name: thanos-queryimage: quay.io/thanos/thanos:v0.17.2args:- "query"- "--log.level=debug"- "--store=${PROM-SERVER-POD-IP}:10901"- "--store=${PROM-SERVER-POD-IP}:10901"ports:- name: httpcontainerPort: 10902- name: grpccontainerPort: 10901- name: clustercontainerPort: 10900---apiVersion: v1kind: Servicemetadata:annotations:prometheus.io/path: /metricsprometheus.io/port: "10902"prometheus.io/scrape: "true"name: thanos-querylabels:app: thanos-queryrelease: prometheus-operatorjobLabel: thanosnamespace: monitoringspec:selector:app: thanos-queryports:- port: 9090protocol: TCPtargetPort: httpname: http-query---apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata:name: prom-thanos-querynamespace: monitoringlabels:release: prometheusspec:jobLabel: jobLabelselector:matchLabels:app: thanos-querynamespaceSelector:matchNames:- "monitoring"endpoints:- port: http-queryinterval: 15s
