14.容器资源需求、资源限制及HeapSter

一、容器资源需求及资源限制:

1、概念

Requests:资源需求,最低保障。

Limits:资源限额,硬限制。限制容器无论怎么运行都不能超过的资源阈值

一般来讲,requests <= limits

CPU:可压缩资源。一颗逻辑CPU,即一核。1=1000,millicores

内存:不可压缩资源。Ei,Pi,Ti,Gi,Mi,Ki ==> 以1024为进制。

2、定义资源需求及限制

资源需求和资源限制都是定义在容器上的。

[[email protected] ~]# kubectl explain pod.spec.containers.resources

使用方法文档:https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/

测试:

[[email protected] metrics]# kubectl exec pod-metrics-demo top

宿主机内核总数是2核,定义的资源limits是0.5m,所以应该是25%,此处13%,原因未明,可能与宿主机是VMVare虚拟机有关。后续再研究。

查看,CPU的limit是与定义匹配的,但内存未符合预期,可能压测效果不够。

3、服务质量QoS Class

我们对容器分配了资源限制后,k8s会自动分配一个QoS,叫服务质量

QoS(服务质量)类别(根据设置,自动归类):

Guranteed:每个容器同时设置了CPU资源,内存资源的requests和limits,并且cpu.limits=cpu.requests和memory.limits=memory.requests

Burstable:至少有一个容器设置了CPU和内存资源的requests属性

BestEffort:没有任何一个容器设置了requests或limits属性。

当资源不够使用时,BestEffort类别的容器会被优先终止;然后还是不够用,就终止Burstable级别的容器(终止是有计算标准的,优先终止已占用量接近limits的容器);

[[email protected] metrics]# kubectl describe pod pod-metrics-demo|grep "QoS Class"

二、Heapster

目前已经不维护了,此处学习只是帮助理解。目前替代采集工具是metric-server,监控工具是prometheus。

https://github.com/kubernetes-retired/heapster

1、介绍

[[email protected] metrics]# kubectl top pod pod-metrics-demo  # 查看节点或pod的资源使用,但是依赖于Heapster去采集数据。

Heapster:统一的资源使用指标的采集和存储工具。

cAdvisor:专门负责收集当前节点上各Pod,各Container,以及节点级资源的情况。属于kubelet的一个子组件,被整合到kubelet中,默认监听端口:4194。

kubelet中的cAdvisor负责收集每个节点上的资源使用情况,然后把信息存储HeapSter中,HeapSter再把数据持久化的存储在数据库InfluxDB中。然后我们再通过Grafana来图形化展示;

一般我们监控的指标包括k8s集群的系统指标、容器指标和应用指标。

默认InfluxDB使用的是存储卷是emptyDir,容器一关数据就没了,所以我们生产要换成glusterfs等存储卷才行。

2、部署

(1)准备工作

wget https://raw.githubusercontent.com/kubernetes-retired/heapster/master/deploy/kube-config/rbac/heapster-rbac.yaml
wget https://raw.githubusercontent.com/kubernetes-retired/heapster/master/deploy/kube-config/influxdb/influxdb.yaml
wget https://raw.githubusercontent.com/kubernetes-retired/heapster/master/deploy/kube-config/influxdb/heapster.yaml
wget https://raw.githubusercontent.com/kubernetes-retired/heapster/master/deploy/kube-config/influxdb/grafana.yaml[[email protected] heapster]# sed -i "s/k8s.gcr.io/registry.aliyuncs.com\/google_containers/g" *   #替换镜像文件

(2)部署influxDB

[[email protected] heapster]# vim influxdb.yaml

#修改apiVersion为apps/v1 ,因为deployment版本已经属于apps/v1群组。添加selector

[[email protected] heapster]# kubectl apply -f influxdb.yaml

influxDB工作正常了。

(3)部署Heapster

[[email protected] heapster]# kubectl apply -f heapster-rbac.yaml
[[email protected] heapster]# vim heapster.yaml  #修改apiVersion为apps/v1 ,因为deployment版本已经属于apps/v1群组。添加selector[[email protected] heapster]# kubectl apply -f heapster.yaml

(4)部署grafana

[[email protected] heapster]# vim grafana.yaml  #修改apiVersion为apps/v1 ,因为deployment版本已经属于apps/v1群组。添加selector 。修改Service的类型为NodePort

[[email protected] heapster]# kubectl apply -f grafana.yaml

默认使用的数据源就是influxDB,因为部署grafana时是有默认配置的。

3、问题排查

(1)问题一

[[email protected] heapster]# kubectl top pod

[[email protected] heapster]# kubectl logs heapster-76467968c9-qpqqf  -n kube-system
报错:Error in scraping containers from kubelet:192.168.42.130:10255: failed to get all container stats from Kubelet URL "http://192.168.42.130:10255/stats/container/": Post http://192.168.42.130:10255/stats/container/: dial tcp 192.168.42.130:10255: getsockopt: connection refused

解决方法

#在heapster.yaml清单文件中进行如下修改:

--source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250&insecure=true

(2)问题二

报错:Error in scraping containers from kubelet:192.168.42.129:10250: failed to get all container stats from Kubelet URL "https://192.168.42.129:10250/stats/container/": request failed - "403 Forbidden", response: "Forbidden (user=system:serviceaccount:kube-system:heapster, verb=create, resource=nodes, subresource=stats)"

原因分析:

查看ClusterRole: system:heapster的权限,发现的确没有针对Resource: nodes/stats 的create权限

[[email protected] heapster]# kubectl describe clusterrole system:heapster

[[email protected] heapster]# kubectl get clusterrole system:heapster -o yaml > heapster_modify.yaml
[[email protected] heapster]# kubectl delete -f heapster_modify.yaml
[[email protected] heapster]# vim heapster_modify.yaml

[[email protected] heapster]# kubectl apply -f heapster_modify.yaml
重新部署Heapster
[[email protected] heapster]# kubectl delete -f heapster.yaml
[[email protected] heapster]# kubectl apply -f heapster.yaml

查看Heapster运行日志,没有报错了。Kubectl top也能采集到数据了。

(3)验证

[[email protected] heapster]# kubectl top node

4、现状

Kubernetes从1.11就废弃了Heapster!!

CPU内存、HPA指标: 改为metrics-server

基础监控:集成到prometheus中,kubelet将metric信息暴露成prometheus需要的格式,使用Prometheus Operator

事件监控:集成到https://github.com/heptiolabs/eventrouter

后续关注基于Heapster的HPA(Horizontal Pod Autoscaling)等操作。

原文地址:https://www.cnblogs.com/cmxu/p/12256272.html

时间: 2024-08-30 16:30:35

14.容器资源需求、资源限制及HeapSter的相关文章

容器资源需求、资源限制(二十二)

官网:https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ 容器的资源需求,资源限制 Request:需求,最低保障: Limits:限制,硬限制 CPU: 1颗逻辑CPU 1=1000,millcores 500m=0.5CPU 内存: E.P.T.G.M.K.Ei.Pi Request保障容器CPU资源可用,limits限制资源 编写Demo测试, 查看CPU压缩使用情况 [

k8s之dashboard认证、资源需求、资源限制及HeapSter

1.部署dashboard kubernetes-dashboard运行时需要有sa账号提供权限 Dashboard官方地址:https://github.com/kubernetes/dashboard # 在node1上下载镜像 docker pull googlecontainer/kubernetes-dashboard-amd64:v1.10.1 docker tag googlecontainer/kubernetes-dashboard-amd64:v1.10.1 k8s.gcr.

查看 docker 容器使用的资源

在容器的使用过程中,如果能及时的掌握容器使用的系统资源,无论对开发还是运维工作都是非常有益的.幸运的是 docker 自己就提供了这样的命令:docker stats. 默认输出 docker stats 命令用来显示容器使用的系统资源.不带任何选项执行 docker stats 命令: $ docker stats 默认情况下,stats 命令会每隔 1 秒钟刷新一次输出的内容直到你按下 ctrl + c.下面是输出的主要内容:[CONTAINER]:以短格式显示容器的 ID.[CPU %]:

十四. k8s资源需求和限制, 以及pod驱逐策略

目录 容器的资源需求和资源限制 QoS Classes分类 Guaranteed Burstable Best-Effort kubernetes之node资源紧缺时pod驱逐机制 Qos Class优先级排名 可压缩资源与不可压缩资源 存储资源不足 举例 内存资源不足 举例 Node OOM (Out Of Memory) 总结 参考链接 容器的资源需求和资源限制 requests:需求,最低保障, 保证被调度的节点上至少有的资源配额 limits:限制,硬限制, 容器可以分配到的最大资源配额

[转]查看 docker 容器使用的资源

作者:sparkdev 出处:http://www.cnblogs.com/sparkdev/ 在容器的使用过程中,如果能及时的掌握容器使用的系统资源,无论对开发还是运维工作都是非常有益的.幸运的是 docker 自己就提供了这样的命令:docker stats. 默认输出 docker stats 命令用来显示容器使用的系统资源.不带任何选项执行 docker stats 命令: $ docker stats 默认情况下,stats 命令会每隔 1 秒钟刷新一次输出的内容直到你按下 ctrl

项目测试中资源需求

项目测试中的资源需求包括硬件资源.软件资源与人力资源,团队书写测试说明书的时候需要涉及到这方面的内容.其中,硬件资源不仅是安卓手机,还有服务器资源,而软件资源主要是Eclipse.人力资源中,除了要求具有一定的知识和技能以外,还需要具备对项目的热情与投入.一般而言,资源质量越好,项目软件活动时间就越短,所以合理分配项目资源需求具有极大意义.在项目测试中,分别对硬件资源.软件资源.人力资源进行了相关的汇总,便于观察资源需求对项目活动的影响.

Effective C++ 条款13/14 以对象管理资源 || 在资源管理类中小心拷贝行为

三.资源管理       资源就是一旦你使用了它,将来不用的时候必须归还系统.C++中最常用的资源就是动态内存分配.其实,资源还有 文件描述符.互斥器.图形界面中的字形.画刷.数据库连接.socket等. 1.        以对象管理资源       void f() {     investment *plv = createInvestment();     //这里存在很多不定因素,可能造成下面语句无法执行,这就存在资源泄露的可能.     delete plv; }      这里我们

通过JNDI从服务器容器中获取资源_Spring JNDI+Mysql+Tomcat

通过JNDI从服务器容器中获取DataSource资源 (由容器管理,不要关闭它,容器自己会处理)上一篇我们使用的是dbcp,这里使用JNDI: 使用JNDI连接数据: 在Spring注释 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="userna

02.规划过程组表格-活动资源需求表

活动资源需求表 项目名称 准备日期 编号 资源类型 数量 假设条件 说明 原文地址:https://www.cnblogs.com/aixiaoxiaoyu/p/9001972.html