Kubernetes 版本是 1.14
# kubectl version --short
Client Version: v1.14.3
Server Version: v1.14.2
下载文件
for file in aggregated-metrics-reader.yaml auth-delegator.yaml auth-reader.yaml metrics-apiservice.yaml metrics-server-deployment.yaml metrics-server-service.yaml resource-reader.yaml
do
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/$file
done
执行文件
# kubectl apply -f .
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
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
deployment.extensions/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
检查结果
# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
...
metrics-server-7cffff65bc-kg7gv 1/1 Running 0 104s
# kubectl get apiservices | grep metrics
v1beta1.metrics.k8s.io kube-system/metrics-server True 6m53s
podmetrics.metrics.k8s.io "" not found
https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/
[root@svn tasks]# kubectl top pod memory-demo --namespace=mem-example
Error from server (NotFound): podmetrics.metrics.k8s.io "mem-example/memory-demo" not found
Change the metrics-server-deployment.yaml
file and add:
command:
- /metrics-server
- --kubelet-preferred-address-types=InternalIP
- --kubelet-insecure-tls
https://stackoverflow.com/questions/52224829/kubernetes-metrics-unable-to-fetch-pod-node-metrics
修正之后,结果显示如下:
[root@svn tasks]# kubectl top pod memory-demo --namespace=mem-example
NAME CPU(cores) MEMORY(bytes)
memory-demo 87m 151Mi