You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何查看Kubernetes中Deployment的自动扩缩容策略?

如何查看Kubernetes中Deployment的自动扩缩容策略?

操作背景

步骤1:创建Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: autoscaling-nginx
  name: autoscaling-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: autoscaling-nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: autoscaling-nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

步骤2:配置自动扩缩容策略

执行以下命令为Deployment设置自动扩缩容策略:

kubectl autoscale deployment autoscaling-nginx --min=5 --max=10 --cpu-percent=80

步骤3:尝试查看Deployment详情

执行kubectl describe deployment autoscaling-nginx后,输出中未包含自动扩缩容策略相关信息:

Name:                   autoscaling-nginx
Namespace:              default
CreationTimestamp:      Tue, 15 Aug 2023 03:30:32 +0000
Labels:                 app=autoscaling-nginx
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=autoscaling-nginx
Replicas:               5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=autoscaling-nginx
  Containers:
   nginx:
    Image:        nginx
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   autoscaling-nginx-5b89cf756 (5/5 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  104s  deployment-controller  Scaled up replica set autoscaling-nginx-5b89cf756 to 2
  Normal  ScalingReplicaSet  24s   deployment-controller  Scaled up replica set autoscaling-nginx-5b89cf756 to 5 from 2

解决方案

Kubernetes中,Deployment的自动扩缩容策略由**HorizontalPodAutoscaler(HPA)**独立管理,不属于Deployment资源的一部分,因此通过kubectl describe deployment无法查看。你可以通过以下方式查看HPA配置:

  • 查看HPA详细信息:
kubectl describe hpa autoscaling-nginx

该命令会展示HPA的完整配置,包括最小/最大副本数、CPU使用率阈值、当前指标状态等。

  • 查看HPA结构化配置:
    若需要查看YAML格式的完整配置:
kubectl get hpa autoscaling-nginx -o yaml

或使用简洁的宽格式输出:

kubectl get hpa autoscaling-nginx -o wide
  • 列出所有HPA资源:
    如果不确定HPA的名称,可列出当前命名空间下的所有HPA:
kubectl get hpa

内容的提问来源于stack exchange,提问作者Ryan Lyu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 15:11:18