K8S部署metrics-server
- 前言
在新版的K8S中,系统资源的采集均使用Metrics-Server服务,可以通过Metrics-Server服务采集节点和Pod的内存、磁盘、CPU和网络的使用率等信息。
说的具体点:新版K8S资源使用情况的度量(如容器的 CPU 和内存使用)可以通过 Metrics API 获取。
注意:
- Metrics API 只可以查询当前的度量数据,并不保存历史数据
- Metrics API URI 为
/apis/metrics.k8s.io/
,在 k8s.io/metrics维护 - 必须部署 metrics-server 才能使用该 API,metrics-server 通过调用 Kubelet Summary API 获取数据
1.下载地址
[root@master0 ~]# wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
[root@master0 ~]# tar xf metrics-server-0.3.6.tar.gz
2.开始部署
[root@master0 ~]# cd metrics-server-0.3.6/deploy/1.8+/
#文件里面的镜像是无法直接拉去的 可以先搜索一下官方可用的镜像 k8s.gcr.io/metrics-server-amd64:v0.3.6
[root@master0 ~]# docker search metrics-server
[root@master0 ~]# docker pull mirrorgooglecontainers/metrics-server-amd64:v0.3.6
#文件有好几个 只需要更改这个一个metrics-server-deployment文件即可
[root@master0 ~/metrics-server-0.3.6/deploy/1.8+]# vim metrics-server-deployment.yaml
3. 更改配置文件
[root@master0 ~/metrics-server-0.3.6/deploy/1.8+]# cat metrics-server-deployment.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-server
namespace: kube-system
---
apiVersion: apps/v1
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 和 imagePullPolicy
# image: k8s.gcr.io/metrics-server-amd64:v0.3.6
image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6
imagePullPolicy: IfNotPresent
# 新增command配置
command:
- /metrics-server
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname
volumeMounts:
- name: tmp-dir
mountPath: /tmp
# 新增resources配置
resources:
limits:
cpu: 300m
memory: 200Mi
requests:
cpu: 200m
memory: 100Mi
4. 执行命令
[root@master0 ~/metrics-server-0.3.6/deploy/1.8+]# kubectl apply -f .
[root@master0 ~]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
master0 236m 11% 2572Mi 32%
node01 56m 5% 1019Mi 26%
node02 56m 5% 1043Mi 27%
[root@master0 ~]# kubectl top pods -A
NAMESPACE NAME CPU(cores) MEMORY(bytes)
kube-system calico-kube-controllers-6dfcd885bf-qz4x8 1m 12Mi
kube-system calico-node-5hdsh 18m 33Mi
kube-system calico-node-9lptj 41m 36Mi
kube-system calico-node-zfspg 20m 35Mi
kube-system coredns-6d56c8448f-rdpt6 3m 14Mi
kube-system coredns-6d56c8448f-wr72d 3m 12Mi
kube-system etcd-master0 19m 54Mi
kube-system kube-apiserver-master0 75m 356Mi
kube-system kube-controller-manager-master0 22m 52Mi
kube-system kube-proxy-4t924 3m 16Mi
kube-system kube-proxy-cdk27 1m 18Mi
kube-system kube-proxy-tb6nl 1m 19Mi
kube-system kube-scheduler-master0 4m 23Mi
kube-system metrics-server-b7cff9c67-nr5vh 1m 10Mi
5. 报错
#他要对节点收集状态与部署 一会就可以使用了 不用着急
[root@master0 ~/metrics-server-0.3.6/deploy/1.8+]# kubectl top node
error: metrics not available yet
标签:master0,kube,system,server,metrics,K8S,root
From: https://www.cnblogs.com/yidadasre/p/16873265.html