本篇 thanos 部署是基于 prometheus-operator,prometheus-operator 为 thanos 提供了在 CRD 和 controller 上的反对。
sidecar
- 创立 minio 的拜访配置 (s3 协定)
# cat thanos-storage-minio.yaml
type: s3
config:
bucket: thanos
endpoint: minio.minio.svc.cluster.local:9000
access_key: minio
secret_key: minio123
insecure: true
signature_version2: false
创立 secret 保留配置:
$ kubectl create secret generic thanos-objectstorage --from-file=thanos.yaml=thanos-storage-minio.yaml -n monitoring
- 批改 prometheus 的 CRD,减少 thanos 的配置
# vi ../prometheus/prometheus-prometheus.yaml
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
labels:
prometheus: k8s
name: k8s
namespace: monitoring
spec:
...
thanos:
image: thanosio/thanos:v0.18.0
objectStorageConfig:
key: thanos.yaml
name: thanos-objstore-config
更新 CRD:
# kubectl replace -f prometheus-prometheus.yaml
Prometheus-Operator 监听到 CRD 的批改后:
- 为每个 Prometheus Pod 减少 1 个 sidecar container;
- 为 prometheus-operated 这个 svc 减少 1 个 10901 的 grpc 拜访端口;
- thanos 应用的端口统计:
- 10900: cluster-port;
- 10901: grpc;
- 10902: http;
querier
- 部署 querier deployment
因为 querier 组件须要与 sidecar 和 store 组件对接,故 querier 须要配置:
- sidecar 的拜访地址;
- store 的拜访地址;(该配置待 store 组件部署 ok 后再批改)
# cat thanos-querier-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: thanos-querier
namespace: monitoring
labels:
app: thanos-querier
spec:
replicas: 1
selector:
matchLabels:
app: thanos-querier
template:
metadata:
labels:
app: thanos-querier
spec:
containers:
- name: thanos
image: thanosio/thanos:v0.18.0
args:
- "query"
- "--log.level=debug"
- "--query.replica-label=prometheus_replica"
- "--store=dnssrv+prometheus-operated:10901"
ports:
- name: http
containerPort: 10902
- name: grpc
containerPort: 10901
- name: cluster
containerPort: 10900
这里仅配置了 sidecar 的拜访地址:–store=dnssrv+prometheus-operated:10901
- 部署 querier service
querier Service 用 NodePort 将服务裸露进去,能够应用 NodePort 拜访 querier WEB UI 做查问;
# cat thanos-querier-svc.yaml
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/path: /metrics
prometheus.io/port: "10902"
prometheus.io/scrape: "true"
name: thanos-querier
labels:
app: thanos-querier
namespace: monitoring
spec:
selector:
app: thanos-querier
ports:
- port: 9090
targetPort: http
name: http-querier
nodePort: 32700
type: NodePort
裸露的 NodePort=32700,拜访 WEB UI 如下:
拜访“store”菜单,能够看到 querier 对接的存储列表:sidecar 已被辨认
- 创立 querier-ServiceMonitor 将其退出 prometheus 监控
# cat thanos-querier-serviceMonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: thanos-querier
namespace: monitoring
spec:
selector:
matchLabels:
app: thanos-querier
namespaceSelector:
matchNames:
- "monitoring"
endpoints:
- port: http-querier
interval: 15s
serviceMonitor 被创立后,能够在 prometheus WEB UI 的 target 列表中查看: