KubeVirt副本集

一、简介

VirtualMachineInstanceReplicaSet(vmis)确保指定数量的 VirtualMachineInstance(vmi) 副本在任何时候都在运行。
我们可以这样理解,vmis就是kubernetes(k8s)里面的控制器(DeployMent,ReplicaSet)管理我们pod的副本数,实现扩缩容、回滚等。也可以借助HorizontalPodAutoscaler(hpa)实现弹性伸缩。这里我们就说vmis控制器,在这里的vmis控制器,管理我们vmi虚拟机实例的副本数,也可以实现扩缩容,借助hpa实现弹性伸缩。所有yaml文件写法原理都类似。

当需要许多相同的虚拟机,并且不关心在虚拟机终止后任何磁盘状态时。
因此使用VirtualMachineInstanceReplicaSet意味者虚拟机磁盘无法在虚拟机回收后无法保存。

Note: The base assumption is that referenced disks are read-only or that the VMIs are writing internally to a tmpfs. The most obvious volume sources for VirtualMachineInstanceReplicaSets which KubeVirt supports are referenced below. If other types are used data corruption is possible.

Using VirtualMachineInstanceReplicaSet is the right choice when one wants many identical VMs and does not care about maintaining any disk state after the VMs are terminated.

官方推荐数据存储类型如下:

  • cloudInitNoCloud
  • ephemeral
  • containerDisk
  • emptyDisk
  • configMap
  • secret
  • any other type, if the VMI writes internally to a tmpfs

二、创建 VirtualMachineInstanceReplicaSet

apiVersion: kubevirt.io/v1
kind: VirtualMachineInstanceReplicaSet
metadata:
  name: centos
  namespace: vlan
spec:
  replicas: 3
  selector:
    matchLabels:
      kubevirt.io/vmReplicaSet: vmi-replicaset-cirros
  template:
    metadata:
      labels:
        kubevirt.io/vmReplicaSet: vmi-replicaset-cirros
    spec:
      domain:
        devices:
          disks:
            - disk:
                bus: virtio
              name: cdromiso
            - disk:
                bus: virtio
              name: cloudinitdisk
          interfaces:
            - bridge: {}
              name: default
        machine:
          type: q35
        resources:
          requests:
            memory: 2Gi
      networks:
        - name: default
          pod: {}
      volumes:
        - name: cdromiso
          containerDisk:
            image: harbor.mrlch.cn/kubevirt/centos:7.9
        - cloudInitNoCloud:
            networkData: |-
              network:
                version: 1
                config:
                  - type: physical
                    name: eth0
                    subnets:
                      - type: dhcp
            userData: |-
              #cloud-config
              disable_root: false
              ssh_pwauth: true
              users:
                - default
                - name: root
                  lock_passwd: false
                  hashed_passwd: $1$4t.w.u.X$BkdPjEOi30r85GpIaTZ8C1
          name: cloudinitdisk
[root@192 vlan]# kubectl get vmi -A
NAMESPACE   NAME          AGE   PHASE     IP               NODENAME         READY
vlan        centos5t29p   15m   Running   192.168.10.223   192.168.10.102   True
vlan        centosrskrs   15m   Running   192.168.10.222   192.168.10.102   True
vlan        centoswgn28   15m   Running   192.168.10.221   192.168.10.102   True

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code