kube-prometheus-v0.5.0监控kube-controller-manager+kube-scheduler失败

文章目录

  • 0.问题描述
  • 1.问题原因
  • 2.解决
    • 2.1 新建yaml文件
    • 2.2 apply

0.问题描述

搭建完成:Kubernetes-v1.17.4部署kube-prometheus-v0.5.0
发现以下两个系统监控失败:

monitoring/kube-controller-manager/0 (0/0 up)
monitoring/kube-scheduler/0 (0/0 up)
在这里插入图片描述

1.问题原因

[root@manager manifests]# cat prometheus-serviceMonitorKubeScheduler.yaml 
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: kube-scheduler
  name: kube-scheduler
  namespace: monitoring
spec:
  endpoints:
  - interval: 30s
    port: http-metrics
  jobLabel: k8s-app
  namespaceSelector:
    matchNames:
    - kube-system
  selector:
    matchLabels:
      k8s-app: kube-scheduler

selector.matchLabels在kube-system这个命名空间下面匹配具有k8s-app=kube-scheduler这样的Service,但是系统中没有对应的Service

2.解决

2.1 新建yaml文件

cd /opt/kube-prometheus-0.5.0/manifests
vim prometheus-kubeControllerManagerService.yaml

apiVersion: v1
kind: Service
metadata:
  namespace: kube-system
  name: kube-controller-manager
  labels:
    k8s-app: kube-controller-manager
spec:
  ports:
  - name: http-metrics
    port: 10252
    targetPort: 10252
    protocol: TCP

vim prometheus-kubeControllerManagerServiceEnpoints.yaml

apiVersion: v1
kind: Endpoints
metadata:
  labels:
    k8s-app: kube-controller-manager
  name: kube-controller-manager
  namespace: kube-system
subsets:
  - addresses:
      - ip: 10.180.249.245
    ports:
    - name: http-metrics
      port: 10252
      protocol: TCP

vim prometheus-kubeSchedulerService.yaml

apiVersion: v1
kind: Service
metadata:
  namespace: kube-system
  name: kube-scheduler-prometheus-discovery
  labels:
    k8s-app: kube-scheduler
spec:
  ports:
  - name: http-metrics
    port: 10251
    targetPort: 10251
    protocol: TCP

vim prometheus-kubeSchedulerServiceEnpoints.yaml

apiVersion: v1
kind: Endpoints
metadata:
  labels:
    k8s-app: kube-scheduler
  name: kube-scheduler
  namespace: kube-system
subsets:
  - addresses:
      - ip: 10.180.249.245
    ports:
    - name: http-metrics
      port: 10251
      protocol: TCP

2.2 apply

kubectl apply -f prometheus-kubeControllerManagerService.yaml
kubectl apply -f prometheus-kubeControllerManagerServiceEnpoints.yaml
kubectl apply -f prometheus-kubeSchedulerService.yaml
kubectl apply -f prometheus-kubeSchedulerServiceEnpoints.yaml

kube-prometheus-v0.5.0监控kube-controller-manager+kube-scheduler失败_第1张图片

你可能感兴趣的:(Prometheus,Kubernetes)