prometheus-operator监控集群内和集群外的服务

集群内:

1.应用添加相应metric

2.应用打包docker,配置k8s部署,再k8s里启动应用的pod

3.部署PodMonitor

apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: my-pod-monitor
  namespace: my
spec:
  selector:
    matchLabels:
      app: my       #pod的lable
  namespaceSelector:
    any: true
  podMetricsEndpoints:
  - port: web   #pod的容器里对应的port名字
    path: /metrics

集群外:

1.应用添加相应metric

2.应用在主机上启动

3.部署endpoint

kind: Endpoints
apiVersion: v1
metadata:
  name: my-ep
  namespace: my
  labels:
     app: my
subsets:
  - addresses:
      - ip: 10.10.14.2 # ip为安装应用服务器的ip
    ports:
      - name: metrics
        port: 8000 # 应用的端口

4.部署servicemonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: my-svc-mnt
  namespace: my
spec:
  endpoints:
    - interval: 15s
      port: metrics  #endpoint的port名
  selector: {}

参考

Kubernetes + Prometheus Operator + 自定义Metrics 搭建监控系统 | 四号程序员

prometheus-operator监控集群外的docker服务_katy的小乖的博客-CSDN博客

你可能感兴趣的:(k8s,prometheus,kubernetes,docker)