[英]How to get a pod's labels in Prometheus when pulling the metrics from Kube State Metrics
[英]Is it possible to get pod metrics from prometheus without RBAC?
我有一個 Kubernetes 命名空間,其權限有限,不包括ClusterRole
和ClusterRoleBinding
的創建。 我想在命名空間級別監控資源消耗和 pod 相關指標。
例如,pod 健康和狀態、新 pod 創建、pod 重啟等。
盡管我可以通過公開/metrics
並添加注釋prometheus.io/scrape: 'true'
來為自定義指標創建應用程序級指標端點。
但是有沒有辦法在沒有Cluster Role
和ClusterRoleBinding
的情況下在命名空間級別獲取resource consumption and pod-related metrics
?
可以從 kube-state-metrics 獲取命名空間級別的實體。
拉取kube-state-metrics的helm圖表: https://bitnami.com/stack/kube-state-metrics/helm
編輯 values.yaml 文件並進行以下更改:
rbac: create: false useClusterRole: false collectors: - configmaps - cronjobs - daemonsets - deployments - endpoints - horizontalpodautoscalers - ingresses - jobs - limitranges - networkpolicies - poddisruptionbudgets - pods - replicasets - resourcequotas - services - statefulsets namespace: <current-namespace>
在 prometheus ConfigMap 中,添加一個具有以下配置的作業:
- job_name: 'kube-state-metrics' scrape_interval: 1s scrape_timeout: 500ms static_configs: - targets: ['{{.Values.kube_state_metrics.service.name }}:8080']
創建角色綁定:
apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: kube-state-metrics namespace: <current-namespace> roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: view subjects: - kind: ServiceAccount name: kube-state-metrics namespace: <current-namespace>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.