Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker DevOps


Kubernetes Pod 控制器 HPA

Kubernetes 大约 2078 字

说明

需要安装mertics-serverhttps://github.com/kubernetes-sigs/metrics-server

特点

Horizontal Pod Autoscaler

通过监测Pod的使用情况,实现Pod数量的自动调整。

查看帮助

kubectl explain HorizontalPodAutoscaler

示例 yml

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: pc-hpa
  namespace: dev
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: pc-deployment
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Pods
    pods:
      metric:
        name: packets-per-second
      target:
        type: AverageValue
        averageValue: 1k

查看 HPA

kubectl get hpa -n dev

输出:

[root@localhost ~]# kubectl get hpa -n dev
NAME     REFERENCE                  TARGETS                       MINPODS   MAXPODS   REPLICAS   AGE
pc-hpa   Deployment/pc-deployment   <unknown>/1k, <unknown>/50%   1         10        0          18s

查看 Node

kubectl top node

输出:

[root@localhost ~]# kubectl top node
NAME                    CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
localhost.localdomain   115m         11%    600Mi           64%

查看 Pod

kubectl top pod -A

输出:

[root@localhost ~]# kubectl top pod -A
NAMESPACE     NAME                                      CPU(cores)   MEMORY(bytes)   
dev           pc-deployment-6f7f65b46d-b28fk            0m           1Mi             
dev           pc-deployment-6f7f65b46d-th9wp            0m           1Mi             
dev           pc-deployment-6f7f65b46d-xbxjf            0m           1Mi             
kube-system   coredns-5789895cd-vkfnr                   3m           14Mi            
kube-system   local-path-provisioner-6c79684f77-p44bx   1m           5Mi             
kube-system   metrics-server-7cd5fcb6b7-4w4q5           7m           27Mi            
kube-system   svclb-traefik-sjsfx                       0m           0Mi             
kube-system   traefik-6bb96f9bd8-wmdx4                  1m           24Mi

相关文档

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale

阅读 472 · 发布于 2022-03-12

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批