[root@master1 ~]# cd /opt/install && mkdir -p metrics-server
[root@master1 install]# cd metrics-server
[root@master1 metrics-server]# wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
[root@master1 ~]# cd /opt/install/metrics-server/metrics-server-0.3.6/deploy/1.8+/
[root@master1 1.8+]# cp metrics-server-deployment.yaml metrics-server-deployment.yaml.backup
[root@master1 1.8+]# vi metrics-server-deployment.yaml
[root@master1 1.8+]# diff metrics-server-deployment.yaml metrics-server-deployment.yaml.backup
32,38c32,33
< image: harbor.demo/middleware/metrics-server-amd64:v0.3.6
< imagePullPolicy: IfNotPresent
< command:
< - /metrics-server
< - --requestheader-allowed-names=k8s-demo-aggregator
< - --kubelet-insecure-tls
< - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
---
> image: k8s.gcr.io/metrics-server-amd64:v0.3.6
> imagePullPolicy: Always
42,48c37
< resources:
< limits:
< cpu: 500m
< memory: 500Mi
< requests:
< cpu: 200m
< memory: 200Mi
---
>
[root@master1 ~]# cd /opt/install/metrics-server/
[root@master1 metrics-server]# kubectl apply -f metrics-server-0.3.6/deploy/1.8+/
serviceaccount/metrics-server created
deployment.apps/metrics-server created
[root@master1 ~]# kubectl get apiservices.apiregistration.k8s.io | grep metrics
v1beta1.metrics.k8s.io kube-system/metrics-server True 1h
[root@master1 ~]# kubectl get apiservice v1beta1.metrics.k8s.io -o yaml
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apiregistration.k8s.io/v1beta1","kind":"APIService","metadata":{"annotations":{},"name":"v1beta1.metrics.k8s.io"},"spec":{"group":"metrics.k8s.io","groupPriorityMinimum":100,"insecureSkipTLSVerify":true,"service":{"name":"metrics-server","namespace":"kube-system"},"version":"v1beta1","versionPriority":100}}
creationTimestamp: "2020-12-30T01:42:45Z"
name: v1beta1.metrics.k8s.io
resourceVersion: "6762803"
selfLink: /apis/apiregistration.k8s.io/v1/apiservices/v1beta1.metrics.k8s.io
uid: 437ded8b-3a2c-40ed-8503-4c1450f61635
spec:
group: metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: metrics-server
namespace: kube-system
port: 443
version: v1beta1
versionPriority: 100
status:
conditions:
- lastTransitionTime: "2021-01-27T02:16:16Z"
message: all checks passed
reason: Passed
status: "True"
type: Available
[root@master1 ~]# kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
master1 175m 4% 1681Mi 58%
master2 226m 5% 1844Mi 63%
master3 195m 4% 1772Mi 61%
node1 230m 5% 1212Mi 64%
node2 118m 2% 962Mi 51%
node3 238m 5% 1315Mi 69%
[root@master1 ~]# kubectl top pod -A
NAMESPACE NAME CPU(cores) MEMORY(bytes)
default busybox 0m 1Mi
kube-system calico-kube-controllers-6bbbcf9cb7-mp2qg 1m 23Mi
kube-system calico-node-2mmrn 33m 108Mi
kube-system calico-node-4gnz4 28m 111Mi
kube-system calico-node-7lb2j 36m 112Mi
kube-system calico-node-kwksx 33m 111Mi
kube-system calico-node-lnwj2 33m 114Mi
kube-system calico-node-tfj98 35m 114Mi
kube-system coredns-7f44d46d8d-q4sd2 4m 22Mi
kube-system metrics-server-59fc8d556f-tdbhd 1m 33Mi
[root@master1 ~]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes/node2" | jq
{
"kind": "NodeMetrics",
"apiVersion": "metrics.k8s.io/v1beta1",
"metadata": {
"name": "node2",
"selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/node2",
"creationTimestamp": "2021-01-28T02:41:22Z"
},
"timestamp": "2021-01-28T02:40:59Z",
"window": "30s",
"usage": {
"cpu": "114340963n",
"memory": "990204Ki"
}
}
[root@master1 ~]# kubectl top node
error: metrics not available yet
[root@master1 ~]# kubectl top node
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)
K8S-Demo集群实践00:搭建镜像仓库Harbor+安全扫描
K8S-Demo集群实践01:准备VMware虚拟机模板
K8S-Demo集群实践02:准备VMware虚拟机3台Master+3台Node
K8S-Demo集群实践03:准备集群各组件间HTTPS通讯需要的x509证书
K8S-Demo集群实践04:部署etcd三节点高可用集群
K8S-Demo集群实践05:安装kubectl并配置集群管理员账户
K8S-Demo集群实践06:部署kube-apiserver到master节点(3个无状态实例)
K8S-Demo集群实践07:kube-apiserver高可用方案
K8S-Demo集群实践08:部署高可用kube-controller-manager集群
K8S-Demo集群实践09:部署高可用kube-scheduler集群
K8S-Demo集群实践10:部署ipvs模式的kube-proxy组件
K8S-Demo集群实践11:部署ipvs模式的kube-kubelet组件
K8S-Demo集群实践12:部署Calico网络
K8S-Demo集群实践13:部署集群CoreDNS
K8S-Demo集群实践14:部署集群监控服务Metrics Server
K8S-Demo集群实践15:部署Kubernetes Dashboard
K8S-Demo集群实践16:部署Kube-Prometheus
K8S-Demo集群实践17:部署私有云盘owncloud(10.6版本)
K8S-Demo集群实践18:构建宇宙中第一个基础容器镜像