[k8s]Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
查看容器资源报错
kubectl top nodes
kubectl top pods
[root@master ~]# kubectl top nodes
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
[root@master ~]# kubectl top pods
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
需要安装 metrics server
curl -O https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
[root@master ~]# tar zxvf metrics-server-0.3.6.tar.gz
cd /root/metrics-server-0.3.6/deploy/1.8+
修改配置文件
vi 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: k8s.gcr.io/metrics-server-amd64:v0.3.6
imagePullPolicy: Always
volumeMounts:
- name: tmp-dir
mountPath: /tmp
# 修改后
---
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: registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.6
imagePullPolicy: IfNotPresent
### 新增开始
command:
- /metrics-server
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname
### 新增结束
volumeMounts:
- name: tmp-dir
mountPath: /tmp
拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.6
部署
kubectl apply -f .
[root@master 1.8+]# 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.apps/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
继续报错 error: metrics not available yet
这个不是BUG 需要耐心等待一会
[root@master 1.8+]# kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
master 140m 3% 3050Mi 38%
worker1 83m 2% 2144Mi 27%
worker2 66m 1% 2095Mi 26%
[root@master 1.8+]# kubectl top pods -n kube-system
NAME CPU(cores) MEMORY(bytes)
calico-kube-controllers-5569bdd565-65m6j 1m 10Mi
calico-node-dtz4t 19m 28Mi
calico-node-lfkwr 21m 32Mi
calico-node-stfz7 21m 28Mi
coredns-7ff77c879f-9gl2z 2m 13Mi
coredns-7ff77c879f-l9f27 3m 12Mi
etcd-master 13m 278Mi
kube-apiserver-master 29m 413Mi
kube-controller-manager-master 10m 47Mi
kube-proxy-cmg67 1m 12Mi
kube-proxy-kc6jz 1m 14Mi
kube-proxy-whn2j 1m 14Mi
kube-scheduler-master 4m 19Mi
metrics-server-7c9f8b966f-chb4w 1m 11Mi