在Kubernetes集群中部署 Metrics API(Metrics Server)
创新互联公司主营沈河网站建设的网络公司,主营网站建设方案,重庆APP开发,沈河h5小程序制作搭建,沈河网站营销推广欢迎沈河等地区企业咨询
[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