在过去的文章中,我们花了相当大的篇幅来聊关于监控的话题。这是因为当你正在管理Kubernetes集群时,一切都会以极快的速度发生变化。因此有一个工具来监控集群的健康状态和资源指标极为重要。 在Rancher 2.5中,我们引入了基于Prometheus Operator的新版监控,它可以提供Prometheus以及相关监控组件的原生Kubernetes部署和管理。Prometheus Operator可以让你监控集群节点、Kubernetes组件和应用程序工作负载的状态和进程。同时,它还能够通过Prometheus收集的指标来定义告警并且创建自定义仪表盘,通过Grafana可以轻松地可视化收集到的指标。你可以访问下列链接获取更多关于新版监控组件的细节: 新版本站长交易的监控也采用prometheus-adapter,开发人员可以利用其基于自定义指标和HPA扩展他们的工作负载。 在本文中,我们将探索如何利用Prometheus Operator来抓取自定义指标并利用这些指标进行高级工作负载管理。 安装Prometheus 在Rancher 2.5中安装Prometheus极为简单。仅需访问Cluster Explorer -> Apps并安装rancher-monitoring即可。 你需要了解以下默认设置: prometheus-adapter将会作为chart安装的一部分启用 ServiceMonitorNamespaceSelector 留为空,允许 Prometheus 在所有命名空间中收集 ServiceMonitors 部署工作负载 现在让我们部署一个从应用层暴露自定义指标的示例工作负载。该工作负载暴露了一个简单的应用程序,该应用程序已经使用Prometheus client_golang库进行了检测,并在/metric端点上提供了一些自定义指标。 它有两个指标: http_requests_total http_request_duration_seconds 以下manifest部署了工作负载、相关服务以及访问该工作负载的ingress: apiVersion: apps/v1kind: Deploymentmetadata: labels: app.kubernetes.io/name: prometheus-example-app name: prometheus-example-appspec: replicas: 1 selector: matchLabels: app.kubernetes.io/name: prometheus-example-app template: metadata: labels: app.kubernetes.io/name: prometheus-example-app spec: containers: - name: prometheus-example-app image: gmehta3/demo-app:metrics ports: - name: web containerPort: 8080---apiVersion: v1kind: Servicemetadata: name: prometheus-example-app labels: app.kubernetes.io/name: prometheus-example-appspec: selector: app.kubernetes.io/name: prometheus-example-app ports: - protocol: TCP port: 8080 targetPort: 8080 name: web---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata: name: prometheus-example-appspec: rules: - host: hpa.demo http: paths: - path: / backend: serviceName: prometheus-example-app servicePort: 8080 |
|