Kubernetes(1.30) 监控

安装Metrics Server

下载配置文件https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

增加启动参数--kubelet-insecure-tls

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
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
selector:
matchLabels:
k8s-app: metrics-server
strategy:
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
k8s-app: metrics-server
spec:
containers:
- args:
- --cert-dir=/tmp
- --secure-port=10250
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --kubelet-use-node-status-port
- --metric-resolution=15s
- --kubelet-insecure-tls
image: registry.k8s.io/metrics-server/metrics-server:v0.7.2

运行配置。

1
kubectl apply -f components.yaml

等待十几分钟之后,CPU和Memory的使用就可以查看到了。

但是metrics server一般只是用来做弹性扩容使用,如果需要监控并且保存历史数据,还是需要使用Prometheus。

安装Prometheus Operator

参考prometheus-operator/kube-prometheus

## Reference

>[Installing Prometheus Operator](https://prometheus-operator.dev/docs/getting-started/installation/)
>[How to monitor Kubernetes clusters with the Prometheus Operator](https://grafana.com/blog/2023/01/19/how-to-monitor-kubernetes-clusters-with-the-prometheus-operator/)