Operator方式下的Prometheus监控二进制方式部署的kubernetes组件

Operator方式下的Prometheus默认监控的是以静态pod形式部署的kubernetes组件(kubectl,kube-controller-manager,kube-scheduler)
如果需要监控以rpm包或者二进制包方式部署的kubernetes组件,需要做以下改动:
首先是需要有Service, 一般Operator方式下会自动创建,但是都是去匹配pod的endpoints
我们这里没有pod,所以endpoints为
Operator方式下的Prometheus监控二进制方式部署的kubernetes组件_第1张图片
修改已经创建的Service,

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: kube-scheduler
  name: kube-scheduler
  namespace: kube-system
spec:
  clusterIP: None
  ports:
  - name: https-metrics
    port: 10257
    protocol: TCP
    targetPort: 10257
  - name: http-metrics
    port: 10252
    protocol: TCP
    targetPort: 10252
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

仔细观察发现也就是去掉了spec.selector 属性
其次: 由于我们不是静态pod自然endpoint属性也为,所以需要创建endpoint

apiVersion: v1
kind: Endpoints
metadata:
  annotations:
  labels:
    app.kubernetes.io/managed-by: hand-create
    app.kubernetes.io/name: kube-scheduler
    k8s-app: kube-scheduler
    service.kubernetes.io/headless: ""
  name: kube-scheduler
  namespace: kube-system
subsets:
- addresses:
  - ip: 192.100.30.164
    targetRef:
      kind: Node
      name: kubernetesm01
  - ip: 192.100.30.165
    targetRef:
      kind: Node
      name: kubernetesm02
  ports:
  - name: https-metrics
    port: 10259
    protocol: TCP
  - name: http-metrics
    port: 10251
    protocol: TCP

Servervice配置好之后我们就需要创建ServiceMonitor监控了,修改响应的ServiceMonitor对象

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  annotations:
  labels:
    app.kubernetes.io/name: kube-scheduler
    app.kubernetes.io/part-of: kube-prometheus
    app.kubernetes.io/vendor: kubesphere
  name: kube-scheduler
  namespace: kubesphere-monitoring-system
spec:
  endpoints:
  - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
    interval: 1m
    metricRelabelings:
    - action: drop
      regex: scheduler_(e2e_scheduling_latency_microseconds|scheduling_algorithm_predicate_evaluation|scheduling_algorithm_priority_evaluation|scheduling_algorithm_preemption_evaluation|scheduling_algorithm_latency_microseconds|binding_latency_microseconds|scheduling_latency_seconds)
      sourceLabels:
      - __name__
    port: http-metrics
    scheme: http
    tlsConfig:
      insecureSkipVerify: true
  jobLabel: app.kubernetes.io/name
  namespaceSelector:
    matchNames:
    - kube-system
  selector:
    matchLabels:
      app.kubernetes.io/name: kube-scheduler

上面的matchLabels要和创建的Service一致
至此,你就可以在prometheus target中看到你监控的kubernetes系统组件指标了,如果报错connection refused 可能是你的系统组件bind-address设置为127.0.0.1,需要将其改为0.0.0.0 如图:
Operator方式下的Prometheus监控二进制方式部署的kubernetes组件_第2张图片

你可能感兴趣的:(kubernetes,prometheus,容器)