我是靠谱客的博主 英勇流沙,最近开发中收集的这篇文章主要介绍K8s Heapster安装:Error from server (NotFound): the server could not.... (get services http:heapster:)故事的起因,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
Kubernetes Heapster
故事的起因
最近备考cka,做实验的时候发现运行kubectl top时无法正常运行。
报错如下:
[root@k8s-master ~]# kubectl top pods
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
报错原因
Heapster是容器集群监控和性能分析工具,HPA、Dashborad、Kubectl top都依赖于heapster收集的数据。
但是Heapster从kubernetes 1.8以后已经被遗弃了… 被metrics-server所替代…
那么就部署一下Heapster吧
两个yaml文件内容如下:
[root@k8s-master ~]# cat heapster.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: heapster
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: heapster
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:heapster
subjects:
- kind: ServiceAccount
name: heapster
namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: heapster
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
k8s-app: heapster
template:
metadata:
labels:
task: monitoring
k8s-app: heapster
spec:
serviceAccountName: heapster
containers:
- name: heapster
# image: k8s.gcr.io/heapster-amd64:v1.5.4 将默认google的官方镜像替换为阿里云镜像,否则你懂得
image: registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.4
command:
- /heapster
- --source=kubernetes:https://kubernetes.default?useServiceAccount=true&kubeletHttps=true&kubeletPort=10250&insecure=true
---
apiVersion: v1
kind: Service
metadata:
labels:
task: monitoring
# For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
# If you are NOT using this as an add-on, you should comment out this line.
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: Heapster
name: heapster
namespace: kube-system
spec:
ports:
- port: 80
targetPort: 8082
selector:
k8s-app: heapster
[root@k8s-master ~]# cat heapster-clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:heapster
rules:
- apiGroups:
- ""
resources:
- events
- namespaces
- nodes
- pods
- nodes/stats
verbs:
- create
- get
- list
- watch
- apiGroups:
- extensions
resources:
- deployments
verbs:
- get
- list
- watch
部署Heapster
[root@k8s-master ~]# kubectl apply -f heapster-clusterrole.yaml
[root@k8s-master ~]# kubectl apply -f heapster.yaml
[root@k8s-master ~]# kubectl get pods -n kube-system
heapster-5ff6f69d68-cgq5j 1/1 Running 0 10s
[root@k8s-master ~]# kubectl top pods -n kube-system
NAME CPU(cores) MEMORY(bytes)
coredns-bccdc95cf-4fpls 3m 15Mi
coredns-bccdc95cf-plxlr 3m 17Mi
etcd-k8s-master 42m 101Mi
heapster-5ff6f69d68-g4bxs 0m 22Mi
kube-apiserver-k8s-master 68m 268Mi
kube-controller-manager-k8s-master 34m 58Mi
kube-flannel-ds-amd64-5lkh6 2m 20Mi
kube-flannel-ds-amd64-fpw6k 2m 21Mi
kube-flannel-ds-amd64-snngf 2m 19Mi
kube-proxy-glrtz 2m 27Mi
kube-proxy-jdcpf 2m 25Mi
kube-proxy-tcsk2 2m 23Mi
kube-scheduler-k8s-master 1m 20Mi
kube-state-metrics-7c76bdbf68-r685j 0m 30Mi
kubernetes-dashboard-79ddd5-pdjsl 0m 13Mi
模拟开题
考题的内容大概是:从label xxx=xxx,中找出cpu 最高的pod,将pod名输出到xxx文件。
[root@k8s-master ~]# kubectl top pods -n kube-system -l app=flannel
NAME CPU(cores) MEMORY(bytes)
kube-flannel-ds-amd64-5lkh6 2m 20Mi
kube-flannel-ds-amd64-fpw6k 2m 21Mi
kube-flannel-ds-amd64-snngf 2m 19Mi
[root@k8s-master ~]# kubectl top pods -n kube-system -l app=flannel|grep -i kube-flannel|head -n 1|awk '{print $1}'
kube-flannel-ds-amd64-5lkh6
[root@k8s-master ~]# kubectl top pods -n kube-system -l app=flannel|grep -i kube-flannel|head -n 1|awk '{print $1}' > 666.txt
差不多就是这样
最后
以上就是英勇流沙为你收集整理的K8s Heapster安装:Error from server (NotFound): the server could not.... (get services http:heapster:)故事的起因的全部内容,希望文章能够帮你解决K8s Heapster安装:Error from server (NotFound): the server could not.... (get services http:heapster:)故事的起因所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复