部署 kube-state-metrics
https://github.com/kubernetes/kube-state-metrics
Kube-state-metrics : 通过监听 API Server 生成有关资源对象的状态指标,比如 Deploy、node、pod,它只提供metrics数据并不存储,所以我们需要用 Prometheus 抓取这些数据然后存储,主要关注的一些业务相关的元数据,具体举几个例子:
Deployment、Pod、副本状态等,调度了多少replicas? 现在可用的有哪些? 多少个 Pod 是 running/stopped/terminated 状态?Pod 重启了多少次?目前有多少 job 在运行中 等等 …
镜像
https://hub.docker.com/r/bitnami/kube-state-metrics
https://quay.io/repository/coreos/kube-state-metrics?tag=latest&tab=tags
指标
https://xie.infoq.cn/article/9e1fff6306649e65480a96bb1
部署 kube-state-metrics
vim kube-state-metrics-deploy.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| apiVersion: apps/v1 kind: Deployment metadata: name: kube-state-metrics namespace: kube-system spec: replicas: 1 selector: matchLabels: app: kube-state-metrics template: metadata: labels: app: kube-state-metrics spec: serviceAccountName: kube-state-metrics containers: - name: kube-state-metrics image: bitnami/kube-state-metrics:2.2.4 ports: - containerPort: 8080
--- --- apiVersion: v1 kind: ServiceAccount metadata: name: kube-state-metrics namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: kube-state-metrics rules: - apiGroups: [""] resources: ["nodes", "pods", "services", "resourcequotas", "replicationcontrollers", "limitranges", "persistentvolumeclaims", "persistentvolumes", "namespaces", "endpoints"] verbs: ["list", "watch"] - apiGroups: ["extensions"] resources: ["daemonsets", "deployments", "replicasets"] verbs: ["list", "watch"] - apiGroups: ["apps"] resources: ["statefulsets"] verbs: ["list", "watch"] - apiGroups: ["batch"] resources: ["cronjobs", "jobs"] verbs: ["list", "watch"] - apiGroups: ["autoscaling"] resources: ["horizontalpodautoscalers"] verbs: ["list", "watch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: kube-state-metrics roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: kube-state-metrics subjects: - kind: ServiceAccount name: kube-state-metrics namespace: kube-system
--- apiVersion: v1 kind: Service metadata: annotations: prometheus.io/scrape: 'true' name: kube-state-metrics namespace: kube-system labels: app: kube-state-metrics spec: type: NodePort ports: - name: kube-state-metrics port: 8080 targetPort: 8080 nodePort: 31666 protocol: TCP selector: app: kube-state-metrics
|
kubectl create -f kube-state-metrics-deploy.yaml
prometheus 采集数据
vim /apps/prometheus/prometheus.yml
1 2 3
| - job_name: "kube-state-metrics" static_configs: - targets: ["192.168.15.111:31666"]
|
grafana 导入模板
三个选择
- 13332 (自我感觉这个符合我的审美)
- 13824
- 14518