阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

HPA

150次阅读
没有评论

共计 2239 个字符,预计需要花费 6 分钟才能阅读完成。

Horizontal Pod Autoscaling 可以根据 CPU 利用率自动伸缩一个 ReplicaSet、Deployment 或者中的 Pod 数量

cat hpa-deploy.yaml apiVersion: apps/v1 kind: Deployment metadata: name: hpa-web spec: selector: matchLabels: app: hpa-web replicas: 1 template: metadata: labels: app: hpa-web spec: containers: - name: hpa-web image: gcr.io/google_containers/hpa-example imagePullPolicy: IfNotPresent ports: - containerPort: 80 resources: limits: cpu: 200m memory: 200Mi requests: cpu: 100m memory: 100Mi --- apiVersion: v1 kind: Service metadata: name: hpa-web spec: type: ClusterIP selector: app: hpa-web ports: - name: http port: 80 targetPort: 80

HPA

HPA

创建 HPA 控制器 – 相关算法的详情请参阅这篇文档:http://git.k8s.io/community/contributors/design-proposals/horizontal-pod-autoscaler.md#autoscaling-algorithm

kubectl autoscale deployment hpa-web --cpu-percent=50 --min=1 --max=10

HPA

增加负载,查看负载节点数目

两种方式: 1. 命令行创建: 创建测试 POD: kubectl run -i --tty zutuanxue --image=busybox --image-pull-policy='IfNotPresent' /bin/sh 执行命令: while true; do wget -q -O- http://hpa-web.default.svc.cluster.local; done 2. 副本控制器创建: cat test.yaml apiVersion: apps/v1 kind: Deployment metadata: name: ceshi spec: selector: matchLabels: app: ceshi replicas: 1 template: metadata: labels: app: ceshi spec: containers: - name: ceshi image: docker.io/busybox imagePullPolicy: IfNotPresent command: ['sh', '-c', 'while true; do wget -q -O- http://hpa-web.default.svc.cluster.local; done']

HPA

HPA

HPA

资源限制 – Pod

Kubernetes 对资源的限制实际上是通过 cgroup 来控制的,cgroup 是容器的一组用来控制内核如何运行进程的相关属性集合。针对内存、CPU 和各种设备都有对应的 cgroup

默认情况下,Pod 运行没有 CPU 和内存的限额。这意味着系统中的任何 Pod 将能够像执行该 Pod 所在的节点一样,消耗足够多的 CPU 和内存。一般会针对某些应用的 pod 资源进行资源限制,这个资源限制是通过 resources 的 requests 和 limits 来实现

spec: containers: - image: xxxx imagePullPolicy: Always name: auth ports: - containerPort: 8080 protocol: TCP resources: limits: cpu: "4" memory: 2Gi requests: cpu: 250m memory: 250Mi

requests 要分配的资源,limits 为最高请求的资源值。可以简单理解为初始值和最大值

资源限制 – 名称空间

​ 1、计算资源配额

apiVersion: v1 kind: ResourceQuota metadata: name: compute-resources namespace: zutuanxue spec: hard: pods: "20" requests.cpu: "20" requests.memory: 100Gi limits.cpu: "40" limits.memory: 200Gi

2、配置对象数量配额限制

apiVersion: v1 kind: ResourceQuota metadata: name: object-counts namespace: zutuanxue spec: hard: configmaps: "10" persistentvolumeclaims: "4" ReplicaSet: "20" secrets: "10" services: "10"

3、配置 CPU 和 内存 LimitRange

apiVersion: v1 kind: LimitRange metadata: name: mem-limit-range spec: limits: - default: memory: 50Gi cpu: 5 defaultRequest: memory: 1Gi cpu: 1 type: Container

default 即 limit 的值

defaultRequest 即 request 的值

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-06-09发表,共计2239字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中