prometheus和metrucs-server (k8s监控)
资源指标:metrucs-server 自定义指标:prometheus, k8s-prometheus-adapter(转换prometheus数据的格式) 新一代架构: 核心指标流水线:由kubelet、metrics-server以及由API server提供的api组成;CPU累积使用率、内存实时使用率、 Pod的资源占用率及容器的磁盘占用率; 监控流水线:用于从系统收集各种指标数据并提供终端用户、存储系统以及HPA,它们包含核心指标及许多非核心指 标。非核心指标本身不能被k8s所解析, metrics-server:API server #kube-aggregator()
#部署metrucs-server(使用kubectl top)
#1.20.x安装(注意镜像的下载)
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
#github https://github.com/kubernetes-incubator/metrics-server
git clone https://github.com/kubernetes-incubator/metrics-server cd metrics-server
#修改配置文件metrics-server-deployment.yaml vim deploy/1.8+/metrics-server-deployment.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-server
namespace: kube-system
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: metrics-server
namespace: kube-system
labels:
k8s-app: metrics-server
spec:
selector:
matchLabels:
k8s-app: metrics-server
template:
metadata:
name: metrics-server
labels:
k8s-app: metrics-server
spec:
serviceAccountName: metrics-server
volumes:
# mount in tmp so we can safely use from-scratch images and/or read-only containers
- name: tmp-dir
emptyDir: {}
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.3.1
imagePullPolicy: Always
command:
- /metrics-server
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalIP
volumeMounts:
- name: tmp-dir
mountPath: /tmp
#导入文件
kubectl create -f deploy/1.8+/ #查看
##查看 kubectl -n kube-system get pods -l k8s-app=metrics-server kubectl api-versions #使用kube-proxy打开端口8080监听 kubectl proxy --port=8080
#过一会使用kubelet top
[root@k8s-m 1.8+]# curl http://localhost:8080/apis/metrics.k8s.io/v1beta1/nodes { "kind": "NodeMetricsList", "apiVersion": "metrics.k8s.io/v1beta1", "metadata": { "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes" }, "items": [ { "metadata": { "name": "k8s-m", "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/k8s-m", "creationTimestamp": "2019-01-02T08:12:49Z" }, "timestamp": "2019-01-02T08:11:46Z", "window": "30s", "usage": { "cpu": "391134684n", "memory": "1245640Ki" } }, { "metadata": { "name": "node", "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/node", "creationTimestamp": "2019-01-02T08:12:49Z" }, "timestamp": "2019-01-02T08:11:44Z", "window": "30s", "usage": { "cpu": "63170360n", "memory": "962660Ki" } } ] } #使用top [root@k8s-m 1.8+]# kubectl top nodes NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% k8s-m 110m 5% 1216Mi 69% node 61m 3% 941Mi 54% [root@k8s-m 1.8+]# kubectl top pod NAME CPU(cores) MEMORY(bytes) nginx-pod 0m 2Mi
#安装prometheus+Grafana
#下载yaml git clone https://github.com/zhangbin804/k8s.git #导入文件 kubectl create -f node-exporter.yaml kubectl apply -f prometheus/ kubectl apply -f grafana/ #查看30003端口服务 http://宿主机IP:30003/graph
#访问Grafana
[root@k8s-m k8s]# kubectl get svc -n kube-system|grep grafana
grafana NodePort 10.108.93.180 <none> 3000:32094/TCP 23m
#账号和密码都是admin
#添加数据源
#模板导入
模板地址:https://grafana.com/dashboards
#找一个模板下载下来
#导入模板文件
#导入
#查看