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 仮想マシンにlabel付与

0
Last updated at Posted at 2026-10-04

Openshiftにおいて仮想マシンにラベルを付与する際にマニフェストのどこにlabelを付与するかによって挙動の違いがあるようだったので整理する

環境

Openshift4.18.42
OpenshiftVirtualization4.18.36

検証

・label付与対象はVirtualMachineのマニフェスト
・付与する位置はmetadata.labelあるいはspec.template.metadataの2パターン

1.metadata.labelにlabelを付与

以下のようにVirtualMachineにlabelを付与します

metadata:
  (...snip)
  labels:
    app: rhel9-scarlet-crab-76
    kubevirt.io/dynamic-credentials-support: 'true'
    test: true

仮想マシンを確認するとlabelが付与されていた。
image.png
しかしVirtlauncherPodを見るとlabelは付与されていなかった。
image.png
仮想マシンを再起動しても変わらずでった
image.png

2.spec.template.metadataにlabelを付与

以下のようにVirtualMachineにlabelを付与します

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  (..snip)
spec:
 (...snip)
  template:
    metadata:
      annotations:
        vm.kubevirt.io/flavor: small
        vm.kubevirt.io/os: rhel9
        vm.kubevirt.io/workload: server
      creationTimestamp: null
      labels:
        kubevirt.io/domain: rhel9-scarlet-crab-76
        kubevirt.io/size: small
        network.kubevirt.io/headlessService: headless
        test2: 'true'

仮想マシンを確認 labelは付与されていない
image.png
VM Podにを付与されず
image.png

仮想マシン再起動
仮想マシンは変わらず
image.png
VM Podにラベルが付与
image.png
*VMの再起動を行いVirtlauncherPodの再作成が行われその際にlabelが付与されていそう

結果

VM側へloabelを反映させるにはmetadata.labelに記載
VM podへlabelを反映させるにはspec.template.metadataに記載しなおかつVMの再起動を行う必要がある
再起動させたくない場合は,VM podへ直接labelを付与すればよい

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?