searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

kubevirt虚机生命周期状态管理

2023-09-26 01:00:28
167
0

1.状态枚举(参考0.51.0版本)

1.1 vm状态(源码枚举)

// VirtualMachineStatusStopped indicates that the virtual machine is currently stopped and isn't expected to start.
VirtualMachineStatusStopped VirtualMachinePrintableStatus = "Stopped"
// VirtualMachineStatusProvisioning indicates that cluster resources associated with the virtual machine
// (e.g., DataVolumes) are being provisioned and prepared.
VirtualMachineStatusProvisioning VirtualMachinePrintableStatus = "Provisioning"
// VirtualMachineStatusStarting indicates that the virtual machine is being prepared for running.
VirtualMachineStatusStarting VirtualMachinePrintableStatus = "Starting"
// VirtualMachineStatusRunning indicates that the virtual machine is running.
VirtualMachineStatusRunning VirtualMachinePrintableStatus = "Running"
// VirtualMachineStatusPaused indicates that the virtual machine is paused.
VirtualMachineStatusPaused VirtualMachinePrintableStatus = "Paused"
// VirtualMachineStatusStopping indicates that the virtual machine is in the process of being stopped.
VirtualMachineStatusStopping VirtualMachinePrintableStatus = "Stopping"
// VirtualMachineStatusTerminating indicates that the virtual machine is in the process of deletion,
// as well as its associated resources (VirtualMachineInstance, DataVolumes, …).
VirtualMachineStatusTerminating VirtualMachinePrintableStatus = "Terminating"
// VirtualMachineStatusCrashLoopBackOff indicates that the virtual machine is currently in a crash loop waiting to be retried.
VirtualMachineStatusCrashLoopBackOff VirtualMachinePrintableStatus = "CrashLoopBackOff"
// VirtualMachineStatusMigrating indicates that the virtual machine is in the process of being migrated
// to another host.
VirtualMachineStatusMigrating VirtualMachinePrintableStatus = "Migrating"
// VirtualMachineStatusUnknown indicates that the state of the virtual machine could not be obtained,
// typically due to an error in communicating with the host on which it's running.
VirtualMachineStatusUnknown VirtualMachinePrintableStatus = "Unknown"
// VirtualMachineStatusUnschedulable indicates that an error has occurred while scheduling the virtual machine,
// e.g. due to unsatisfiable resource requests or unsatisfiable scheduling constraints.
VirtualMachineStatusUnschedulable VirtualMachinePrintableStatus = "ErrorUnschedulable"
// VirtualMachineStatusErrImagePull indicates that an error has occured while pulling an image for
// a containerDisk VM volume.
VirtualMachineStatusErrImagePull VirtualMachinePrintableStatus = "ErrImagePull"
// VirtualMachineStatusImagePullBackOff indicates that an error has occured while pulling an image for
// a containerDisk VM volume, and that kubelet is backing off before retrying.
VirtualMachineStatusImagePullBackOff VirtualMachinePrintableStatus = "ImagePullBackOff"
// VirtualMachineStatusPvcNotFound indicates that the virtual machine references a PVC volume which doesn't exist.
VirtualMachineStatusPvcNotFound VirtualMachinePrintableStatus = "ErrorPvcNotFound"
// VirtualMachineStatusDataVolumeNotFound indicates that the virtual machine references a DataVolume volume which doesn't exist.
VirtualMachineStatusDataVolumeNotFound VirtualMachinePrintableStatus = "ErrorDataVolumeNotFound"
// VirtualMachineStatusDataVolumeError indicates that an error has been reported by one of the DataVolumes
// referenced by the virtual machines.
VirtualMachineStatusDataVolumeError VirtualMachinePrintableStatus = "DataVolumeError"
// VirtualMachineStatusWaitingForVolumeBinding indicates that some PersistentVolumeClaims backing
// the virtual machine volume are still not bound.
VirtualMachineStatusWaitingForVolumeBinding VirtualMachinePrintableStatus = "WaitingForVolumeBinding"

 

1.2 vmi状态(源码枚举)

//When a VirtualMachineInstance Object is first initialized and no phase, or Pending is present.
VmPhaseUnset VirtualMachineInstancePhase = ""
// Pending means the VirtualMachineInstance has been accepted by the system.
Pending VirtualMachineInstancePhase = "Pending"
// A target Pod exists but is not yet scheduled and in running state.
Scheduling VirtualMachineInstancePhase = "Scheduling"
// A target pod was scheduled and the system saw that Pod in runnig state.
// Here is where the responsibility of virt-controller ends and virt-handler takes over.
Scheduled VirtualMachineInstancePhase = "Scheduled"
// Running means the pod has been bound to a node and the VirtualMachineInstance is started.
Running VirtualMachineInstancePhase = "Running"
// Succeeded means that the VirtualMachineInstance stopped voluntarily, e.g. reacted to SIGTERM or shutdown was invoked from
// inside the VirtualMachineInstance.
Succeeded VirtualMachineInstancePhase = "Succeeded"
// Failed means that the vmi crashed, disappeared unexpectedly or got deleted from the cluster before it was ever started.
Failed VirtualMachineInstancePhase = "Failed"
// Unknown means that for some reason the state of the VirtualMachineInstance could not be obtained, typically due
// to an error in communicating with the host of the VirtualMachineInstance.
Unknown VirtualMachineInstancePhase = "Unknown"

 

2. vm/vmi各状态具体判断条件/转换操作

 

vm状态
判断条件

CrashLoopBackOff

1.开机失败

2.失败次数大于0

3.运行策略为一直在运行或者失败重试

Stopped

1.vmi为关机或崩溃状态(Failed/Succeeded)

Provisioning

1.绑定了pvc的datavolumn没有准备好

WaitingForVolumeBinding

1.pvc状态为未绑定

Starting

1.vmi状态为Pending或者空

2.vmi状态为Scheduling

3.vmi状态为Scheduled

Running 1.vmi状态为Running
Paused

1.vmi状态为Running

2.vmi有Paused的condition,Paused一般为宿主机问题,例如存储空间不足等

Stopping

1.vmi不为关机或崩溃状态(Failed/Succeeded)

2.vmi未被标记为删除或者期望删除

Terminating

1.vm.ObjectMeta.DeletionTimestamp不为空

Migrating

1.根据vmi.Status.MigrationState的开始和结束时间,判断现在状态是否在迁移中

ErrorUnschedulable

1.vmi状态为Pending

vmi的condition中的PodScheduled为false,且原因为Unschedulable,pod不可调度,原因包括资源不足或调度限制

ErrImagePull

1.vmi状态为Scheduling
vmi的condition中的Synchronized为false,且原因为ErrImagePull,拉镜像错误
ImagePullBackOff

1.vmi状态为Scheduling

vmi的condition中的Synchronized为false,且原因为ImagePullBackOff,拉镜像错误且重试前kubelet崩溃

ErrorPvcNotFound

1.vmi状态为Pending

vmi的condition中的Synchronized为false,且原因为

FailedPvcNotFound,无时间限制,vmi事件触发更新,按照队列进行更新

ErrorDataVolumeNotFound

1.vmi状态为Pending

vmi的condition中的Synchronized为false,且原因为

FailedDataVolumeNotFound,无时间限制,vmi事件触发更新,按照队列进行更新

DataVolumeError

1.vmi状态为Pending

只要vm关联的dv有一个Status.Phase为Failed,或者dv的condition的Running为false

 

vmi原始状态
判断条件
vmi状态转换/操作
pending/空 pod存在,且不为临时pod

Scheduling

  vmi删除时间不为空/关联的dv有一个没有ready(Status.Phase为WaitForFirstConsumer)

Failed

  关联有dv为ready状态,存在临时pod(annotation:kubevirt.io/ephemeral-provisioning不为空),且pod状态为failed/容器状态为Terminated/pod标记删除 Failed
  同步pod/dv信息及状态失败,且失败原因为pvcNotFound/

DataVolumeNotFound

添加condition (PodReasonUnschedulable)

Scheduling

查看镜像错误,失败原因为ErrImagePull/ImagePullBackOff

其他同步错误(pod QOs正常分配/热插拔准备成功/磁盘状态ok)

Scheduling

  pod状态ready且未被标记删除,且无任何同步错误

Scheduled

  pod状态为failed/容器状态为Terminated/pod标记删除 Failed
  pod不存在/pod为临时pod Failed

Failed/Succeeded

  清空所有关联pod

状态为Scheduled后由virt-handler接管将按照队列更新状态(每当有操作时将虚机放入队列)

Scheduled

无domain,无socket,无pod/vmi 重新丢回队列
 
无domain,virt-launcher找不到,vmi状态一直停留 Failed
  无domain,其余情况

Scheduled

domain状态shutoff/crash 原因为crash/panic Failed
  原因为destroy且ACPI不可用 Failed
  原因为destroy且ACPI可用

Succeeded

  原因为shutdown/saved/fromSnapshot

Succeeded

  原因为migrated 保留原状态
domain状态Running/Paused/Blocked/PMSuspended   Running

 

3. 虚机各阶段状态管理与变化 

 

虚拟机创建分为创建DataVolume和VMI两个流程:

1. 创建DataVolume后,CDI组件创建对应的PVC并且关联到合适的PV,然后通过临时Importer Pod拉取虚拟机容器镜像绑定到DataVolume生成的PV中,并且将镜像转换成disk.img文件存储在PV中供虚拟机使用。

2. 创建VMI后,等待disk.img转换成功,然后在对应的Node上启动Launcher Pod,并将CDI流程生成的PV挂载到Pod内,当做虚拟机启动的系统盘。Launcher根据VMI的定义生成定义虚拟机的XML文件,然后调用libvirt进程调用Qemu命令创建并且启动虚拟机。VMI会对Launcher Pod状态进行同步,反应VM运行的状态。

0条评论
0 / 1000
黄****涛
2文章数
0粉丝数
黄****涛
2 文章 | 0 粉丝
黄****涛
2文章数
0粉丝数
黄****涛
2 文章 | 0 粉丝
原创

kubevirt虚机生命周期状态管理

2023-09-26 01:00:28
167
0

1.状态枚举(参考0.51.0版本)

1.1 vm状态(源码枚举)

// VirtualMachineStatusStopped indicates that the virtual machine is currently stopped and isn't expected to start.
VirtualMachineStatusStopped VirtualMachinePrintableStatus = "Stopped"
// VirtualMachineStatusProvisioning indicates that cluster resources associated with the virtual machine
// (e.g., DataVolumes) are being provisioned and prepared.
VirtualMachineStatusProvisioning VirtualMachinePrintableStatus = "Provisioning"
// VirtualMachineStatusStarting indicates that the virtual machine is being prepared for running.
VirtualMachineStatusStarting VirtualMachinePrintableStatus = "Starting"
// VirtualMachineStatusRunning indicates that the virtual machine is running.
VirtualMachineStatusRunning VirtualMachinePrintableStatus = "Running"
// VirtualMachineStatusPaused indicates that the virtual machine is paused.
VirtualMachineStatusPaused VirtualMachinePrintableStatus = "Paused"
// VirtualMachineStatusStopping indicates that the virtual machine is in the process of being stopped.
VirtualMachineStatusStopping VirtualMachinePrintableStatus = "Stopping"
// VirtualMachineStatusTerminating indicates that the virtual machine is in the process of deletion,
// as well as its associated resources (VirtualMachineInstance, DataVolumes, …).
VirtualMachineStatusTerminating VirtualMachinePrintableStatus = "Terminating"
// VirtualMachineStatusCrashLoopBackOff indicates that the virtual machine is currently in a crash loop waiting to be retried.
VirtualMachineStatusCrashLoopBackOff VirtualMachinePrintableStatus = "CrashLoopBackOff"
// VirtualMachineStatusMigrating indicates that the virtual machine is in the process of being migrated
// to another host.
VirtualMachineStatusMigrating VirtualMachinePrintableStatus = "Migrating"
// VirtualMachineStatusUnknown indicates that the state of the virtual machine could not be obtained,
// typically due to an error in communicating with the host on which it's running.
VirtualMachineStatusUnknown VirtualMachinePrintableStatus = "Unknown"
// VirtualMachineStatusUnschedulable indicates that an error has occurred while scheduling the virtual machine,
// e.g. due to unsatisfiable resource requests or unsatisfiable scheduling constraints.
VirtualMachineStatusUnschedulable VirtualMachinePrintableStatus = "ErrorUnschedulable"
// VirtualMachineStatusErrImagePull indicates that an error has occured while pulling an image for
// a containerDisk VM volume.
VirtualMachineStatusErrImagePull VirtualMachinePrintableStatus = "ErrImagePull"
// VirtualMachineStatusImagePullBackOff indicates that an error has occured while pulling an image for
// a containerDisk VM volume, and that kubelet is backing off before retrying.
VirtualMachineStatusImagePullBackOff VirtualMachinePrintableStatus = "ImagePullBackOff"
// VirtualMachineStatusPvcNotFound indicates that the virtual machine references a PVC volume which doesn't exist.
VirtualMachineStatusPvcNotFound VirtualMachinePrintableStatus = "ErrorPvcNotFound"
// VirtualMachineStatusDataVolumeNotFound indicates that the virtual machine references a DataVolume volume which doesn't exist.
VirtualMachineStatusDataVolumeNotFound VirtualMachinePrintableStatus = "ErrorDataVolumeNotFound"
// VirtualMachineStatusDataVolumeError indicates that an error has been reported by one of the DataVolumes
// referenced by the virtual machines.
VirtualMachineStatusDataVolumeError VirtualMachinePrintableStatus = "DataVolumeError"
// VirtualMachineStatusWaitingForVolumeBinding indicates that some PersistentVolumeClaims backing
// the virtual machine volume are still not bound.
VirtualMachineStatusWaitingForVolumeBinding VirtualMachinePrintableStatus = "WaitingForVolumeBinding"

 

1.2 vmi状态(源码枚举)

//When a VirtualMachineInstance Object is first initialized and no phase, or Pending is present.
VmPhaseUnset VirtualMachineInstancePhase = ""
// Pending means the VirtualMachineInstance has been accepted by the system.
Pending VirtualMachineInstancePhase = "Pending"
// A target Pod exists but is not yet scheduled and in running state.
Scheduling VirtualMachineInstancePhase = "Scheduling"
// A target pod was scheduled and the system saw that Pod in runnig state.
// Here is where the responsibility of virt-controller ends and virt-handler takes over.
Scheduled VirtualMachineInstancePhase = "Scheduled"
// Running means the pod has been bound to a node and the VirtualMachineInstance is started.
Running VirtualMachineInstancePhase = "Running"
// Succeeded means that the VirtualMachineInstance stopped voluntarily, e.g. reacted to SIGTERM or shutdown was invoked from
// inside the VirtualMachineInstance.
Succeeded VirtualMachineInstancePhase = "Succeeded"
// Failed means that the vmi crashed, disappeared unexpectedly or got deleted from the cluster before it was ever started.
Failed VirtualMachineInstancePhase = "Failed"
// Unknown means that for some reason the state of the VirtualMachineInstance could not be obtained, typically due
// to an error in communicating with the host of the VirtualMachineInstance.
Unknown VirtualMachineInstancePhase = "Unknown"

 

2. vm/vmi各状态具体判断条件/转换操作

 

vm状态
判断条件

CrashLoopBackOff

1.开机失败

2.失败次数大于0

3.运行策略为一直在运行或者失败重试

Stopped

1.vmi为关机或崩溃状态(Failed/Succeeded)

Provisioning

1.绑定了pvc的datavolumn没有准备好

WaitingForVolumeBinding

1.pvc状态为未绑定

Starting

1.vmi状态为Pending或者空

2.vmi状态为Scheduling

3.vmi状态为Scheduled

Running 1.vmi状态为Running
Paused

1.vmi状态为Running

2.vmi有Paused的condition,Paused一般为宿主机问题,例如存储空间不足等

Stopping

1.vmi不为关机或崩溃状态(Failed/Succeeded)

2.vmi未被标记为删除或者期望删除

Terminating

1.vm.ObjectMeta.DeletionTimestamp不为空

Migrating

1.根据vmi.Status.MigrationState的开始和结束时间,判断现在状态是否在迁移中

ErrorUnschedulable

1.vmi状态为Pending

vmi的condition中的PodScheduled为false,且原因为Unschedulable,pod不可调度,原因包括资源不足或调度限制

ErrImagePull

1.vmi状态为Scheduling
vmi的condition中的Synchronized为false,且原因为ErrImagePull,拉镜像错误
ImagePullBackOff

1.vmi状态为Scheduling

vmi的condition中的Synchronized为false,且原因为ImagePullBackOff,拉镜像错误且重试前kubelet崩溃

ErrorPvcNotFound

1.vmi状态为Pending

vmi的condition中的Synchronized为false,且原因为

FailedPvcNotFound,无时间限制,vmi事件触发更新,按照队列进行更新

ErrorDataVolumeNotFound

1.vmi状态为Pending

vmi的condition中的Synchronized为false,且原因为

FailedDataVolumeNotFound,无时间限制,vmi事件触发更新,按照队列进行更新

DataVolumeError

1.vmi状态为Pending

只要vm关联的dv有一个Status.Phase为Failed,或者dv的condition的Running为false

 

vmi原始状态
判断条件
vmi状态转换/操作
pending/空 pod存在,且不为临时pod

Scheduling

  vmi删除时间不为空/关联的dv有一个没有ready(Status.Phase为WaitForFirstConsumer)

Failed

  关联有dv为ready状态,存在临时pod(annotation:kubevirt.io/ephemeral-provisioning不为空),且pod状态为failed/容器状态为Terminated/pod标记删除 Failed
  同步pod/dv信息及状态失败,且失败原因为pvcNotFound/

DataVolumeNotFound

添加condition (PodReasonUnschedulable)

Scheduling

查看镜像错误,失败原因为ErrImagePull/ImagePullBackOff

其他同步错误(pod QOs正常分配/热插拔准备成功/磁盘状态ok)

Scheduling

  pod状态ready且未被标记删除,且无任何同步错误

Scheduled

  pod状态为failed/容器状态为Terminated/pod标记删除 Failed
  pod不存在/pod为临时pod Failed

Failed/Succeeded

  清空所有关联pod

状态为Scheduled后由virt-handler接管将按照队列更新状态(每当有操作时将虚机放入队列)

Scheduled

无domain,无socket,无pod/vmi 重新丢回队列
 
无domain,virt-launcher找不到,vmi状态一直停留 Failed
  无domain,其余情况

Scheduled

domain状态shutoff/crash 原因为crash/panic Failed
  原因为destroy且ACPI不可用 Failed
  原因为destroy且ACPI可用

Succeeded

  原因为shutdown/saved/fromSnapshot

Succeeded

  原因为migrated 保留原状态
domain状态Running/Paused/Blocked/PMSuspended   Running

 

3. 虚机各阶段状态管理与变化 

 

虚拟机创建分为创建DataVolume和VMI两个流程:

1. 创建DataVolume后,CDI组件创建对应的PVC并且关联到合适的PV,然后通过临时Importer Pod拉取虚拟机容器镜像绑定到DataVolume生成的PV中,并且将镜像转换成disk.img文件存储在PV中供虚拟机使用。

2. 创建VMI后,等待disk.img转换成功,然后在对应的Node上启动Launcher Pod,并将CDI流程生成的PV挂载到Pod内,当做虚拟机启动的系统盘。Launcher根据VMI的定义生成定义虚拟机的XML文件,然后调用libvirt进程调用Qemu命令创建并且启动虚拟机。VMI会对Launcher Pod状态进行同步,反应VM运行的状态。

文章来自个人专栏
kubevirt
2 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0