发布时间: 2024-11-29 文章作者: myluzh 分类名称: Kubernetes 朗读文章
- job_name: 'k8s-ingress-nginx' kubernetes_sd_configs: - role: pod namespaces: names: - ingress-nginx # 只监控 ingress-nginx 命名空间中的 Pod relabel_configs: - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] action: keep regex: true # 仅保留 prometheus.io/scrape 注解值为 true 的 Pods - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme] action: replace target_label: __scheme__ regex: (https?) - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] action: replace target_label: __metrics_path__ regex: (.+) - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] action: replace target_label: __address__ regex: ([^:]+)(?::\d+)?;(\d+) replacement: $1:$2 - source_labels: [__meta_kubernetes_service_name] regex: prometheus-server action: drop
root@k8s-master:~/prom# kubectl edit daemonset -n ingress-nginx spec: template: metadata: annotations: prometheus.io/path: "/metrics" prometheus.io/port: "10254" prometheus.io/scheme: "http" prometheus.io/scrape: "true"
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: prometheus-k8s-readonly subjects: - kind: ServiceAccount name: prometheus-k8s namespace: monitoring # 指定命名空间为 monitoring roleRef: kind: ClusterRole name: prometheus-k8s-readonly # 绑定的角色 apiGroup: rbac.authorization.k8s.io --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: prometheus-k8s-readonly rules: # 允许访问所有的 API Group 和资源 - apiGroups: ["*"] resources: ["*"] verbs: ["get", "list", "watch"]
标签: ingress-nginx Prometheus monitoring 监控 metrics
发表评论