给kubevirt创建虚拟机镜像

2023-08-21 13:23:14 浏览数 (1)

安装kubevirt之后需要制作虚拟机,目前官方文档太简洁不易看懂,这里翻出以前用过的文档

(1)registryDisk 方式

kubevirt提供了registryDisk的base docker image registry-disk-v1alpha

1 . 准备raw或者qcow2格式的虚拟机镜像,例如Windows---server-2012-datacenter-64bit-cn-syspreped---2018-01-15.qcow2

2 . 创建Dockerfile

FROM kubevirt/registry-disk-v1alpha

MAINTAINER "MinMin" <rmm0811@gmail.com># Add alpine image COPY Windows---server-2012-datacenter-64bit-cn-syspreped---2018-01-15.qcow2 /disk/windows2012dc.img

3 . 创建image

docker build -t windows2012dc:latest ./ docker push windows2012dc:latest

(1)使用pvc方式

kubevirt还未支持blockmode PVC,此处仅介绍file方式的。kubevirt中创建虚拟机是以pod空间中的/disk/目录下,那么意味着需要将PVC实现进行文件系统格式化,并创建disk/目录将 虚拟机root disk image拷贝至disk目录中

cat >Dockerfile <<EOF FROM kubevirt/container-disk-v1alpha ADD fedora32.qcow2 /disk/ EOF

docker build -t kubevirt/fedora-sriov-testing:latest .

一个可用的虚拟机模板:

代码语言:javascript复制
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
  name: centos
spec:
  running: false
  template:
    metadata:
      labels:
        kubevirt.io/size: small
        kubevirt.io/domain: centos
    spec:
      domain:
        devices:
          disks:
          - disk:
              bus: virtio
            name: rootfs
          - name: emptydisk
            disk:
              bus: virtio
          - name: host-disk
            disk:
              bus: virtio
          - disk:
              bus: virtio
            name: cloudinit
          interfaces:
          - name: default
            bridge: {}
        resources:
          requests:
            memory: 512M
      networks:
      - name: default
        pod: {}
      volumes:
        - name: rootfs
          containerDisk:
            image: heishui/centos:new
        - name: emptydisk
          emptyDisk:
            capacity: "20Gi"
        - hostDisk:
            capacity: "20Gi"
            path: /data/disk.img
            type: DiskOrCreate
          name: host-disk
        - name: cloudinit
          cloudInitNoCloud:
            userData: |-
              #cloud-config
              password: centos
              chpasswd: { expire: False }

0 人点赞