1、部署准备

说明:所有的容器组都运行在monitoring 命名空间
本文参考https://github.com/coreos/kube-prometheus
由于官方维护的版本在现有的部署环境出现问题所以下面做了一些修改及变更不影响整体效果
prometheus-operator 项目使用官方yaml 不做任何修改

2、prometheus-operator相关服务的yaml 准备

2.1、下载官方yaml

mkdir kube-prometheus 
cd kube-prometheus 
git clone https://github.com/coreos/kube-prometheus
cd kube-prometheus/manifests
mkdir prometheus-operator
mv 0*  prometheus-operator

2.2、创建 prometheus-operator 服务及Namespace

cd prometheus-operator
kubectl apply -f .  

2.3 查看prometheus-operator 状态

[root@jenkins prometheus-operator]# kubectl get pod -n monitoring -o wide | grep prometheus-operator    
prometheus-operator-747d7b67dc-vr4rd      1/1     Running   0          35d     10.65.1.135     node02    <none>           <none>
[root@jenkins prometheus-operator]# kubectl get service -n monitoring | grep prometheus-operator  
prometheus-operator       ClusterIP   None            <none>        8080/TCP            35d
http://10.65.1.135:8080/metrics
如果正常打开证明prometheus-operator服务 正常
验证prometheus-operator api 接口是否创建 ServiceMonitor 接口是否正常
[root@jenkins prometheus-operator]# kubectl get ServiceMonitor -n monitoring | grep prometheus-operator             
prometheus-operator       35d
[root@jenkins prometheus-operator]# kubectl api-versions| grep monitoring
monitoring.coreos.com/v1

[root@jenkins prometheus-operator]# kubectl get --raw "/apis/monitoring.coreos.com/v1"|jq .
{
  "kind": "APIResourceList",
  "apiVersion": "v1",
  "groupVersion": "monitoring.coreos.com/v1",
  "resources": [
    {
      "name": "servicemonitors",
      "singularName": "servicemonitor",
      "namespaced": true,
      "kind": "ServiceMonitor",
      "verbs": [
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "create",
        "update",
        "watch"
      ],
      "storageVersionHash": "JLhPcfa+5xE="
    },
    {
      "name": "alertmanagers",
      "singularName": "alertmanager",
      "namespaced": true,
      "kind": "Alertmanager",
      "verbs": [
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "create",
        "update",
        "watch"
      ],
      "storageVersionHash": "NshW3zg1K7o="
    },
    {
      "name": "prometheusrules",
      "singularName": "prometheusrule",
      "namespaced": true,
      "kind": "PrometheusRule",
      "verbs": [
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "create",
        "update",
        "watch"
      ],
      "storageVersionHash": "RSJ8iG+KDOo="
    },
    {
      "name": "prometheuses",
      "singularName": "prometheus",
      "namespaced": true,
      "kind": "Prometheus",
      "verbs": [
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "create",
        "update",
        "watch"
      ],
      "storageVersionHash": "C8naPY4eojU="
    }
  ]
}
kubectl get --raw "/apis/monitoring.coreos.com/v1/servicemonitors"|jq .
查看添加的ServiceMonitor
如果一切正常证明prometheus-operator  部署正常

下一篇: Kubernetes 生产环境安装部署 基于 Kubernetes v1.14.0 之 Alertmanager 部署