重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
监控资源指标管道 Metrics API(Metrics Server)
专注于为中小企业提供成都网站设计、做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业奎文免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
在Kubernetes集群中部署 Metrics API(Metrics Server)
[root@node1 metrics]# ll
total 24
-rw-r--r-- 1 root root 398 Feb 28 03:30 auth-delegator.yaml
-rw-r--r-- 1 root root 419 Feb 28 03:30 auth-reader.yaml
-rw-r--r-- 1 root root 388 Feb 28 03:30 metrics-apiservice.yaml
-rw-r--r-- 1 root root 3252 Feb 28 03:30 metrics-server-deployment.yaml
-rw-r--r-- 1 root root 336 Feb 28 03:30 metrics-server-service.yaml
-rw-r--r-- 1 root root 795 Feb 28 03:30 resource-reader.yaml
[root@node1 metrics]#
command: //此处修改
- /metrics-server
- --metric-resolution=30s
# These are needed for GKE, which doesn't support secure communication yet.
# Remove these lines for non-GKE clusters, and when GKE supports token-based auth.
- --kubelet-port=10250
#- --deprecated-kubelet-completely-insecure=true
- --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
command: //此处修改
- /pod_nanny
- --config-dir=/etc/config
- --cpu=5m
- --extra-cpu=0.5m
- --memory=80Mi
- --extra-memory=8Mi
- --threshold=5
- --deployment=metrics-server-v0.3.6
- --container=metrics-server
- --poll-period=300000
- --estimator=exponential
# Specifies the smallest cluster (defined in number of nodes)
# resources will be scaled to.
#- --minClusterSize={{ metrics_server_min_cluster_size }}
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- namespaces
- nodes/stats
[root@node2 ~]# cat pull-metrics.sh
#!/bin/bash
#
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.6
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/addon-resizer:1.8.7
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.6 k8s.gcr.io/metrics-server-amd64:v0.3.6
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/addon-resizer:1.8.7 k8s.gcr.io/addon-resizer:1.8.7
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.6
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/addon-resizer:1.8.7
[root@node2 ~]#
[root@node1 metrics]# kubectl apply -f ./
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
configmap/metrics-server-config created
deployment.apps/metrics-server-v0.3.6 created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
[root@node1 metrics]#
[root@node1 ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
metrics-server-v0.3.6-cf56dfd4-mj7p2 2/2 Running 0 22s
[root@node1 ~]# kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
node1 137m 6% 1043Mi 69%
node2 21m 2% 333Mi 20%
node3 23m 2% 343Mi 28%
查看node资源指标
[root@node1 metrics]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" | jq | less
查看pods资源指标
[root@node1 metrics]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1/pods" | jq | less
其它方式在Kubernetes 上部署Metrics Server的方法
此方法要比以上部署要容易许多,可参考之
github kubernetes-sigs