Kubernetes系列之kubernetes Prometheus Operator

2021-04-02 23:24

阅读:548

  • kube-system
    selector: #这三行是用来匹配我们的service
    matchLabels:
    k8s-app: kubelet
    这里修改完毕后,我们就可以直接创建配置文件

    [root@HUOBAN-K8S-MASTER01 manifests]# kubectl apply -f ./
    namespace/monitoring unchanged
    customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com unchanged
    customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com unchanged
    customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com unchanged
    customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com unchanged
    customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com unchanged
    clusterrole.rbac.authorization.k8s.io/prometheus-operator unchanged
    clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator unchanged
    deployment.apps/prometheus-operator unchanged
    service/prometheus-operator unchanged
    serviceaccount/prometheus-operator unchanged
    servicemonitor.monitoring.coreos.com/prometheus-operator created
    alertmanager.monitoring.coreos.com/main created
    secret/alertmanager-main unchanged
    service/alertmanager-main unchanged
    serviceaccount/alertmanager-main unchanged
    servicemonitor.monitoring.coreos.com/alertmanager created
    secret/grafana-datasources unchanged
    configmap/grafana-dashboard-apiserver unchanged
    configmap/grafana-dashboard-controller-manager unchanged
    configmap/grafana-dashboard-k8s-resources-cluster unchanged
    configmap/grafana-dashboard-k8s-resources-namespace unchanged
    configmap/grafana-dashboard-k8s-resources-node unchanged
    configmap/grafana-dashboard-k8s-resources-pod unchanged
    configmap/grafana-dashboard-k8s-resources-workload unchanged
    configmap/grafana-dashboard-k8s-resources-workloads-namespace unchanged
    configmap/grafana-dashboard-kubelet unchanged
    configmap/grafana-dashboard-node-cluster-rsrc-use unchanged
    configmap/grafana-dashboard-node-rsrc-use unchanged
    configmap/grafana-dashboard-nodes unchanged
    configmap/grafana-dashboard-persistentvolumesusage unchanged
    configmap/grafana-dashboard-pods unchanged
    configmap/grafana-dashboard-prometheus-remote-write unchanged
    configmap/grafana-dashboard-prometheus unchanged
    configmap/grafana-dashboard-proxy unchanged
    configmap/grafana-dashboard-scheduler unchanged
    configmap/grafana-dashboard-statefulset unchanged
    configmap/grafana-dashboards unchanged
    deployment.apps/grafana configured
    service/grafana unchanged
    serviceaccount/grafana unchanged
    servicemonitor.monitoring.coreos.com/grafana created
    clusterrole.rbac.authorization.k8s.io/kube-state-metrics unchanged
    clusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics unchanged
    deployment.apps/kube-state-metrics unchanged
    role.rbac.authorization.k8s.io/kube-state-metrics unchanged
    rolebinding.rbac.authorization.k8s.io/kube-state-metrics unchanged
    service/kube-state-metrics unchanged
    serviceaccount/kube-state-metrics unchanged
    servicemonitor.monitoring.coreos.com/kube-state-metrics created
    clusterrole.rbac.authorization.k8s.io/node-exporter unchanged
    clusterrolebinding.rbac.authorization.k8s.io/node-exporter unchanged
    daemonset.apps/node-exporter configured
    service/node-exporter unchanged
    serviceaccount/node-exporter unchanged
    servicemonitor.monitoring.coreos.com/node-exporter created
    apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io unchanged
    clusterrole.rbac.authorization.k8s.io/prometheus-adapter unchanged
    clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader unchanged
    clusterrolebinding.rbac.authorization.k8s.io/prometheus-adapter unchanged
    clusterrolebinding.rbac.authorization.k8s.io/resource-metrics:system:auth-delegator unchanged
    clusterrole.rbac.authorization.k8s.io/resource-metrics-server-resources unchanged
    configmap/adapter-config unchanged
    deployment.apps/prometheus-adapter configured
    rolebinding.rbac.authorization.k8s.io/resource-metrics-auth-reader unchanged
    service/prometheus-adapter unchanged
    serviceaccount/prometheus-adapter unchanged
    clusterrole.rbac.authorization.k8s.io/prometheus-k8s unchanged
    clusterrolebinding.rbac.authorization.k8s.io/prometheus-k8s unchanged
    prometheus.monitoring.coreos.com/k8s created
    rolebinding.rbac.authorization.k8s.io/prometheus-k8s-config unchanged
    rolebinding.rbac.authorization.k8s.io/prometheus-k8s unchanged
    rolebinding.rbac.authorization.k8s.io/prometheus-k8s unchanged
    rolebinding.rbac.authorization.k8s.io/prometheus-k8s unchanged
    role.rbac.authorization.k8s.io/prometheus-k8s-config unchanged
    role.rbac.authorization.k8s.io/prometheus-k8s unchanged
    role.rbac.authorization.k8s.io/prometheus-k8s unchanged
    role.rbac.authorization.k8s.io/prometheus-k8s unchanged
    prometheusrule.monitoring.coreos.com/prometheus-k8s-rules created
    service/prometheus-k8s unchanged
    serviceaccount/prometheus-k8s unchanged
    servicemonitor.monitoring.coreos.com/prometheus created
    servicemonitor.monitoring.coreos.com/kube-apiserver created
    servicemonitor.monitoring.coreos.com/coredns created
    servicemonitor.monitoring.coreos.com/kube-controller-manager created
    servicemonitor.monitoring.coreos.com/kube-scheduler created
    servicemonitor.monitoring.coreos.com/kubelet created

    当我们部署成功之后,我们可以查看一下crd,yaml文件会自动帮我们创建crd文件。只有我们创建了crd文件,我们的serviceMonitor才会有用

    [root@HUOBAN-K8S-MASTER01 manifests]# kubectl get crd
    NAME CREATED AT
    alertmanagers.monitoring.coreos.com 2019-10-18T08:32:57Z
    podmonitors.monitoring.coreos.com 2019-10-18T08:32:58Z
    prometheuses.monitoring.coreos.com 2019-10-18T08:32:58Z
    prometheusrules.monitoring.coreos.com 2019-10-18T08:32:58Z
    servicemonitors.monitoring.coreos.com 2019-10-18T08:32:59Z

    其他的资源文件都会部署在一个命名空间下面,在monitoring里面是operator Pod对应的列表

    [root@HUOBAN-K8S-MASTER01 manifests]# kubectl get pod -n monitoring
    NAME READY STATUS RESTARTS AGE
    alertmanager-main-0 2/2 Running 0 11m
    alertmanager-main-1 2/2 Running 0 11m
    alertmanager-main-2 2/2 Running 0 11m
    grafana-55488b566f-g2sm9 1/1 Running 0 11m
    kube-state-metrics-ff5cb7949-wq7pb 3/3 Running 0 11m
    node-exporter-6wb5v 2/2 Running 0 11m
    node-exporter-785rf 2/2 Running 0 11m
    node-exporter-7kvkp 2/2 Running 0 11m
    node-exporter-85bnh 2/2 Running 0 11m
    node-exporter-9vxwf 2/2 Running 0 11m
    node-exporter-bvf4r 2/2 Running 0 11m
    node-exporter-j6d2d 2/2 Running 0 11m
    prometheus-adapter-668748ddbd-d8k7f 1/1 Running 0 11m
    prometheus-k8s-0 3/3 Running 1 11m
    prometheus-k8s-1 3/3 Running 1 11m
    prometheus-operator-55b978b89-qpzfk 1/1 Running 0 11m

    其中prometheus和alertmanager采用的StatefulSet,其他的Pod则采用deployment创建

    [root@HUOBAN-K8S-MASTER01 manifests]# kubectl get deployments.apps -n monitoring
    NAME READY UP-TO-DATE AVAILABLE AGE
    grafana 1/1 1 1 12m
    kube-state-metrics 1/1 1 1 12m
    prometheus-adapter 1/1 1 1 12m
    prometheus-operator 1/1 1 1 12m
    [root@HUOBAN-K8S-MASTER01 manifests]# kubectl get statefulsets.apps -n monitoring
    NAME READY AGE
    alertmanager-main 3/3 11m
    prometheus-k8s 2/2 11m


  • 评论


    亲,登录后才可以留言!