前置要求与约定

监控作为独立的一部分,如果您选择安装,需要准备额外的资源:

  • 内存: 8G及以上
  • 磁盘: ssd或高速存储介质50G及以上
  • CPU: 2核2线程及以上

安装要求:

基于 prometheus-operator添加了的监控仪表盘。

部署监控组件

监控非平台运行的必要组件,安装监控组件可以查看集群各个服务cpu,内存和网络等状态,便于优化和提高资源利用率。

添加choerodon chart仓库

  1. helm repo add c7n https://openchart.choerodon.com.cn/choerodon/c7n/
  2. helm repo update

创建存储卷(绑定SSD磁盘)

  • 在有SSD磁盘的主机上配置NFS Server

    • 假设SSD磁盘挂载到目录 /ssd
    • 编辑/etc/exports文件添加需要共享目录及参数

      1. /ssd 192.168.1.1/16(rw,sync,insecure,no_subtree_check,no_root_squash)
  • 配置完成后,启动 NFS Server:

    1. sudo systemctl enable nfs-server
    2. sudo systemctl start nfs-server
  • 在可执行helm命令的主机上,使用helm命令安装ssd-nfs-client-provisioner

    1. helm upgrade --install ssd c7n/nfs-client-provisioner \
      --set rbac.create=true \
      --set persistence.enabled=true \
      --set storageClass.name=ssd \
      --set storageClass.provisioner=choerodon.io/ssd-nfs-client-provisioner \
    2. --set persistence.nfsServer=127.0.0.1 \
    1. --set persistence.nfsPath=/ssd \
    1. --version 0.1.1 \
    2. --create-namespace \
    3. --namespace monitoring

    提供NFS服务的主机IP地址或域名

    NFS服务共享的目录

更多详情可参考NFS动态存储卷搭建

安装监控组件

  • 编写参数配置文件 prometheus-operator-value.yaml

    1. grafana:
    2. adminPassword: password
    3. ingress:
    4. enabled: true
    5. hosts:
    6. - grafana.example.choerodon.io
    7. persistence:
    8. enabled: true
    9. storageClassName: ssd
    10. prometheus:
    11. ingress:
    12. enabled: true
    13. hosts:
    14. - prometheus.example.choerodon.io
    15. prometheusSpec:
    16. storageSpec:
    17. volumeClaimTemplate:
    18. spec:
    19. storageClassName: ssd
  • 安装监控

    1. helm upgrade --install prometheus-operator c7n/prometheus-operator \
    2. -f prometheus-operator-value.yaml \
    3. --version 9.3.0 \
    4. --create-namespace \
    5. --namespace monitoring

    下面列出 Prometheus Operator 常用可配置的参数以及默认值,其他配置参考官方文档

    参数描述默认值
    grafana.adminPassword登录grafana UI的管理员密码“prom-operator”
    grafana.defaultDashboardsEnabled部署默认的 dashboards。这些使用 sidecar 加载的true
    grafana.ingress.enabled是否启用 Grafana 的 Ingressfalse
    grafana.ingress.hosts设置 Grafana 的域名[]
    grafana.persistencegrafana 存储定义{}
    grafana.grafana.iniGrafana的配置,需要配置auth.generic_oauth的 oauth2 认证{}
    prometheus.ingress.enabled如果是 ture,创建 Prometheus Ingressfalse
    prometheus.ingress.hostsPrometheus 域名[]
    prometheus.serviceMonitor.relabelings实例收集的 relabel_configs,需要修改 cluster 标签的replacement 为目标集群名
    prometheus.prometheusSpec.storageSpecstorage Spec,用于指定如何使用存储{}
    prometheus.prometheusSpec.additionalScrapeConfigsadditionalScrapeConfigs 允许指定其他 Prometheus 收集配置。收集配置会追加到 Prometheus Operator 生成的配置中。配置必须符合 Prometheus 官方文档中指定的格式。用户有责任确保它的有效性。{}
  • 查看监控

    在浏览器中输入配置的grafana地址即可,更多信息参见此处

常见问题

Helm 创建 crd 失败

将 helm 升级到 2.14 + 可以避免这个问题——由于helm 的 bug,它可能无法正常安装 chart 里面的五个 CRDs,导致安装 chart 失败。如果使用的helm无法升级,你应该安装采取下面的步骤来解决这个问题:为了在解决这个问题必须保证在安装时这五个 CRDS 已经存在,并禁止创建它。

  1. 创建 CRDs

    1. kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml
    2. kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml
    3. kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
    4. kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
    5. kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml
  2. 等待 CRDs 创建完成,这可能需要一些时间。

  3. 安装时禁用 CRDs 创建 prometheusOperator.createCustomResource=false

    1. $ helm install --name my-release c7n/prometheus-operator --set prometheusOperator.createCustomResource=false --version 9.3.0