0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenShift Virtualization (OCP-V) - Edit VM - CPU

Last updated at Posted at 2025-04-25

OpenShift Virtualization

Red Hat® OpenShift® Virtualization は Red Hat OpenShift に含まれる機能であり、組織が新規および既存の仮想マシン (VM) ワークロードを実行およびデプロイするための先進的なプラットフォームを提供します。このソリューションにより、従来の仮想マシンを、信頼できる、一貫した包括的なハイブリッドクラウド・アプリケーション・プラットフォームに簡単に移行できます。

OpenShift Virtualization は、VM の移行を単純化するとともに、クラウドネイティブ・アプリケーション・プラットフォームのシンプルさと速度を利用してインフラストラクチャのモダナイゼーションの道筋を提供します。また、先進的な管理の原則を取り入れつつ既存の仮想化への投資を維持することを目指しており、Red Hat の包括的な仮想化ソリューションの基盤となります。

Edit VM

OCP 4.17 Bare Metal 環境 OpenShift Virtualization (OCP-V) で Virtual Machine (VM) を編集してみます。ここでは以下の手順を参考に、作成済み VM を編集します。

Editing virtual machines

CPU

OCP Console から VM 再起動無しで動的に CPU 構成の変更をする事が出来ますが、変更反映時に Live Migration が行われます。また、手動での VM 再起動が必要なものもあります。

Hot plugging CPUs on a virtual machine

なお、Live Migration を伴う動的な編集には CPU Toplogy に関連する以下の制限があります。

Updates to the sockets value are applied immediately.
To apply changes to the cores or threads values, you must restart the VirtualMachine.

OCP Console
Live Migration 可能な VM
Add CPU

以下の VM を編集してみます。この VM は Live Migration 可能な状態で worker02 で稼働しています。

image.png

$ oc get pod,vmi,vm -o wide
NAME                                            READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
pod/virt-launcher-rhel9-custom01-upload-q6vfr   1/1     Running   0          57s   10.130.2.21   worker02   <none>           1/1

NAME                                                       AGE   PHASE     IP            NODENAME   READY   LIVE-MIGRATABLE   PAUSED
virtualmachineinstance.kubevirt.io/rhel9-custom01-upload   57s   Running   10.130.2.21   worker02   True    True

NAME                                                       AGE   STATUS    READY
virtualmachine.kubevirt.io/rhel9-custom01-upload           18d   Running   True

なお、現在の CPU / Memory 設定は、画面表示の他に VirtualMachineInstance を参照する事もできます。

$ oc -o json get vmi rhel9-custom01-upload | jq -r '.status | .currentCPUTopology, .memory'
{
  "cores": 1,
  "sockets": 1,
  "threads": 1
}
{
  "guestAtBoot": "2Gi",
  "guestCurrent": "2Gi",
  "guestRequested": "2Gi"
}

Configuration Tab から vCPU 12 に変更してみます。

image.png

画面上部に以下が表示され、Socket への変更は Live Migration による即時反映、Core Threads への変更は VM の再起動が必要な事が分かります。

Updates to the sockets value are applied immediately.
To apply changes to the cores or threads values, you must restart the VirtualMachine.

今回の変更では Topology will be set to 2 socket, 1 core, 1 thread と表示され、CPU Topology が自動的に選択された事が分かります。

Save ボタンを押すと Live Migration が実行され、即時に VM が更新されます。VM は worker01Live Migration された事が分かります。

image.png

CLI で確認すると、編集前の VM Pod が Completed Status で残存していることが分かります。

$ oc get pod,vmi,vm -o wide
NAME                                            READY   STATUS      RESTARTS   AGE     IP             NODE       NOMINATED NODE   READINESS GATES
pod/virt-launcher-rhel9-custom01-upload-9rqd4   1/1     Running     0          2m21s   10.129.2.195   worker01   <none>           1/1
pod/virt-launcher-rhel9-custom01-upload-q6vfr   0/1     Completed   0          10m     10.130.2.21    worker02   <none>           1/1

NAME                                                       AGE   PHASE     IP             NODENAME   READY   LIVE-MIGRATABLE   PAUSED
virtualmachineinstance.kubevirt.io/rhel9-custom01-upload   10m   Running   10.129.2.195   worker01   True    True

NAME                                                       AGE   STATUS    READY
virtualmachine.kubevirt.io/rhel9-custom01-upload           18d   Running   True

Pod Manifest を参照すると CPU Request (.spec.containers[].resources.requests.cpu) が変更されたことが分かります。

$ oc -o json get pod | jq -r '.items[] | .metadata.name, .spec.containers[].resources'
virt-launcher-rhel9-custom01-upload-9rqd4
{
  "limits": {
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1"
  },
  "requests": {
    "cpu": "200m",
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1",
    "ephemeral-storage": "50M",
    "memory": "2302Mi"
  }
}
virt-launcher-rhel9-custom01-upload-q6vfr
{
  "limits": {
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1"
  },
  "requests": {
    "cpu": "100m",
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1",
    "ephemeral-storage": "50M",
    "memory": "2294Mi"
  }
}
Remove CPU

CPU を削除する場合は VM の再起動が必要です。例えば、今回の例で vCPU を 2 から 1 に戻す編集を行うと、以下のようなメッセージが表示されます。
image.png

また、Status conditionsRestartRequired が追加されます。
image.png

Live Migration 不可能な VM

以下の VM を編集してみます。この VM は Live Migration 不可能な状態 (Not migratable)worker02 で稼働しています。

image.png

Not migratable にするために、PVC の Access Mode を ReadWriteOnce (RWO) に設定しています。
image.png

$ oc get pod,vmi,vm,pvc -o wide
NAME                                                    READY   STATUS    RESTARTS   AGE    IP            NODE       NOMINATED NODE   READINESS GATES
pod/virt-launcher-rhel9-custom01-not-migratable-wl9tm   1/1     Running   0          65s   10.130.2.35   worker02   <none>           1/1

NAME                                                               AGE    PHASE     IP            NODENAME   READY   LIVE-MIGRATABLE   PAUSED
virtualmachineinstance.kubevirt.io/rhel9-custom01-not-migratable   65s   Running    10.130.2.35   worker02   True    False

NAME                                                       AGE   STATUS    READY
virtualmachine.kubevirt.io/rhel9-custom01-not-migratable   24h   Running   True

NAME                                                    STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS                                 VOLUMEATTRIBUTESCLASS   AGE   VOLUMEMODE
persistentvolumeclaim/rhel9-custom01-not-migratable     Bound    pvc-747519ea-491d-4647-bc2c-b57cdab482ad   30Gi       RWO            ocs-storagecluster-ceph-rbd                  <unset>                 24h   Block

Configuration Tab から vCPU 12 に変更してみます。

image.png

Live Migration 可能な VM の場合と同様の情報が表示されます。

NOT CORRECT
Save ボタンを押すと 画面上では CPU が 2 と表示されますが、Pending changes のメッセージによって VM の更新が一時停止している事が分かります。

CORRECT
Save ボタンを押すと 画面上では CPU が 2 と表示されますが、特にメッセージ等は表示されず、VM も稼働を継続したままです。

image.png

また、Status conditionsHotVCPUChange True が追加されます。

image.png

この時点で、Pod は CPU 1 で継続して稼働しています。

$  oc get pod -o wide
NAME                                                READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
virt-launcher-rhel9-custom01-not-migratable-wl9tm   1/1     Running   0          11m   10.130.2.35   worker02   <none>           1/1

$ oc -o json get pod | jq -r '.items[] | .metadata.name, .spec.containers[].resources'
virt-launcher-rhel9-custom01-not-migratable-wl9tm
{
  "limits": {
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1"
  },
  "requests": {
    "cpu": "100m",
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1",
    "ephemeral-storage": "50M",
    "memory": "2294Mi"
  }
}

$ oc -o json get vmi rhel9-custom01-not-migratable | jq -r '.status | .currentCPUTopology, .memory'
{
  "cores": 1,
  "sockets": 1,
  "threads": 1
}
{
  "guestAtBoot": "2Gi",
  "guestCurrent": "2Gi",
  "guestRequested": "2Gi"
}

VM を再起動する事で、更新を反映させます。

image.png

image.png

新しい Pod が起動され、CPU が 2 (200m) に変更されている事が分かります。

$ oc get pod -o wide
NAME                                                READY   STATUS    RESTARTS   AGE     IP            NODE       NOMINATED NODE   READINESS GATES
virt-launcher-rhel9-custom01-not-migratable-b5xkp   1/1     Running   0          2m19s   10.130.2.42   worker02   <none>           1/1

$ oc -o json get pod | jq -r '.items[] | .metadata.name, .spec.containers[].resources'
virt-launcher-rhel9-custom01-not-migratable-b5xkp
{
  "limits": {
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1"
  },
  "requests": {
    "cpu": "200m",
    "devices.kubevirt.io/kvm": "1",
    "devices.kubevirt.io/tun": "1",
    "devices.kubevirt.io/vhost-net": "1",
    "ephemeral-storage": "50M",
    "memory": "2302Mi"
  }
}

$ oc -o json get vmi rhel9-custom01-not-migratable | jq -r '.status | .currentCPUTopology, .memory'
{
  "cores": 1,
  "sockets": 2,
  "threads": 1
}
{
  "guestAtBoot": "2Gi",
  "guestCurrent": "2Gi",
  "guestRequested": "2Gi"
}
CLI

VirtualMachine Manifest を編集する事で、OCP Console 同等の操作を行う事が出来ます。

Editing a virtual machine by using the command line

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?