1. 程式人生 > 其它 >prometheus operator 監控redis-exporter

prometheus operator 監控redis-exporter

建立 redis-exporter  service  

apiVersion: v1
kind: Service
metadata:
  labels:
    app: redis-ec-exporter
    k8s.kuboard.cn/name: redis-ec-exporter
  name: redis-ec-exporter
  namespace: monitoring
spec:
  externalTrafficPolicy: Cluster
  ports:
  - name: wzhxkx
    nodePort: 31107
    port: 9121
    protocol: TCP
    targetPort: 9121
  selector:
    app: redis-ec-exporter
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

  

建立 redis-exporter   deploy 應用 

 

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: redis-ec-exporter
    k8s.kuboard.cn/name: redis-ec-exporter
  name: redis-ec-exporter
  namespace: monitoring
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: redis-ec-exporter
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: redis-ec-exporter
    spec:
      containers:
      - args:
        - -redis.addr
        - redis://redis-ec.test:6379
        image: oliver006/redis_exporter:latest
        imagePullPolicy: Always
        name: redis-ec-exporter
        ports:
        - containerPort: 9121
          name: http
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

  

建立 redis-exporter   servicemonitor 

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: redis-ec-exporter
  name: redis-ec-exporter
  namespace: monitoring
spec:
  endpoints:
  - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
    interval: 15s
    port: wzhxkx
    relabelings:
    - action: replace
      regex: (.*)
      replacement: $1
      sourceLabels:
      - __meta_kubernetes_pod_node_name
      targetLabel: instance
    scheme: http
    tlsConfig:
      insecureSkipVerify: true
  jobLabel: app
  selector:
    matchLabels:
      app: redis-ec-exporter

  

檢視 prometheus target 新增效果: