多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# prometheus-operator 介绍 - 支持自动化方式管理Prometheus和alertmanager - 支持原生配置管理 prometheus-operator集群 [yaml配置文件github管理地址](https://gitee.com/huyipow/prometheus-operator.git) ### prometheus-opeartor 核心组件 **Monitoring infrastructure** - Configuration - Rules - node-exporter - Prometheus - Self upgrading - service: - serviceMonitoring: - prometheus-operator: #### Self hosted Kubernetes - Like self-hosted compiler - Kubernetes components run in Kubernetes - Can be discovered just like anything else - Kubernetes itself is just workload ![image](https://coreos.com/operators/prometheus/docs/latest/user-guides/images/architecture.png) > Note: ServiceMonitor objects must be in the same namespace as the Prometheus object. The fact that your ServiceMonitor now shows up in the config is a good thing. That means it was selected and parsed by the Prometheus Operator. The namespaceSelector is in regard to the Service objects, that a ServiceMonitor selects. Basically the point you are at is: your Prometheus instance is running, your ServiceMonitor is selected, but doesn't select the Service yet that you expect. #### Information available for Pods - **All Pods use resources** CPU, memory, network, disk - **Kubernetes API for metadata** To associate Pods with each other - **Custom metrics are not generic** #### Workload metrics - node-exporter - cAdvisor - [kube-state-metrics ](https://github.com/kubernetes/kube-state-metrics) #### kube-state-metrics - kubectl as metrics - Kubernetes API converted to Prometheus metrics - Cluster state metrics #### What's a target? - HTTP Server with /metrics endpoint - Discovered by an SD mechanism ***Static target list*** ***DNS discovery*** ***Kubernetes discovery*** #### Kubernetes Discovery - Discover targets **Pods** **Nodes** **Endpoints/Sevices** - Automatically reconfigure **Add,update,remove** #### Prometheus for Kubernetes Configuration This guide is intended to give an introduction to all the parts required to start monitoring a Kubernetes cluster with Prometheus using the Prometheus Operator. - [Cluster Monitoring](https://github.com/coreos/prometheus-operator/blob/master/Documentation/user-guides/cluster-monitoring.md) ### prometheus-operator RBAC 权限管理 #### 创建集群角色用户:prometheus-operator cat prometheus-operator-service-account.yaml apiVersion: v1 kind: ServiceAccount metadata: name: prometheus-operator namespace: monitoring #### 创建prometheus-operator 集群角色 cat prometheus-operator-cluster-role.yaml apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole metadata: name: prometheus-operator rules: - apiGroups: - extensions resources: - thirdpartyresources verbs: - "*" - apiGroups: - apiextensions.k8s.io resources: - customresourcedefinitions verbs: - "*" - apiGroups: - monitoring.coreos.com resources: - alertmanagers - prometheuses - servicemonitors verbs: - "*" - apiGroups: - apps resources: - statefulsets verbs: ["*"] - apiGroups: [""] resources: - configmaps - secrets verbs: ["*"] - apiGroups: [""] resources: - pods verbs: ["list", "delete"] - apiGroups: [""] resources: - services - endpoints verbs: ["get", "create", "update"] - apiGroups: [""] resources: - nodes verbs: ["list", "watch"] - apiGroups: [""] resources: - namespaces verbs: ["list"] #### 绑定集群角色 cat prometheus-operator-cluster-role-binding.yaml apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: prometheus-operator roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: prometheus-operator subjects: - kind: ServiceAccount name: prometheus-operator namespace: monitoring #### 部署prometheus-operator # cat prometheus-operator.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: k8s-app: prometheus-operator name: prometheus-operator namespace: monitoring spec: replicas: 1 template: metadata: labels: k8s-app: prometheus-operator spec: containers: - args: - --kubelet-service=kube-system/kubelet - --config-reloader-image=quay.io/coreos/configmap-reload:v0.0.1 image: quay.io/coreos/prometheus-operator:v0.15.0 name: prometheus-operator ports: - containerPort: 8080 name: http resources: limits: cpu: 200m memory: 100Mi requests: cpu: 100m memory: 50Mi serviceAccountName: prometheus-operator #### 部署prometheus-opeartor service cat prometheus-operator-service.yaml apiVersion: v1 kind: Service metadata: name: prometheus-operator namespace: monitoring labels: k8s-app: prometheus-operator spec: type: ClusterIP ports: - name: http port: 8080 targetPort: http protocol: TCP selector: k8s-app: prometheus-operator #### 部署 prometheus-operator-service-monitor cat prometheus-k8s-service-monitor-prometheus-operator.yaml apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: prometheus-operator namespace: monitoring labels: k8s-app: prometheus-operator spec: endpoints: - port: http selector: matchLabels: k8s-app: prometheus-operator