--- api_metadata: apiVersion: "autoscaling/v1" import: "k8s.io/api/autoscaling/v1" kind: "HorizontalPodAutoscaler" content_type: "api_reference" description: "水平 Pod 自动缩放器的配置。" title: "HorizontalPodAutoscaler" weight: 12 --- `apiVersion: autoscaling/v1` `import "k8s.io/api/autoscaling/v1"` ## HorizontalPodAutoscaler {#HorizontalPodAutoscaler} 水平 Pod 自动缩放器的配置。
- **apiVersion**: autoscaling/v1 - **kind**: HorizontalPodAutoscaler - **metadata** (}}">ObjectMeta) 标准的对象元数据。 更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata - **spec** (}}">HorizontalPodAutoscalerSpec) `spec` 定义自动缩放器的规约。 更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status. - **status** (}}">HorizontalPodAutoscalerStatus) `status` 是自动缩放器的当前信息。 ## HorizontalPodAutoscalerSpec {#HorizontalPodAutoscalerSpec} 水平 Pod 自动缩放器的规约。
- **maxReplicas** (int32),必填 `maxReplicas` 是自动扩缩器可以设置的 Pod 数量上限; 不能小于 minReplicas。 - **scaleTargetRef** (CrossVersionObjectReference),必填 对被扩缩资源的引用; 水平 Pod 自动缩放器将了解当前的资源消耗,并使用其 scale 子资源设置所需的 Pod 数量。 **CrossVersionObjectReference 包含足够的信息来让你识别出所引用的资源。** - **scaleTargetRef.kind** (string),必填 `kind` 是被引用对象的类别; 更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - **scaleTargetRef.name** (string),必填 `name` 是被引用对象的名称; 更多信息: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - **scaleTargetRef.apiVersion** (string) `apiVersion` 是被引用对象的 API 版本。 - **minReplicas** (int32) minReplicas 是自动缩放器可以缩减的副本数的下限。 它默认为 1 个 Pod。 如果启用了 alpha 特性门禁 HPAScaleToZero 并且配置了至少一个 Object 或 External 度量标准, 则 minReplicas 允许为 0。 只要至少有一个度量值可用,缩放就处于活动状态。 - **targetCPUUtilizationPercentage** (int32) `targetCPUUtilizationPercentage` 是所有 Pod 的目标平均 CPU 利用率(以请求 CPU 的百分比表示); 如果未指定,将使用默认的自动缩放策略。 ## HorizontalPodAutoscalerStatus {#HorizontalPodAutoscalerStatus} 水平 Pod 自动缩放器的当前状态
- **currentReplicas** (int32),必填 `currentReplicas` 是此自动缩放器管理的 Pod 的当前副本数。 - **desiredReplicas** (int32),必填 `desiredReplicas` 是此自动缩放器管理的 Pod 副本的所需数量。 - **currentCPUUtilizationPercentage** (int32) `currentCPUUtilizationPercentage` 是当前所有 Pod 的平均 CPU 利用率, 以请求 CPU 的百分比表示, 例如:70 表示平均 Pod 现在正在使用其请求 CPU 的 70%。 - **lastScaleTime** (Time) `lastScaleTime` 是上次 HorizontalPodAutoscaler 缩放 Pod 的数量; 自动缩放器用它来控制 Pod 数量的更改频率。 **Time 是 time.Time 的包装类,支持正确地序列化为 YAML 和 JSON。 为 time 包提供的许多工厂方法提供了包装类。** - **observedGeneration** (int64) `observedGeneration` 是此自动缩放器观察到的最新一代。 ## HorizontalPodAutoscalerList {#HorizontalPodAutoscalerList} 水平 Pod 自动缩放器对象列表。
- **apiVersion**: autoscaling/v1 - **kind**: HorizontalPodAutoscalerList - **metadata** (}}">ListMeta) 标准的列表元数据。 - **items** ([]}}">HorizontalPodAutoscaler), required `items` 是水平 Pod 自动缩放器对象的列表。 ## 操作 {#Operations}
### `get` 读取特定的 HorizontalPodAutoscaler #### HTTP 请求 GET /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name} #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称。 - **namespace** (**路径参数**): string,必填 }}">namespace - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 401: Unauthorized ### `get` 读取特定 HorizontalPodAutoscaler 的状态 #### HTTP 请求 GET /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name}/status #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称。 - **namespace** (**路径参数**): string,必填 }}">namespace - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 401: Unauthorized ### `list` 列出或监视 HorizontalPodAutoscaler 类别的对象 #### HTTP 参数 GET /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers #### 参数 - **namespace** (**路径参数**): string,必填 }}">namespace - **allowWatchBookmarks** (**查询参数**): boolean }}">allowWatchBookmarks - **continue** (**查询参数**): string }}">continue - **fieldSelector** (**查询参数**): string }}">fieldSelector - **labelSelector** (**查询参数**): string }}">labelSelector - **limit** (**查询参数**): integer }}">limit - **pretty** (**查询参数**): string }}">pretty - **resourceVersion** (**查询参数**): string }}">resourceVersion - **resourceVersionMatch** (**查询参数**): string }}">resourceVersionMatch - **sendInitialEvents** (**查询参数**): boolean }}">sendInitialEvents - **timeoutSeconds** (*查询参数**): integer }}">timeoutSeconds - **watch** (**查询参数**): boolean }}">watch #### 响应 200 (}}">HorizontalPodAutoscalerList): OK 401: Unauthorized ### `list` 列出或监视 HorizontalPodAutoscaler 类别的对象 #### HTTP 请求 GET /apis/autoscaling/v1/horizontalpodautoscalers #### 参数 - **allowWatchBookmarks** (**查询参数**): boolean }}">allowWatchBookmarks - **continue** (*查询参数**): string }}">continue - **fieldSelector** (**查询参数**): string }}">fieldSelector - **labelSelector** (**查询参数**): string }}">labelSelector - **limit** (**查询参数**): integer }}">limit - **pretty** (**查询参数**): string }}">pretty - **resourceVersion** (**查询参数**): string }}">resourceVersion - **resourceVersionMatch** (**查询参数**): string }}">resourceVersionMatch - **sendInitialEvents** (**查询参数**): boolean }}">sendInitialEvents - **timeoutSeconds** (**查询参数**): integer }}">timeoutSeconds - **watch** (**查询参数**): boolean }}">watch #### 响应 200 (}}">HorizontalPodAutoscalerList): OK 401: Unauthorized ### `create` 创建一个 HorizontalPodAutoscaler #### HTTP 请求 POST /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers #### 参数 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">HorizontalPodAutoscaler,必填 - **dryRun** (**查询参数**): string }}">dryRun - **fieldManager** (**查询参数**): string }}">fieldManager - **fieldValidation** (**查询参数**): string }}">fieldValidation - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 201 (}}">HorizontalPodAutoscaler): Created 202 (}}">HorizontalPodAutoscaler): Accepted 401: Unauthorized ### `update` 替换特定的 HorizontalPodAutoscaler #### HTTP 请求 PUT /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name} #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">HorizontalPodAutoscaler,必填 - **dryRun** (**查询参数**): string }}">dryRun - **fieldManager** (**查询参数**): string }}">fieldManager - **fieldValidation** (**查询参数**): string }}">fieldValidation - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 201 (}}">HorizontalPodAutoscaler): Created 401: Unauthorized ### `update` 替换特定 HorizontalPodAutoscaler 的状态 #### HTTP 请求 PUT /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name}/status #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">HorizontalPodAutoscaler,必填 - **dryRun** (**查询参数**): string }}">dryRun - **fieldManager** (**查询参数**): string }}">fieldManager - **fieldValidation** (**查询参数**): string }}">fieldValidation - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 201 (}}">HorizontalPodAutoscaler): Created 401: Unauthorized ### `patch` 部分更新特定的 HorizontalPodAutoscaler #### HTTP 请求 PATCH /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name} #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">Patch,必填 - **dryRun** (**查询参数**): string }}">dryRun - **fieldManager** (**查询参数**): string }}">fieldManager - **fieldValidation** (**查询参数**): string }}">fieldValidation - **force** (**查询参数**): boolean }}">force - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 201 (}}">HorizontalPodAutoscaler): Created 401: Unauthorized ### `patch` 部分更新特定 HorizontalPodAutoscaler 的状态 #### HTTP 请求 PATCH /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name}/status #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">Patch,必填 - **dryRun** (**查询参数**): string }}">dryRun - **fieldManager** (**查询参数**): string }}">fieldManager - **fieldValidation** (**查询参数**): string }}">fieldValidation - **force** (**查询参数**): boolean }}">force - **pretty** (**查询参数**): string }}">pretty #### 响应 200 (}}">HorizontalPodAutoscaler): OK 201 (}}">HorizontalPodAutoscaler): Created 401: Unauthorized ### `delete` 删除一个 HorizontalPodAutoscaler #### HTTP 请求 DELETE /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name} #### 参数 - **name** (**路径参数**): string,必填 HorizontalPodAutoscaler 的名称 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">DeleteOptions - **dryRun** (**查询参数**): string }}">dryRun - **gracePeriodSeconds** (**查询参数**): integer }}">gracePeriodSeconds - **ignoreStoreReadErrorWithClusterBreakingPotential**(**查询参数**): boolean }}">ignoreStoreReadErrorWithClusterBreakingPotential - **pretty** (**查询参数**): string }}">pretty - **propagationPolicy** (**查询参数**): string }}">propagationPolicy #### 响应 200 (}}">Status): OK 202 (}}">Status): Accepted 401: Unauthorized ### `deletecollection` 删除 HorizontalPodAutoscaler 的集合 #### HTTP 请求 DELETE /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers #### 参数 - **namespace** (**路径参数**): string,必填 }}">namespace - **body**: }}">DeleteOptions - **continue** (**查询参数**): string }}">continue - **dryRun** (**查询参数**): string }}">dryRun - **fieldSelector** (**查询参数**): string }}">fieldSelector - **gracePeriodSeconds** (**查询参数**): integer }}">gracePeriodSeconds - **ignoreStoreReadErrorWithClusterBreakingPotential**(**查询参数**): boolean }}">ignoreStoreReadErrorWithClusterBreakingPotential - **labelSelector** (**查询参数**): string }}">labelSelector - **limit** (**查询参数**): integer }}">limit - **pretty** (**查询参数**): string }}">pretty - **propagationPolicy** (**查询参数**): string }}">propagationPolicy - **resourceVersion** (**查询参数**): string }}">resourceVersion - **resourceVersionMatch** (**查询参数**): string }}">resourceVersionMatch - **sendInitialEvents** (**查询参数**): boolean }}">sendInitialEvents - **timeoutSeconds** (**查询参数**): integer }}">timeoutSeconds #### 响应 200 (}}">Status): OK 401: Unauthorized