1 Download deployment

1.1 download


git clone https://github.com/coreos/kube-prometheus.git

The installation files are all in the kube-prometheus/manifests/ Under the table of contents .

Arrangement yaml file ,


mkdir prometheus
cp kube-prometheus/manifests/* prometheus/
cd prometheus/
mkdir -p operator node-exporter alertmanager grafana kube-state-metrics prometheus serviceMonitor adapter
mv *-serviceMonitor* serviceMonitor/
mv grafana-* grafana/
mv kube-state-metrics-* kube-state-metrics/
mv alertmanager-* alertmanager/
mv node-exporter-* node-exporter/
mv prometheus-adapter* adapter/
mv prometheus-* prometheus/

The final directory structure is as follows : setup By default


1.2 Deploy

Create a namespace

kubectl apply -f .



kubectl apply -f setup/

According to the components in turn

kubectl apply -f adapter/
kubectl apply -f alertmanager/
kubectl apply -f node-exporter/
kubectl apply -f kube-state-metrics/
kubectl apply -f grafana/
kubectl apply -f prometheus/
kubectl apply -f serviceMonitor/

View the status of each component

kubectl get all -n monitoring


[[email protected] prometheus]# kubectl get all -n monitoring 
NAME                                       READY   STATUS    RESTARTS   AGE
pod/alertmanager-main-0                    2/2     Running   0          88m
pod/alertmanager-main-1                    2/2     Running   0          88m
pod/alertmanager-main-2                    2/2     Running   0          88m
pod/grafana-86c68fc557-wtb99               1/1     Running   0          170m
pod/kube-state-metrics-584bdcbd9f-wljk6    3/3     Running   0          171m
pod/node-exporter-mmwxl                    2/2     Running   0          113m
pod/node-exporter-mwh5m                    2/2     Running   0          113m
pod/node-exporter-ncx2w                    2/2     Running   0          113m
pod/prometheus-k8s-0                       3/3     Running   1          107m
pod/prometheus-k8s-1                       3/3     Running   1          107m
pod/prometheus-operator-68df4bff8b-wqgg4   2/2     Running   0          144m
NAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/alertmanager-main       ClusterIP           9093/TCP                     95m
service/alertmanager-operated   ClusterIP   None                     9093/TCP,9094/TCP,9094/UDP   88m
service/grafana                 NodePort           3000:32000/TCP               170m
service/kube-state-metrics      ClusterIP   None                     8443/TCP,9443/TCP            171m
service/node-exporter           ClusterIP   None                     9100/TCP                     129m
service/prometheus-k8s          NodePort             9090:31000/TCP               129m
service/prometheus-operated     ClusterIP   None                     9090/TCP                     129m
service/prometheus-operator     ClusterIP   None                     8443/TCP                     174m
NAME                           DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
daemonset.apps/node-exporter   3         3         3       3            3           kubernetes.io/os=linux   113m
NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/grafana               1/1     1            1           170m
deployment.apps/kube-state-metrics    1/1     1            1           171m
deployment.apps/prometheus-operator   1/1     1            1           174m
NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/grafana-86c68fc557               1         1         1       170m
replicaset.apps/kube-state-metrics-584bdcbd9f    1         1         1       171m
replicaset.apps/prometheus-operator-68df4bff8b   1         1         1       174m
NAME                                 READY   AGE
statefulset.apps/alertmanager-main   3/3     88m
statefulset.apps/prometheus-k8s      2/2     129m


2 change service type

In order to facilitate Internet access


kubectl edit service/grafana -n monitoring



kubectl edit service/prometheus-k8s -n monitoring

As shown in the figure below :

3 web Page access

It is found that the two data in the red box have not been collected



terms of settlement :

newly build prometheus-kubeSchedulerService.yaml


apiVersion: v1
kind: Service
  namespace: kube-system
  name: kube-scheduler
    k8s-app: kube-scheduler # And servicemonitor Medium selector matching
    component: kube-scheduler #  And scheduler Of pod Label always
  - name: http-metrics
    port: 10251
    targetPort: 10251
    protocol: TCP


kubectl apply -f prometheus-kubeSchedulerService.yaml

In the same way prometheus-kubeControllerManagerService.yaml


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

4 visit grafnan The username and password are both admin