k8s集群资源监控Metrics Server & cAdvisor

Metrics Server + cAdvisor 监控集群资源消耗

Metrics Server 是一个集群范围内资源使用情况的数据聚合器;作为一个应用部署在集群中,Metrics Server 从每个节点上的kubelet API-Server收集指标,通过k8s聚合器注册在Master APIServer中;

资源地址:

chait@k8s-master01:~$ kubectl top
Display Resource (CPU/Memory/Storage) usage.

 The top command allows you to see the resource consumption for nodes or pods.

 This command requires Metrics Server to be correctly configured and working on the server.

Available Commands:
  node        Display Resource (CPU/Memory/Storage) usage of nodes
  pod         Display Resource (CPU/Memory/Storage) usage of pods

Usage:
  kubectl top [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
chait@k8s-master01:~$
  • 查看集群资源消耗信息=》# kubectl top [flags] [options]

安装metrics-server

直接使用命令【kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml】安装可能会失败,受限于网络原因;

 可以分步执行:

  • 下载yaml资源=》# wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
  • 修改yaml资源名称=》# sudo mv components.yaml metrics-server.yaml
  • 查看yaml信息 =》# vim metrics-server.yaml
  • 修改yaml镜像地址=》如下图标记位置(args 参数 & image 镜像)添加参数和修改镜像访问地址,可以先把镜像资源下载到私有仓库;
  • 运行命令安装=》# kubectl apply -f metrics-server.yaml

spec:
  containers:
  - args:
    - --cert-dir=/tmp
    - --secure-port=4443
    - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
    - --kubelet-use-node-status-port
    image: k8s.gcr.io/metrics-server/metrics-server:v0.4.1

 args 参数说明:

  • cert-dir 指定证书目录
  • secure-port 开放安全端口
  • kubelet-preferred-address-types 使用InternalIP,ExternalIP,Hostname连接kubelet
  • kubelet-use-node-status-port 使用节点状态端口

args 参数添加:

  • kubelet-insecure-tls 不验证kubelet提供的https证书/ca

修改保存后,运行命令安装:=》# kubectl apply -f metrics-server.yaml

查看集群资源消耗信息:

  • # kubectl top node
  • # kubectl top pod

Metrics-server + cAdvisor显示资源(CPU/内存/存储)使用情况。

管理k8s组件日志

  • k8s系统组件日志
  • k8s cluster 里面部署的应用程序日志
  1. 标准输出
  2. 日志文件

猜你喜欢

转载自blog.csdn.net/ChaITSimpleLove/article/details/110902675