11.4. 部署虚拟机


安装并激活 OpenShift Virtualization 和 Containerized Data Importer (CDI) 后,创建一个命名空间并部署虚拟机 (VM)。

流程

  • 部署 YAML,它将创建虚拟机定义和一个包含 Fedora 操作系统的数据卷。

    在以下示例中,使用命名空间 mig-vm,并使用以下 YAML 来创建 Fedora 虚拟机,并创建包含 Fedora 操作系统的 datavolume:

    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
      name: rhel9-lime-damselfly-72
      namespace: mig-vm 
    1
    
      labels:
        app: rhel9-lime-damselfly-72
        kubevirt.io/dynamic-credentials-support: 'true'
        vm.kubevirt.io/template: rhel9-server-small
        vm.kubevirt.io/template.namespace: openshift
        vm.kubevirt.io/template.revision: '1'
        vm.kubevirt.io/template.version: v0.31.1
    spec:
      dataVolumeTemplates:
        - apiVersion: cdi.kubevirt.io/v1beta1
          kind: DataVolume
          metadata:
            name: rhel9-lime-damselfly-72
          spec:
            sourceRef:
              kind: DataSource
              name: rhel9
              namespace: openshift-virtualization-os-images
            storage:
              resources:
                requests:
                  storage: 30Gi
      running: true 
    2
    
      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-lime-damselfly-72 
    3
    
            kubevirt.io/size: small
            network.kubevirt.io/headlessService: headless
        spec:
          architecture: amd64
          domain:
            cpu:
              cores: 1
              sockets: 1
              threads: 1
            devices:
              disks:
                - disk:
                    bus: virtio
                  name: rootdisk
                - disk:
                    bus: virtio
                  name: cloudinitdisk
              interfaces:
                - masquerade: {}
                  model: virtio
                  name: default
              rng: {}
            features:
              acpi: {}
              smm:
                enabled: true
            firmware:
              bootloader:
                efi: {}
            machine:
              type: pc-q35-rhel9.4.0
            memory:
              guest: 2Gi
            resources: {}
          networks:
            - name: default
              pod: {}
          terminationGracePeriodSeconds: 180
          volumes:
            - dataVolume:
                name: rhel9-lime-damselfly-72
              name: rootdisk
            - cloudInitNoCloud:
                userData: |-
                  #cloud-config
                  user: cloud-user
                  password: password
                  chpasswd: { expire: False }
              name: cloudinitdisk
    Copy to Clipboard Toggle word wrap
1
在本例中,使用命名空间 mig-vm
2
使用 running: true 来表示虚拟机在创建后应启动。
3
数据卷创建一个名为 rhel9-lime-damselfly-72 的持久性卷声明 (PVC),它与数据卷的名称相同。

持久性卷 (PV) 由操作系统填充,虚拟机已启动。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat