在過去的文章中,我們花了相當(dāng)大的篇幅來聊關(guān)于監(jiān)控的話題。這是因?yàn)楫?dāng)你正在管理Kubernetes集群時(shí),一切都會(huì)以極快的速度發(fā)生變化。因此有一個(gè)工具來監(jiān)控集群的健康狀態(tài)和資源指標(biāo)極為重要。 在Rancher 2.5中,我們引入了基于Prometheus Operator的新版監(jiān)控,它可以提供Prometheus以及相關(guān)監(jiān)控組件的原生Kubernetes部署和管理。Prometheus Operator可以讓你監(jiān)控集群節(jié)點(diǎn)、Kubernetes組件和應(yīng)用程序工作負(fù)載的狀態(tài)和進(jìn)程。同時(shí),它還能夠通過Prometheus收集的指標(biāo)來定義告警并且創(chuàng)建自定義儀表盤,通過Grafana可以輕松地可視化收集到的指標(biāo)。你可以訪問下列鏈接獲取更多關(guān)于新版監(jiān)控組件的細(xì)節(jié): 新版本站長交易的監(jiān)控也采用prometheus-adapter,開發(fā)人員可以利用其基于自定義指標(biāo)和HPA擴(kuò)展他們的工作負(fù)載。 在本文中,我們將探索如何利用Prometheus Operator來抓取自定義指標(biāo)并利用這些指標(biāo)進(jìn)行高級工作負(fù)載管理。 安裝Prometheus 在Rancher 2.5中安裝Prometheus極為簡單。僅需訪問Cluster Explorer -> Apps并安裝rancher-monitoring即可。 你需要了解以下默認(rèn)設(shè)置: prometheus-adapter將會(huì)作為chart安裝的一部分啟用 ServiceMonitorNamespaceSelector 留為空,允許 Prometheus 在所有命名空間中收集 ServiceMonitors 部署工作負(fù)載 現(xiàn)在讓我們部署一個(gè)從應(yīng)用層暴露自定義指標(biāo)的示例工作負(fù)載。該工作負(fù)載暴露了一個(gè)簡單的應(yīng)用程序,該應(yīng)用程序已經(jīng)使用Prometheus client_golang庫進(jìn)行了檢測,并在/metric端點(diǎn)上提供了一些自定義指標(biāo)。 它有兩個(gè)指標(biāo): http_requests_total http_request_duration_seconds 以下manifest部署了工作負(fù)載、相關(guān)服務(wù)以及訪問該工作負(fù)載的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 |
|