すべてのプロダクト
Search
ドキュメントセンター

Container Service for Kubernetes:垂直ポッドオートスケーラー (VPA)

最終更新日:Dec 13, 2024

ポッドの実際のリソース使用量に基づいてリソース割り当てを自動的に調整および最適化して、十分なリソースがあるノードにポッドを確実にスケジュールできるようにする場合は、アプリケーションコンテナの垂直ポッドオートスケーラー (VPA) 機能を有効にすることをお勧めします。 VPAは、ポッドのリソース消費モードを監視し、CPUとメモリの割り当てに関する推奨事項を提供できます。 さらに、レプリケートされたポッドの数を変更することなく、リソース割り当てを調整できます。 VPAは、安定したリソース供給を必要とするステートフルアプリケーションなどのシナリオに適しています。

あなたが始める前に

VPAの機能をよりよく理解するために、このトピックを読む前に、基本情報、使用法のメモ、および既知の制限について学ぶことをお勧めします。 詳細については、「KubernetesコミュニティVPAの概要」をご参照ください。

さらに、Container Service for Kubernetes (ACK) クラスターは、さまざまなワークロードスケーリング (スケジューリング層の弾力性) とノードスケーリング (リソース層の弾力性) ソリューションを提供します。 さまざまなソリューションのシナリオと限界を最初に理解するには、自動スケーリングの概要トピックを読むことをお勧めします。

ack-vertical-pod-autoscaler紹介

VPAは、ack-vertical-pod-autoscalerコンポーネントに基づいて実装されており、実際のリソース要件に応じて、ポッド内のコンテナのCPU割り当てとメモリの要求および制限パラメータを推奨および自動的に調整します。 VPAは、初期コンテナ設定で指定したリソース制限に対するリソース要求の比率も保持します。 ack-vertical-pod-autoscalerコンポーネントは、次の部分で構成されています。

  • admission-controller: 新しいポッドの正しいリソースリクエスト値を設定します。 admission-controllerコンポーネントをインストールする前に、スクリプトを使用してwebhookの証明書を生成する必要があります。

  • recommender: コンテナの現在および過去のリソース使用状況を監視し、検出されたデータに基づいてリソース設定を推奨し、リソース要件に正確に一致します。

  • updater: VPAによって管理されるポッドのリソース構成が正しいかどうかを確認します。 そうでない場合、アップデータは、後続の再構成のためにこれらのポッドを終了する。

注意事項

重要

VPA機能はベータフェーズにあり、そのパフォーマンスは大規模なクラスターではテストされていません。 この機能を使用するときは注意してください。 問題が発生したり、提案がある場合は、

チケットを起票し、コンテナサービスチームにお問い合わせください。

  • 実行中のポッドのリソース構成を更新すると、ポッドの再起動と再作成が行われ、ポッドは他のノードにスケジュールされる可能性があります。 VPAは、ポッドを再起動せずに既存のポッドのリソース要求を自動的に更新する更新メカニズムをサポートしていますが、このメカニズムはまだテスト段階にあります。

  • VPAは、レプリケーションコントローラーで管理されていないポッドを削除しません。 VPAでは、このようなポッドの自動モードは初期モードと同等です。つまり、VPAは新しいポッドのリソース要求と制限を設定しますが、不適切なリソース割り当てを持つ実行中のポッドを自動的に削除して再作成することはありません。

  • 同じワークロードに対して複数のVPAをデプロイすることはお勧めしません。 複数のVPAが同時にポッドと一致する場合、予測できない動作が発生する可能性があります。

  • VPAによって変更されたポッドリソース要求が、ノードリソース、アイドルリソース、リソースクォータなどの実際のリソースの上限を超え、ポッドがPending状態になり、スケジュールに失敗する可能性があります。 この場合、ノードの自動スケーリングを使用すると、ポッドのリソース使用率がスケーリングしきい値を超えると、ポッドがスケールアウトします。 ただし、ノードリソースが不十分な場合、ポッドはスケジュールされず、Pending状態になり、ノードのスケーリングがトリガーされます。 詳細については、「ノードの自動スケーリングの有効化」をご参照ください。

  • VPAとHorizontal Pod Autoscaler (HPA) のコントローラは完全に互換性がありません。 VPAとHPAの両方を使用してCPUとメモリの使用量を監視すると、競合が発生する可能性があります。 この競合は、HPAがCPUおよびメモリメトリック以外のカスタムまたは外部メトリックのみを監視する場合に回避できます。

  • VPAは、アドミッションコントローラーとしてアドミッションwebhookを使用します。 他のアドミッションWebフックがクラスターに存在する場合は、これらのアドミッションWebフックがVPAと競合しないようにしてください。

    説明

    アドミッションコントローラの実行シーケンスは、APIサーバの構成パラメータで定義される。

  • VPAはほとんどのメモリ不足 (OOM) イベントを処理できますが、すべてのシナリオで成功を保証することはできません。

VPAの既知の制限の詳細については、「VPAの既知の制限」をご参照ください。

ステップ1: ack-vertical-pod-autoscalerをインストールする

Kubernetes 1.26以降を実行するクラスターの場合はコンソールを使用してack-vertical-pod-autoscalerをインストールすることができます。また、1.26より前のKubernetesを実行するクラスターの場合はkubectlを使用します。

コンソールを使用したインストール (推奨)

ackコンソールを使用してACK-vertical-pod-autoscalerをインストールすることをお勧めします。これは、基本的な複雑さを理解することなく、使用を簡素化し、メンテナンスコストを削減するためです。

前提条件

説明

kubectlを使用してVPAをインストールした場合は、そのVPAをアンインストールし、コンソールを使用して再インストールすることを推奨します。 詳細については、「」をご参照ください。コンソールを使用してkubectlを使用してインストールされたVPAを管理する方法?.

インストール手順

  1. ACKコンソールにログインします。 左側のナビゲーションウィンドウで、[クラスター] をクリックします。

  2. [クラスター] ページで、管理するクラスターの名前をクリックします。 左側のナビゲーションウィンドウで、[操作] > [アドオン] を選択します。

  3. アドオンページで、ack-vertical-pod-autoscalerを見つけ、プロンプトに従ってインストールを完了します。

kubectlを使用したインストール

前提条件

ステップ

  1. ロールベースのアクセス制御 (RBAC) 権限のYAMLファイルを保存し、コマンドを実行してRBAC権限ファイルを作成します。

    展開してRBACのYAMLテンプレートを表示

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:metrics-reader
    rules:
      - apiGroups:
          - "metrics.k8s.io"
        resources:
          - pods
        verbs:
          - get
          - list
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:vpa-actor
    rules:
      - apiGroups:
          - ""
        resources:
          - pods
          - nodes
          - limitranges
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - ""
        resources:
          - events
        verbs:
          - get
          - list
          - watch
          - create
      - apiGroups:
          - "poc.autoscaling.k8s.io"
        resources:
          - verticalpodautoscalers
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - "autoscaling.k8s.io"
        resources:
          - verticalpodautoscalers
        verbs:
          - get
          - list
          - watch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:vpa-status-actor
    rules:
      - apiGroups:
          - "autoscaling.k8s.io"
        resources:
          - verticalpodautoscalers/status
        verbs:
          - get
          - patch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:vpa-checkpoint-actor
    rules:
      - apiGroups:
          - "poc.autoscaling.k8s.io"
        resources:
          - verticalpodautoscalercheckpoints
        verbs:
          - get
          - list
          - watch
          - create
          - patch
          - delete
      - apiGroups:
          - "autoscaling.k8s.io"
        resources:
          - verticalpodautoscalercheckpoints
        verbs:
          - get
          - list
          - watch
          - create
          - patch
          - delete
      - apiGroups:
          - ""
        resources:
          - namespaces
        verbs:
          - get
          - list
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:evictioner
    rules:
      - apiGroups:
          - "apps"
          - "extensions"
        resources:
          - replicasets
        verbs:
          - get
      - apiGroups:
          - ""
        resources:
          - pods/eviction
        verbs:
          - create
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:metrics-reader
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:metrics-reader
    subjects:
      - kind: ServiceAccount
        name: vpa-recommender
        namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-actor
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:vpa-actor
    subjects:
      - kind: ServiceAccount
        name: vpa-recommender
        namespace: kube-system
      - kind: ServiceAccount
        name: vpa-updater
        namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-status-actor
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:vpa-status-actor
    subjects:
      - kind: ServiceAccount
        name: vpa-recommender
        namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-checkpoint-actor
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:vpa-checkpoint-actor
    subjects:
      - kind: ServiceAccount
        name: vpa-recommender
        namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:vpa-target-reader
    rules:
      - apiGroups:
        - '*'
        resources:
        - '*/scale'
        verbs:
        - get
        - watch
      - apiGroups:
          - ""
        resources:
          - replicationcontrollers
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - apps
        resources:
          - daemonsets
          - deployments
          - replicasets
          - statefulsets
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - batch
        resources:
          - jobs
          - cronjobs
        verbs:
          - get
          - list
          - watch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-target-reader-binding
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:vpa-target-reader
    subjects:
      - kind: ServiceAccount
        name: vpa-recommender
        namespace: kube-system
      - kind: ServiceAccount
        name: vpa-admission-controller
        namespace: kube-system
      - kind: ServiceAccount
        name: vpa-updater
        namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-evictioner-binding
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:evictioner
    subjects:
      - kind: ServiceAccount
        name: vpa-updater
        namespace: kube-system
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: vpa-admission-controller
      namespace: kube-system
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: vpa-recommender
      namespace: kube-system
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: vpa-updater
      namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:vpa-admission-controller
    rules:
      - apiGroups:
          - ""
        resources:
          - pods
          - configmaps
          - nodes
          - limitranges
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - "admissionregistration.k8s.io"
        resources:
          - mutatingwebhookconfigurations
        verbs:
          - create
          - delete
          - get
          - list
      - apiGroups:
          - "poc.autoscaling.k8s.io"
        resources:
          - verticalpodautoscalers
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - "autoscaling.k8s.io"
        resources:
          - verticalpodautoscalers
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - "coordination.k8s.io"
        resources:
          - leases
        verbs:
          - create
          - update
          - get
          - list
          - watch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-admission-controller
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:vpa-admission-controller
    subjects:
      - kind: ServiceAccount
        name: vpa-admission-controller
        namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:vpa-status-reader
    rules:
      - apiGroups:
          - "coordination.k8s.io"
        resources:
          - leases
        verbs:
          - get
          - list
          - watch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:vpa-status-reader-binding
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:vpa-status-reader
    subjects:
      - kind: ServiceAccount
        name: vpa-updater
        namespace: kube-system
    kubectl apply -f rbac.yaml
  2. CustomResourceDefinition (CRD) のYAMLテンプレートを保存し、コマンドを実行してack-vertical-pod-autoscalerのCRDを作成します。

    説明

    CRDは、ACKクラスタのスケーラビリティを改善する。 詳細については、「CustomResourceDefinitionsによるKubernetes APIの拡張」をご参照ください。

    CRDのYAMLテンプレートは次のとおりです。

    1.2 2以降および1.26以前のKubernetesバージョン

    展開してCRDのYAMLテンプレートを表示

    apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
      annotations:
        api-approved.kubernetes.io: https://github.com/kubernetes/kubernetes/pull/63797
        controller-gen.kubebuilder.io/version: v0.9.2
      creationTimestamp: null
      name: verticalpodautoscalercheckpoints.autoscaling.k8s.io
    spec:
      group: autoscaling.k8s.io
      names:
        kind: VerticalPodAutoscalerCheckpoint
        listKind: VerticalPodAutoscalerCheckpointList
        plural: verticalpodautoscalercheckpoints
        shortNames:
        - vpacheckpoint
        singular: verticalpodautoscalercheckpoint
      scope: Namespaced
      versions:
      - name: v1
        schema:
          openAPIV3Schema:
            description: VerticalPodAutoscalerCheckpoint is the checkpoint of the internal
              state of VPA that is used for recovery after recommender's restart.
            properties:
              apiVersion:
                description: 'APIVersion defines the versioned schema of this representation
                  of an object. Servers should convert recognized schemas to the latest
                  internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
                type: string
              kind:
                description: 'Kind is a string value representing the REST resource this
                  object represents. Servers may infer this from the endpoint the client
                  submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                type: string
              metadata:
                type: object
              spec:
                description: 'Specification of the checkpoint. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.'
                properties:
                  containerName:
                    description: Name of the checkpointed container.
                    type: string
                  vpaObjectName:
                    description: Name of the VPA object that stored VerticalPodAutoscalerCheckpoint
                      object.
                    type: string
                type: object
              status:
                description: Data of the checkpoint.
                properties:
                  cpuHistogram:
                    description: Checkpoint of histogram for consumption of CPU.
                    properties:
                      bucketWeights:
                        description: Map from bucket index to bucket weight.
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                      referenceTimestamp:
                        description: Reference timestamp for samples collected within
                          this histogram.
                        format: date-time
                        nullable: true
                        type: string
                      totalWeight:
                        description: Sum of samples to be used as denominator for weights
                          from BucketWeights.
                        type: number
                    type: object
                  firstSampleStart:
                    description: Timestamp of the fist sample from the histograms.
                    format: date-time
                    nullable: true
                    type: string
                  lastSampleStart:
                    description: Timestamp of the last sample from the histograms.
                    format: date-time
                    nullable: true
                    type: string
                  lastUpdateTime:
                    description: The time when the status was last refreshed.
                    format: date-time
                    nullable: true
                    type: string
                  memoryHistogram:
                    description: Checkpoint of histogram for consumption of memory.
                    properties:
                      bucketWeights:
                        description: Map from bucket index to bucket weight.
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                      referenceTimestamp:
                        description: Reference timestamp for samples collected within
                          this histogram.
                        format: date-time
                        nullable: true
                        type: string
                      totalWeight:
                        description: Sum of samples to be used as denominator for weights
                          from BucketWeights.
                        type: number
                    type: object
                  totalSamplesCount:
                    description: Total number of samples in the histograms.
                    type: integer
                  version:
                    description: Version of the format of the stored data.
                    type: string
                type: object
            type: object
        served: true
        storage: true
      - name: v1beta2
        schema:
          openAPIV3Schema:
            description: VerticalPodAutoscalerCheckpoint is the checkpoint of the internal
              state of VPA that is used for recovery after recommender's restart.
            properties:
              apiVersion:
                description: 'APIVersion defines the versioned schema of this representation
                  of an object. Servers should convert recognized schemas to the latest
                  internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
                type: string
              kind:
                description: 'Kind is a string value representing the REST resource this
                  object represents. Servers may infer this from the endpoint the client
                  submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                type: string
              metadata:
                type: object
              spec:
                description: 'Specification of the checkpoint. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.'
                properties:
                  containerName:
                    description: Name of the checkpointed container.
                    type: string
                  vpaObjectName:
                    description: Name of the VPA object that stored VerticalPodAutoscalerCheckpoint
                      object.
                    type: string
                type: object
              status:
                description: Data of the checkpoint.
                properties:
                  cpuHistogram:
                    description: Checkpoint of histogram for consumption of CPU.
                    properties:
                      bucketWeights:
                        description: Map from bucket index to bucket weight.
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                      referenceTimestamp:
                        description: Reference timestamp for samples collected within
                          this histogram.
                        format: date-time
                        nullable: true
                        type: string
                      totalWeight:
                        description: Sum of samples to be used as denominator for weights
                          from BucketWeights.
                        type: number
                    type: object
                  firstSampleStart:
                    description: Timestamp of the fist sample from the histograms.
                    format: date-time
                    nullable: true
                    type: string
                  lastSampleStart:
                    description: Timestamp of the last sample from the histograms.
                    format: date-time
                    nullable: true
                    type: string
                  lastUpdateTime:
                    description: The time when the status was last refreshed.
                    format: date-time
                    nullable: true
                    type: string
                  memoryHistogram:
                    description: Checkpoint of histogram for consumption of memory.
                    properties:
                      bucketWeights:
                        description: Map from bucket index to bucket weight.
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                      referenceTimestamp:
                        description: Reference timestamp for samples collected within
                          this histogram.
                        format: date-time
                        nullable: true
                        type: string
                      totalWeight:
                        description: Sum of samples to be used as denominator for weights
                          from BucketWeights.
                        type: number
                    type: object
                  totalSamplesCount:
                    description: Total number of samples in the histograms.
                    type: integer
                  version:
                    description: Version of the format of the stored data.
                    type: string
                type: object
            type: object
        served: true
        storage: false
    ---
    apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
      annotations:
        api-approved.kubernetes.io: https://github.com/kubernetes/kubernetes/pull/63797
        controller-gen.kubebuilder.io/version: v0.9.2
      creationTimestamp: null
      name: verticalpodautoscalers.autoscaling.k8s.io
    spec:
      group: autoscaling.k8s.io
      names:
        kind: VerticalPodAutoscaler
        listKind: VerticalPodAutoscalerList
        plural: verticalpodautoscalers
        shortNames:
        - vpa
        singular: verticalpodautoscaler
      scope: Namespaced
      versions:
      - additionalPrinterColumns:
        - jsonPath: .spec.updatePolicy.updateMode
          name: Mode
          type: string
        - jsonPath: .status.recommendation.containerRecommendations[0].target.cpu
          name: CPU
          type: string
        - jsonPath: .status.recommendation.containerRecommendations[0].target.memory
          name: Mem
          type: string
        - jsonPath: .status.conditions[?(@.type=='RecommendationProvided')].status
          name: Provided
          type: string
        - jsonPath: .metadata.creationTimestamp
          name: Age
          type: date
        name: v1
        schema:
          openAPIV3Schema:
            description: VerticalPodAutoscaler is the configuration for a vertical pod
              autoscaler, which automatically manages pod resources based on historical
              and real time resource utilization.
            properties:
              apiVersion:
                description: 'APIVersion defines the versioned schema of this representation
                  of an object. Servers should convert recognized schemas to the latest
                  internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
                type: string
              kind:
                description: 'Kind is a string value representing the REST resource this
                  object represents. Servers may infer this from the endpoint the client
                  submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                type: string
              metadata:
                type: object
              spec:
                description: 'Specification of the behavior of the autoscaler. More info:
                  https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.'
                properties:
                  recommenders:
                    description: Recommender responsible for generating recommendation
                      for this object. List should be empty (then the default recommender
                      will generate the recommendation) or contain exactly one recommender.
                    items:
                      description: VerticalPodAutoscalerRecommenderSelector points to
                        a specific Vertical Pod Autoscaler recommender. In the future
                        it might pass parameters to the recommender.
                      properties:
                        name:
                          description: Name of the recommender responsible for generating
                            recommendation for this object.
                          type: string
                      required:
                      - name
                      type: object
                    type: array
                  resourcePolicy:
                    description: Controls how the autoscaler computes recommended resources.
                      The resource policy may be used to set constraints on the recommendations
                      for individual containers. If not specified, the autoscaler computes
                      recommended resources for all containers in the pod, without additional
                      constraints.
                    properties:
                      containerPolicies:
                        description: Per-container resource policies.
                        items:
                          description: ContainerResourcePolicy controls how autoscaler
                            computes the recommended resources for a specific container.
                          properties:
                            containerName:
                              description: Name of the container or DefaultContainerResourcePolicy,
                                in which case the policy is used by the containers that
                                don't have their own policy specified.
                              type: string
                            controlledResources:
                              description: Specifies the type of recommendations that
                                will be computed (and possibly applied) by VPA. If not
                                specified, the default of [ResourceCPU, ResourceMemory]
                                will be used.
                              items:
                                description: ResourceName is the name identifying various
                                  resources in a ResourceList.
                                type: string
                              type: array
                            controlledValues:
                              description: Specifies which resource values should be controlled.
                                The default is "RequestsAndLimits".
                              enum:
                              - RequestsAndLimits
                              - RequestsOnly
                              type: string
                            maxAllowed:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Specifies the maximum amount of resources that
                                will be recommended for the container. The default is
                                no maximum.
                              type: object
                            minAllowed:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Specifies the minimal amount of resources that
                                will be recommended for the container. The default is
                                no minimum.
                              type: object
                            mode:
                              description: Whether autoscaler is enabled for the container.
                                The default is "Auto".
                              enum:
                              - Auto
                              - "Off"
                              type: string
                          type: object
                        type: array
                    type: object
                  targetRef:
                    description: TargetRef points to the controller managing the set of
                      pods for the autoscaler to control - e.g. Deployment, StatefulSet.
                      VerticalPodAutoscaler can be targeted at controller implementing
                      scale subresource (the pod set is retrieved from the controller's
                      ScaleStatus) or some well known controllers (e.g. for DaemonSet
                      the pod set is read from the controller's spec). If VerticalPodAutoscaler
                      cannot use specified target it will report ConfigUnsupported condition.
                      Note that VerticalPodAutoscaler does not require full implementation
                      of scale subresource - it will not use it to modify the replica
                      count. The only thing retrieved is a label selector matching pods
                      grouped by the target resource.
                    properties:
                      apiVersion:
                        description: API version of the referent
                        type: string
                      kind:
                        description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"'
                        type: string
                      name:
                        description: 'Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names'
                        type: string
                    required:
                    - kind
                    - name
                    type: object
                    x-kubernetes-map-type: atomic
                  updatePolicy:
                    description: Describes the rules on how changes are applied to the
                      pods. If not specified, all fields in the `PodUpdatePolicy` are
                      set to their default values.
                    properties:
                      minReplicas:
                        description: Minimal number of replicas which need to be alive
                          for Updater to attempt pod eviction (pending other checks like
                          PDB). Only positive values are allowed. Overrides global '--min-replicas'
                          flag.
                        format: int32
                        type: integer
                      updateMode:
                        description: Controls when autoscaler applies changes to the pod
                          resources. The default is 'Auto'.
                        enum:
                        - "Off"
                        - Initial
                        - Recreate
                        - Auto
                        type: string
                    type: object
                required:
                - targetRef
                type: object
              status:
                description: Current information about the autoscaler.
                properties:
                  conditions:
                    description: Conditions is the set of conditions required for this
                      autoscaler to scale its target, and indicates whether or not those
                      conditions are met.
                    items:
                      description: VerticalPodAutoscalerCondition describes the state
                        of a VerticalPodAutoscaler at a certain point.
                      properties:
                        lastTransitionTime:
                          description: lastTransitionTime is the last time the condition
                            transitioned from one status to another
                          format: date-time
                          type: string
                        message:
                          description: message is a human-readable explanation containing
                            details about the transition
                          type: string
                        reason:
                          description: reason is the reason for the condition's last transition.
                          type: string
                        status:
                          description: status is the status of the condition (True, False,
                            Unknown)
                          type: string
                        type:
                          description: type describes the current condition
                          type: string
                      required:
                      - status
                      - type
                      type: object
                    type: array
                  recommendation:
                    description: The most recently computed amount of resources recommended
                      by the autoscaler for the controlled pods.
                    properties:
                      containerRecommendations:
                        description: Resources recommended by the autoscaler for each
                          container.
                        items:
                          description: RecommendedContainerResources is the recommendation
                            of resources computed by autoscaler for a specific container.
                            Respects the container resource policy if present in the spec.
                            In particular the recommendation is not produced for containers
                            with `ContainerScalingMode` set to 'Off'.
                          properties:
                            containerName:
                              description: Name of the container.
                              type: string
                            lowerBound:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Minimum recommended amount of resources. Observes
                                ContainerResourcePolicy. This amount is not guaranteed
                                to be sufficient for the application to operate in a stable
                                way, however running with less resources is likely to
                                have significant impact on performance/availability.
                              type: object
                            target:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Recommended amount of resources. Observes ContainerResourcePolicy.
                              type: object
                            uncappedTarget:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: The most recent recommended resources target
                                computed by the autoscaler for the controlled pods, based
                                only on actual resource usage, not taking into account
                                the ContainerResourcePolicy. May differ from the Recommendation
                                if the actual resource usage causes the target to violate
                                the ContainerResourcePolicy (lower than MinAllowed or
                                higher that MaxAllowed). Used only as status indication,
                                will not affect actual resource assignment.
                              type: object
                            upperBound:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Maximum recommended amount of resources. Observes
                                ContainerResourcePolicy. Any resources allocated beyond
                                this value are likely wasted. This value may be larger
                                than the maximum amount of application is actually capable
                                of consuming.
                              type: object
                          required:
                          - target
                          type: object
                        type: array
                    type: object
                type: object
            required:
            - spec
            type: object
        served: true
        storage: true
        subresources: {}
      - deprecated: true
        deprecationWarning: autoscaling.k8s.io/v1beta2 API is deprecated
        name: v1beta2
        schema:
          openAPIV3Schema:
            description: VerticalPodAutoscaler is the configuration for a vertical pod
              autoscaler, which automatically manages pod resources based on historical
              and real time resource utilization.
            properties:
              apiVersion:
                description: 'APIVersion defines the versioned schema of this representation
                  of an object. Servers should convert recognized schemas to the latest
                  internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
                type: string
              kind:
                description: 'Kind is a string value representing the REST resource this
                  object represents. Servers may infer this from the endpoint the client
                  submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                type: string
              metadata:
                type: object
              spec:
                description: 'Specification of the behavior of the autoscaler. More info:
                  https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.'
                properties:
                  resourcePolicy:
                    description: Controls how the autoscaler computes recommended resources.
                      The resource policy may be used to set constraints on the recommendations
                      for individual containers. If not specified, the autoscaler computes
                      recommended resources for all containers in the pod, without additional
                      constraints.
                    properties:
                      containerPolicies:
                        description: Per-container resource policies.
                        items:
                          description: ContainerResourcePolicy controls how autoscaler
                            computes the recommended resources for a specific container.
                          properties:
                            containerName:
                              description: Name of the container or DefaultContainerResourcePolicy,
                                in which case the policy is used by the containers that
                                don't have their own policy specified.
                              type: string
                            maxAllowed:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Specifies the maximum amount of resources that
                                will be recommended for the container. The default is
                                no maximum.
                              type: object
                            minAllowed:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Specifies the minimal amount of resources that
                                will be recommended for the container. The default is
                                no minimum.
                              type: object
                            mode:
                              description: Whether autoscaler is enabled for the container.
                                The default is "Auto".
                              enum:
                              - Auto
                              - "Off"
                              type: string
                          type: object
                        type: array
                    type: object
                  targetRef:
                    description: TargetRef points to the controller managing the set of
                      pods for the autoscaler to control - e.g. Deployment, StatefulSet.
                      VerticalPodAutoscaler can be targeted at controller implementing
                      scale subresource (the pod set is retrieved from the controller's
                      ScaleStatus) or some well known controllers (e.g. for DaemonSet
                      the pod set is read from the controller's spec). If VerticalPodAutoscaler
                      cannot use specified target it will report ConfigUnsupported condition.
                      Note that VerticalPodAutoscaler does not require full implementation
                      of scale subresource - it will not use it to modify the replica
                      count. The only thing retrieved is a label selector matching pods
                      grouped by the target resource.
                    properties:
                      apiVersion:
                        description: API version of the referent
                        type: string
                      kind:
                        description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"'
                        type: string
                      name:
                        description: 'Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names'
                        type: string
                    required:
                    - kind
                    - name
                    type: object
                    x-kubernetes-map-type: atomic
                  updatePolicy:
                    description: Describes the rules on how changes are applied to the
                      pods. If not specified, all fields in the `PodUpdatePolicy` are
                      set to their default values.
                    properties:
                      updateMode:
                        description: Controls when autoscaler applies changes to the pod
                          resources. The default is 'Auto'.
                        enum:
                        - "Off"
                        - Initial
                        - Recreate
                        - Auto
                        type: string
                    type: object
                required:
                - targetRef
                type: object
              status:
                description: Current information about the autoscaler.
                properties:
                  conditions:
                    description: Conditions is the set of conditions required for this
                      autoscaler to scale its target, and indicates whether or not those
                      conditions are met.
                    items:
                      description: VerticalPodAutoscalerCondition describes the state
                        of a VerticalPodAutoscaler at a certain point.
                      properties:
                        lastTransitionTime:
                          description: lastTransitionTime is the last time the condition
                            transitioned from one status to another
                          format: date-time
                          type: string
                        message:
                          description: message is a human-readable explanation containing
                            details about the transition
                          type: string
                        reason:
                          description: reason is the reason for the condition's last transition.
                          type: string
                        status:
                          description: status is the status of the condition (True, False,
                            Unknown)
                          type: string
                        type:
                          description: type describes the current condition
                          type: string
                      required:
                      - status
                      - type
                      type: object
                    type: array
                  recommendation:
                    description: The most recently computed amount of resources recommended
                      by the autoscaler for the controlled pods.
                    properties:
                      containerRecommendations:
                        description: Resources recommended by the autoscaler for each
                          container.
                        items:
                          description: RecommendedContainerResources is the recommendation
                            of resources computed by autoscaler for a specific container.
                            Respects the container resource policy if present in the spec.
                            In particular the recommendation is not produced for containers
                            with `ContainerScalingMode` set to 'Off'.
                          properties:
                            containerName:
                              description: Name of the container.
                              type: string
                            lowerBound:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Minimum recommended amount of resources. Observes
                                ContainerResourcePolicy. This amount is not guaranteed
                                to be sufficient for the application to operate in a stable
                                way, however running with less resources is likely to
                                have significant impact on performance/availability.
                              type: object
                            target:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Recommended amount of resources. Observes ContainerResourcePolicy.
                              type: object
                            uncappedTarget:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: The most recent recommended resources target
                                computed by the autoscaler for the controlled pods, based
                                only on actual resource usage, not taking into account
                                the ContainerResourcePolicy. May differ from the Recommendation
                                if the actual resource usage causes the target to violate
                                the ContainerResourcePolicy (lower than MinAllowed or
                                higher that MaxAllowed). Used only as status indication,
                                will not affect actual resource assignment.
                              type: object
                            upperBound:
                              additionalProperties:
                                anyOf:
                                - type: integer
                                - type: string
                                pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                                x-kubernetes-int-or-string: true
                              description: Maximum recommended amount of resources. Observes
                                ContainerResourcePolicy. Any resources allocated beyond
                                this value are likely wasted. This value may be larger
                                than the maximum amount of application is actually capable
                                of consuming.
                              type: object
                          required:
                          - target
                          type: object
                        type: array
                    type: object
                type: object
            required:
            - spec
            type: object
        served: true
        storage: false

    1.22より前のKubernetesバージョン

    展開してCRDのYAMLテンプレートを表示

    apiVersion: apiextensions.k8s.io/v1beta1
    kind: CustomResourceDefinition
    metadata:
      name: verticalpodautoscalers.autoscaling.k8s.io
      annotations:
        "api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
    spec:
      group: autoscaling.k8s.io
      scope: Namespaced
      names:
        plural: verticalpodautoscalers
        singular: verticalpodautoscaler
        kind: VerticalPodAutoscaler
        shortNames:
          - vpa
      version: v1beta1
      versions:
        - name: v1beta1
          served: false
          storage: false
        - name: v1beta2
          served: true
          storage: true
        - name: v1
          served: true
          storage: false
      validation:
        # openAPIV3Schema is the schema for validating custom objects.
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              required: []
              properties:
                targetRef:
                  type: object
                updatePolicy:
                  type: object
                  properties:
                    updateMode:
                      type: string
                resourcePolicy:
                  type: object
                  properties:
                    containerPolicies:
                      type: array
                      items:
                        type: object
                        properties:
                          containerName:
                            type: string
                          controlledValues:
                            type: string
                            enum: ["RequestsAndLimits", "RequestsOnly"]
                          mode:
                            type: string
                            enum: ["Auto", "Off"]
                          minAllowed:
                            type: object
                          maxAllowed:
                            type: object
                          controlledResources:
                            type: array
                            items:
                              type: string
                              enum: ["cpu", "memory"]
    ---
    apiVersion: apiextensions.k8s.io/v1beta1
    kind: CustomResourceDefinition
    metadata:
      name: verticalpodautoscalercheckpoints.autoscaling.k8s.io
      annotations:
        "api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
    spec:
      group: autoscaling.k8s.io
      scope: Namespaced
      names:
        plural: verticalpodautoscalercheckpoints
        singular: verticalpodautoscalercheckpoint
        kind: VerticalPodAutoscalerCheckpoint
        shortNames:
          - vpacheckpoint
      version: v1beta1
      versions:
        - name: v1beta1
          served: false
          storage: false
        - name: v1beta2
          served: true
          storage: true
        - name: v1
          served: true
          storage: false
    kubectl apply -f crd.yaml
  3. ack-vertical-pod-autoscalerのadmission-controller、recommender、およびupdaterコンポーネントをインストールします。

    1.22以降および1.26以前のKubernetesバージョン

    インストールadmission-controller

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vpa-admission-controller
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: vpa-admission-controller
      template:
        metadata:
          labels:
            app: vpa-admission-controller
        spec:
          serviceAccountName: vpa-admission-controller
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534 # nobody
          containers:
            - name: admission-controller
              image: registry.cn-hangzhou.aliyuncs.com/acs/vpa-admission-controller:0.13.0
              imagePullPolicy: Always
              env:
                - name: NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
              volumeMounts:
                - name: tls-certs
                  mountPath: "/etc/tls-certs"
                  readOnly: true
              resources:
                limits:
                  cpu: 200m
                  memory: 500Mi
                requests:
                  cpu: 50m
                  memory: 200Mi
              ports:
                - containerPort: 8000
                - name: prometheus
                  containerPort: 8944
          volumes:
            - name: tls-certs
              secret:
                secretName: vpa-tls-certs
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: vpa-webhook
      namespace: kube-system
    spec:
      ports:
        - port: 443
          targetPort: 8000
      selector:
        app: vpa-admission-controller

    recommenderのインストール

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vpa-recommender
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: vpa-recommender
      template:
        metadata:
          labels:
            app: vpa-recommender
        spec:
          serviceAccountName: vpa-recommender
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534 # nobody
          containers:
          - name: recommender
            image: registry.cn-hangzhou.aliyuncs.com/acs/vpa-recommender:0.13.0
            imagePullPolicy: Always
            resources:
              limits:
                cpu: 200m
                memory: 1000Mi
              requests:
                cpu: 50m
                memory: 500Mi
            ports:
            - name: prometheus
              containerPort: 8942

    updaterのインストール

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vpa-updater
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: vpa-updater
     template:
        metadata:
          labels:
            app: vpa-updater
        spec:
          serviceAccountName: vpa-updater
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534 # nobody
          containers:
            - name: updater
              image: registry.cn-hangzhou.aliyuncs.com/acs/vpa-updater:0.13.0
              imagePullPolicy: Always
              env:
                - name: NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
              resources:
                limits:
                  cpu: 200m
                  memory: 1000Mi
                requests:
                  cpu: 50m
                  memory: 500Mi
              ports:
                - name: prometheus
                  containerPort: 8943

    1.22より前のKubernetesバージョン

    インストールadmission-controller

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vpa-admission-controller
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: vpa-admission-controller
      template:
        metadata:
          labels:
            app: vpa-admission-controller
        spec:
          serviceAccountName: admin
          containers:
            - name: admission-controller
              image: registry.cn-hangzhou.aliyuncs.com/acs/vpa-admission-controller:0.7.0
              imagePullPolicy: Always
              env:
                - name: NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
              volumeMounts:
                - name: tls-certs
                  mountPath: "/etc/tls-certs"
                  readOnly: true
              resources:
                limits:
                  cpu: 200m
                  memory: 500Mi
                requests:
                  cpu: 50m
                  memory: 200Mi
              ports:
                - containerPort: 8000
          volumes:
            - name: tls-certs
              secret:
                secretName: vpa-tls-certs
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: vpa-webhook
      namespace: kube-system
    spec:
      ports:
        - port: 443
          targetPort: 8000
      selector:
        app: vpa-admission-controller

    recommenderのインストール

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vpa-recommender
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: vpa-recommender
      template:
        metadata:
          labels:
            app: vpa-recommender
        spec:
          serviceAccountName: admin
          containers:
          - name: recommender
            image: registry.cn-hangzhou.aliyuncs.com/acs/vpa-recommender:0.7.0
            imagePullPolicy: Always
            resources:
              limits:
                cpu: 200m
                memory: 1000Mi
              requests:
                cpu: 50m
                memory: 500Mi
            ports:
            - containerPort: 8080

    updaterのインストール

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vpa-updater
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: vpa-updater
      template:
        metadata:
          labels:
            app: vpa-updater
        spec:
          serviceAccountName: admin
          containers:
            - name: updater
              image: registry.cn-hangzhou.aliyuncs.com/acs/vpa-updater:0.7.0
              imagePullPolicy: Always
              resources:
                limits:
                  cpu: 200m
                  memory: 1000Mi
                requests:
                  cpu: 50m
                  memory: 500Mi
              ports:
                - containerPort: 8080

ステップ2: VPAがインストールされていることを確認する

  1. 次のYAMLテンプレートを保存し、コマンドを実行してnginx-Deployment-basicという名前のdeploymentを作成します。

    展開して表示nginx-deployment-basic.yamlテンプレート

    説明

    デプロイの構成では、要求フィールドと制限フィールドを空のままにします。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment-basic
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
    kubectl apply -f nginx-deployment-basic.yaml
  2. 次のYAMLテンプレートを保存し、コマンドを実行してnginx-deployment-basic-VPAという名前のvpaリソースを作成します。

    展開して表示nginx-deployment-basic-vpa.yamlテンプレート

    説明

    必要に応じて、updateModeOffまたはAutoに設定できます。

    • オフ (推奨): ポッドリソース要求を推奨し、クラスターリソース消費に基づいて設定を制限しますが、ポッドリソースの設定は自動的に更新されません。

    • 自動: ポッドリソース要求を推奨し、クラスターリソース消費に基づいて設定を制限し、ポッドリソースの設定を自動的に更新します。

    apiVersion: autoscaling.k8s.io/v1
    kind: VerticalPodAutoscaler
    metadata:
      name: nginx-deployment-basic-vpa
    spec:
      targetRef:
        apiVersion: "apps/v1"
        kind:       Deployment
        name:       nginx-deployment-basic
      updatePolicy:
        updateMode: "Off" # Set to off.
    kubectl apply -f nginx-deployment-basic-vpa.yaml
  3. 次のコマンドを実行して、VPAがデプロイに推奨するCPUおよびメモリリソースの要求値を照会します。

    kubectl describe vpa nginx-deployment-basic-vpa

    予想される出力には約2分かかる場合があります。 次の出力は、推奨されるリソースリクエストの例を示します。

    展開して期待される出力を表示

      Recommendation:
        Container Recommendations:
          Container Name:  nginx
          Lower Bound:
            Cpu:     25m
            Memory:  262144k
          Target:
            Cpu:     25m
            Memory:  262144k
          Uncapped Target:
            Cpu:     25m
            Memory:  262144k
          Upper Bound:
            Cpu:     11601m
            Memory:  12128573170

    推奨事項に基づいて、デプロイのリソースリクエストを指定できます。 VPAは、デプロイメントのリソース使用状況を継続的に監視し、最適化の提案を提供します。

コンソールを使用してkubectlを使用してインストールされたVPAを管理する方法?

Kubernetes 1.26以降を実行するクラスターの場合、コンソールを使用してack-vertical-pod-autoscalerコンポーネントをインストールし、VPAを管理することを推奨します。 kubectlを使用してインストールした既存のVPAをアンインストールし、コンソールから再インストールして、新規VPAと既存のVPAの競合を回避する必要があります。

展開してプロシージャを表示

手順1: クラスターにデプロイされたVPAのアンインストール

クラスターにデプロイされたVPAをアンインストールします。これには、デプロイメント、RBAC権限、シークレット、CRD、サービスなどのリソースのクリアが含まれます。

  1. 次のnginx-deployment-basic-vpa.yaml例に示すように、既存のVPAのYAMLファイルのmetadataフィールドには、nameフィールドとnamespaceフィールドのみを保持し、その他の情報はすべて削除します。 さらに、statusフィールドの情報を削除します。 その後、このYAMLファイルを保存して以降の手順を実行します。

    apiVersion: autoscaling.k8s.io/v1
    kind: VerticalPodAutoscaler
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"autoscaling.k8s.io/v1","kind":"VerticalPodAutoscaler","metadata":{"annotations":{},"name":"nginx-deployment-basic-vpa","namespace":"default"},"spec":{"targetRef":{"apiVersion":"apps/v1","kind":"Deployment","name":"nginx-deployment-basic"},"updatePolicy":{"updateMode":"Off"}}}
      creationTimestamp: "2024-02-29T06:03:35Z"
      generation: 1
      name: nginx-deployment-basic-vpa
      namespace: default
      resourceVersion: "56264"
      uid: 9f128737-d12e-46f6-b254-c1a7505c19c6
    spec:
      targetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: nginx-deployment-basic
      updatePolicy:
        updateMode: "Off"
    status:
      conditions:
      - lastTransitionTime: "2024-02-29T06:03:55Z"
        status: "True"
        type: RecommendationProvided
      recommendation:
        containerRecommendations:
        - containerName: nginx
          lowerBound:
            cpu: 25m
            memory: 262144k
          target:
            cpu: 25m
            memory: 262144k
          uncappedTarget:
            cpu: 25m
            memory: 262144k
          upperBound:
            cpu: 25m
            memory: 262144k
    kubectl get vpa nginx-deployment-basic-vpa -oyaml
  2. 次のコマンドを実行して、VPAによってインストールされたリソースを削除します。

    // Delete Deployment and Service
    kubectl delete deployment vpa-admission-controller vpa-recommender vpa-updater -n kube-system
    kubectl delete svc vpa-webhook -n kube-system
    // Delete ClusterRole
    kubectl delete clusterrole system:metrics-reader system:vpa-actor system:vpa-status-actor system:vpa-checkpoint-actor system:evictioner system:vpa-target-reader  system:vpa-admission-controller system:vpa-status-reader
    // Delete ClusterRoleBinding
    kubectl delete clusterrolebinding system:metrics-reader system:vpa-actor system:vpa-status-actor system:vpa-checkpoint-actor system:vpa-target-reader-binding system:vpa-evictioner-binding system:vpa-admission-controller system:vpa-status-reader-binding
    // Delete ServiceAccount
    kubectl delete sa vpa-admission-controller vpa-recommender vpa-updater -n kube-system
    // Delete Secret
    kubectl delete secret vpa-tls-certs -n kube-system
    // Delete CRD
    kubectl delete crd verticalpodautoscalercheckpoints.autoscaling.k8s.io verticalpodautoscalers.autoscaling.k8s.io

ステップ2: Install the ack-vertical-pod-autoscaler component

  1. ACKコンソールにログインします。 左側のナビゲーションウィンドウで、[クラスター] をクリックします。

  2. [クラスター] ページで、管理するクラスターの名前をクリックします。 左側のナビゲーションウィンドウで、[操作] > [アドオン] を選択します。

  3. アドオンページで、ack-vertical-pod-autoscalerを見つけ、プロンプトに従ってインストールを完了します。

ステップ3: VPAのYAMLファイルの再デプロイ

次のコマンドを実行して、手順1: クラスターにデプロイされたVPAのアンインストールで保存されたYAMLファイルを再デプロイします。 このステップは例としてnginx-deployment-basic-vpa.yamlを使用します:

kubectl apply -f nginx-deployment-basic-vpa.yaml