kubeasz/docs/guide/metrics-server.md

53 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Metrics Server
从 v1.8 开始,资源使用情况的度量(如容器的 CPU 和内存使用)可以通过 Metrics API 获取;前提是集群中要部署 Metrics Server它从Kubelet 公开的Summary API采集指标信息关于更多的背景介绍请参考如下文档
- Metrics Server[设计提案](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/metrics-server.md)
大致是说它符合k8s的监控架构设计受heapster项目启发并且比heapster优势在于访问不需要apiserver的代理机制提供认证和授权等很多集群内组件依赖它HPA,scheduler,kubectl top因此它应该在集群中默认运行部分k8s集群的安装工具已经默认集成了Metrics Server的安装以下概述下它的安装
- 1.metric-server是扩展的apiserver依赖于[kube-aggregator](https://github.com/kubernetes/kube-aggregator)因此需要在apiserver中开启相关参数。
- 2.需要在集群中运行deployment处理请求
从kubeasz 0.1.1 开始metrics-server已经默认集成在集群安装脚本中请查看`roles/cluster-addon/defaults/main.yml`中的设置
## 安装
默认已集成在90.setup.yml中如果分步请执行`ansible-play /etc/ansible/07.cluster-addon.yml`
- 1.设置apiserver相关[参数](../../roles/kube-master/templates/kube-apiserver.service.j2)
``` bash
... # 省略
--requestheader-client-ca-file={{ ca_dir }}/ca.pem \
--requestheader-allowed-names=aggregator \
--requestheader-extra-headers-prefix=X-Remote-Extra- \
--requestheader-group-headers=X-Remote-Group \
--requestheader-username-headers=X-Remote-User \
--proxy-client-cert-file={{ ca_dir }}/aggregator-proxy.pem \
--proxy-client-key-file={{ ca_dir }}/aggregator-proxy-key.pem \
--enable-aggregator-routing=true \
```
- 2.生成[aggregator proxy相关证书](../../roles/kube-master/tasks/main.yml)
参考1https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/
参考2https://kubernetes.io/docs/tasks/access-kubernetes-api/setup-extension-api-server/
## 验证
- 查看生成的新apiv1beta1.metrics.k8s.io
``` bash
$ kubectl get apiservice|grep metrics
v1beta1.metrics.k8s.io 1d
```
- 查看kubectl top命令无需额外安装heapster
``` bash
$ kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
192.168.1.1 116m 2% 2342Mi 60%
192.168.1.2 79m 1% 1824Mi 47%
192.168.1.3 82m 2% 1897Mi 49%
$ kubectl top pod --all-namespaces # 输出略
```
- 验证基于metrics-server实现的基础hpa自动缩放请参考[hpa.md](hpa.md)