Kubevirt 创建虚拟机

常用操作
kubectl get vms -o yaml testvm

virtctl start testvm

# Start the virtual machine:
kubectl virt start testvm

# Stop the virtual machine:
kubectl virt stop testvm
Alternatively you could use kubectl patch:

# Start the virtual machine:
kubectl patch virtualmachine testvm --type merge -p \
    '{"spec":{"running":true}}'

# Stop the virtual machine:
kubectl patch virtualmachine testvm --type merge -p \
    '{"spec":{"running":false}}'

kubectl get vmis
kubectl get vmis -o yaml testvm

virtctl console testvm
Disconnect from the virtual machine console by typing: ctrl+].

virtctl stop testvm

kubectl delete vm testvm

实例:
创建dv
kubectl-virt image-upload --image-path=/root/kubevirt/CentOS-7-x86_64-GenericCloud.qcow2 --pvc-name=jgpt --access-mode=ReadOnlyMany --pvc-size=40G --uploadproxy-url=https://10.102.182.17:443 --insecure --wait-secs=100 --storage-class=rook-ceph-block

创建vm
# cat jgpt-vm.yaml
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
  creationTimestamp: null
  generation: 1
  labels:
    kubevirt.io/os: linux
  name: jgpt
spec:
  running: true
  template:
    metadata:
      creationTimestamp: null
      labels:
        kubevirt.io/domain: jgpt
    spec:
      nodeSelector:
        kubernetes.io/hostname: 172.16.100.34
      domain:
        cpu:
          cores: 2
        devices:
          disks:
          - disk:
              bus: virtio
            name: disk0
          - cdrom:
              bus: sata
              readonly: true
            name: cloudinitdisk
        machine:
          type: q35
        resources:
          requests:
            memory: 4096M
      volumes:
      - name: disk0
        persistentVolumeClaim:
          claimName: jgpt
      - cloudInitNoCloud:
          userData: |
            #cloud-config
            hostname: jgpt
            ssh_pwauth: True
            disable_root: false
            ssh_authorized_keys:
              - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUL/dpkEf7HFIMU2nau6aP/CaYyriopLobWNU7DY1DwUdzEG+f5qlET4OflVKdtgos7s3aSNinoRgMoO9c5xNuq1KZWfh3RAw5v6VLUqHqaoeekkQqfkLHKhaVoksriSUIBpMRInZTABr/lCafoBrv+vlX80oB5SL2evNrDi30tXmuiI+LQHgeQAjI+fOJYyIjiBh9ULgXmNEcA6ZpeBldrOQgw/lJuTl78aP0feTEJOvUmAkCfKzYbP+8PQKsirvK+chfSHWJGhGXmpReUIvhz0MSp9ApLq9pwYI1XBXzOhq77nE6K/YHI6xbUCnKIKEerUfjcMu+5Ri4hjOMxQV7 root@home.tang.com
        name: cloudinitdisk

# cat jgpt-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: jgpt-1889
  namespace: default
spec:
  ports:
  - name: http
    port: 1889
    protocol: TCP
    targetPort: 1889
  - name: tcp
    port: 6808
    protocol: TCP
    targetPort: 6808
  - name: tcp2
    port: 9000
    protocol: TCP
    targetPort: 9000
  - name: ssh
    port: 22
    protocol: TCP
    targetPort: 22
  selector:
    kubevirt.io/domain: jgpt
  sessionAffinity: None

kubectl apply -f jgpt-vm.yaml
kubectl apply -f jgpt-service.yaml