此方法适用于kubeadm集群,controller和scheduler为pod部署

默认情况下prometheus无法获取controller和scheduler的监控数据,原因有两点
1、两个服务的pod没有配置对应的svc
2、controller和scheduler的yaml文件中服务监听地址是127.0.0.1
image

创建svc

kubeControllerManager.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: kube-controller-manager
    app.kubernetes.io/name: kube-controller-manager
    k8s-app: kube-controller-manager
  name: kube-controller-manager
  namespace: kube-system
spec:
  clusterIP: None
  ports:
  - name: https-metrics
    port: 10257
    targetPort: 10257
    protocol: TCP
  selector:
    component: kube-controller-manager

kube-scheduler.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: kube-scheduler
    app.kubernetes.io/name: kube-scheduler
  name: kube-scheduler
  namespace: kube-system
spec:
  clusterIP: None
  ports:
  - name: https-metrics
    port: 10259
    protocol: TCP
    targetPort: 10259
  selector:
    component: kube-scheduler
  sessionAffinity: None
  type: ClusterIP

kubectl apply -f kubeControllerManager.yaml
kubectl apply -f kube-scheduler.yaml

修改bind地址

$ grep bind  /etc/kubernetes/manifests/kube-controller-manager.yaml
    - --bind-address=0.0.0.0
$ grep bind  /etc/kubernetes/manifests/kube-scheduler.yaml
    - --bind-address=0.0.0.0
kubectl apply -f /etc/kubernetes/manifests/kube-controller-manager.yaml
kubectl apply -f /etc/kubernetes/manifests/kube-scheduler.yaml

or

sed -i 's/bind-address=127.0.0.1/bind-address=0.0.0.0/g' /etc/kubernetes/manifests/kube-controller-manager.yaml
sed -i 's/bind-address=127.0.0.1/bind-address=0.0.0.0/g' /etc/kubernetes/manifests/kube-scheduler.yaml
kubectl apply -f /etc/kubernetes/manifests/kube-controller-manager.yaml
kubectl apply -f /etc/kubernetes/manifests/kube-scheduler.yaml

检查监控状态

下次数据采集的时候就会监控到scheduler和controller的数据了
image