Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions api/core/v1alpha2/virtual_machine_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type VirtualMachineOperation struct {

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message=".spec is immutable"
// +kubebuilder:validation:XValidation:rule="self.type == 'Start' ? !has(self.force) || !self.force : true",message="The `Start` operation cannot be performed forcibly."
// +kubebuilder:validation:XValidation:rule="self.type == 'Migrate' ? !has(self.force) || !self.force : true",message="The `Migrate` operation cannot be performed forcibly."
// +kubebuilder:validation:XValidation:rule="self.type == 'Restore' ? has(self.restore) : true",message="Restore requires restore field."
// +kubebuilder:validation:XValidation:rule="self.type == 'Clone' ? has(self.clone) : true",message="Clone requires clone field."
// +kubebuilder:validation:XValidation:rule="!(has(self.migrate)) || self.type == 'Migrate'",message="spec.migrate can only be set when spec.type is 'Migrate'"
type VirtualMachineOperationSpec struct {
Type VMOPType `json:"type"`
// Name of the virtual machine the operation is performed for.
Expand All @@ -63,6 +63,8 @@ type VirtualMachineOperationSpec struct {
Restore *VirtualMachineOperationRestoreSpec `json:"restore,omitempty"`
// Clone defines the clone operation.
Clone *VirtualMachineOperationCloneSpec `json:"clone,omitempty"`
// Defines the virtual machine migration operation.
Migrate *VirtualMachineOperationMigrateSpec `json:"migrate,omitempty"`
}

// VirtualMachineOperationRestoreSpec defines the restore operation.
Expand All @@ -84,6 +86,15 @@ type VirtualMachineOperationCloneSpec struct {
Customization *VirtualMachineOperationCloneCustomization `json:"customization,omitempty"`
}

// VirtualMachineOperationMigrateSpec defines the restore operation.
type VirtualMachineOperationMigrateSpec struct {
// Node selector for scheduling the VM onto a node. Must match the target node's labels.
// [Same](https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/) as the Pod `spec.nodeSelector` field in Kubernetes.
//
// > The `nodeSelector` field is not available in the Community Edition.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="!has(self.namePrefix) || (size(self.namePrefix) >= 1 && size(self.namePrefix) <= 59)",message="namePrefix length must be between 1 and 59 characters if set"
// +kubebuilder:validation:XValidation:rule="!has(self.nameSuffix) || (size(self.nameSuffix) >= 1 && size(self.nameSuffix) <= 59)",message="nameSuffix length must be between 1 and 59 characters if set"
// VirtualMachineOperationCloneCustomization defines customization options for cloning.
Expand Down Expand Up @@ -162,8 +173,8 @@ const (
// * `Start`: Start the virtual machine.
// * `Stop`: Stop the virtual machine.
// * `Restart`: Restart the virtual machine.
// * `Migrate` (deprecated): Migrate the virtual machine to another node where it can be started.
// * `Evict`: Migrate the virtual machine to another node where it can be started.
// * `Migrate`: Migrate the virtual machine to another node where it can run.
// * `Evict`: Evict the virtual machine to another node where it can run.
// * `Restore`: Restore the virtual machine from a snapshot.
// * `Clone`: Clone the virtual machine to a new virtual machine.
// +kubebuilder:validation:Enum={Restart,Start,Stop,Migrate,Evict,Restore,Clone}
Expand Down
28 changes: 28 additions & 0 deletions api/core/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions crds/doc-ru-virtualmachineoperations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ spec:
* `Start` — запустить виртуальную машину;
* `Stop` — остановить виртуальную машину;
* `Restart` — перезапустить виртуальную машину;
* `Migrate` (устаревшее значение) — мигрировать виртуальную машину на другой узел, доступный для запуска данной ВМ;
* `Evict` — мигрировать виртуальную машину на другой узел, доступный для запуска данной ВМ;
* `Migrate` — мигрировать виртуальную машину на другой узел, на котором её можно запустить;
* `Evict` — вытеснить виртуальную машину на другой узел, на котором её можно запустить;
* `Restore` — восстановить виртуальную машину из снимка;
* `Clone` — клонировать виртуальную машину.
virtualMachineName:
Expand All @@ -42,6 +42,16 @@ spec:
virtualMachineSnapshotName:
description: |
Имя снимка виртуальной машины, который используется как источник для операции восстановления.
migrate:
description: |
Определяет операцию миграции виртуальной машины.
properties:
nodeSelector:
description: |-
Селектор меток узла для планирования виртуальной машины на узел. Должен соответствовать меткам целевого узла.
[По аналогии](https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/) с параметром подов `spec.nodeSelector` в Kubernetes.

> Поле `nodeSelector` недоступно в Community Edition.
clone:
description: |
Определяет операцию клонирования.
Expand Down
23 changes: 17 additions & 6 deletions crds/virtualmachineoperations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ spec:
* Effect on `Restart` and `Stop`: operation performs immediately.
* Effect on `Evict` and `Migrate`: enable the AutoConverge feature to force migration via CPU throttling if the `PreferSafe` or `PreferForced` policies are used for live migration.
type: boolean
migrate:
description: Defines the virtual machine migration operation.
properties:
nodeSelector:
additionalProperties:
type: string
description: |-
Node selector for scheduling the VM onto a node. Must match the target node's labels.
[Same](https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/) as the Pod `spec.nodeSelector` field in Kubernetes.

> The `nodeSelector` field is not available in the Community Edition.
type: object
type: object
restore:
description: Restore defines the restore operation.
properties:
Expand Down Expand Up @@ -191,8 +204,8 @@ spec:
* `Start`: Start the virtual machine.
* `Stop`: Stop the virtual machine.
* `Restart`: Restart the virtual machine.
* `Migrate` (deprecated): Migrate the virtual machine to another node where it can be started.
* `Evict`: Migrate the virtual machine to another node where it can be started.
* `Migrate`: Migrate the virtual machine to another node where it can run.
* `Evict`: Evict the virtual machine to another node where it can run.
* `Restore`: Restore the virtual machine from a snapshot.
* `Clone`: Clone the virtual machine to a new virtual machine.
enum:
Expand All @@ -219,14 +232,12 @@ spec:
rule: self == oldSelf
- message: The `Start` operation cannot be performed forcibly.
rule: "self.type == 'Start' ? !has(self.force) || !self.force : true"
- message: The `Migrate` operation cannot be performed forcibly.
rule:
"self.type == 'Migrate' ? !has(self.force) || !self.force :
true"
- message: Restore requires restore field.
rule: "self.type == 'Restore' ? has(self.restore) : true"
- message: Clone requires clone field.
rule: "self.type == 'Clone' ? has(self.clone) : true"
- message: spec.migrate can only be set when spec.type is 'Migrate'
rule: "!(has(self.migrate)) || self.type == 'Migrate'"
status:
properties:
conditions:
Expand Down
51 changes: 38 additions & 13 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1623,12 +1623,13 @@ d8 v restart linux-vm

A list of possible operations is given in the table below:

| d8 | vmop type | Action |
| -------------- | --------- | ------------------------------ |
| `d8 v stop` | `Stop` | Stop VM |
| `d8 v start` | `Start` | Start the VM |
| `d8 v restart` | `Restart` | Restart the VM |
| `d8 v evict` | `Evict` | Migrate the VM to another host |
| d8 | vmop type | Action |
| ---------------- | ----------- | ------------------------------ |
| `d8 v stop` | `Stop` | Stop VM |
| `d8 v start` | `Start` | Start the VM |
| `d8 v restart` | `Restart` | Restart the VM |
| `d8 v evict` | `Evict` | Evict the VM to another host |
| `d8 v migrate` | `Migrate` | Migrate the VM to another host |

How to perform the operation in the web interface:

Expand Down Expand Up @@ -2364,31 +2365,55 @@ We can see that it is currently running on the `virtlab-pt-1` node.
To migrate a virtual machine from one node to another while taking into account VM placement requirements, use the following command:

```bash
d8 v evict -n <namespace> <vm-name> [--force]
d8 v migrate -n <namespace> <vm-name> [--force] [--target-node-name string]
```

Running this command creates a VirtualMachineOperations resource.

When used during virtual machine migration, the `--force` flag activates a special mechanism called AutoConverge (for more details, see the [Migration with insufficient network bandwidth](#migration-with-insufficient-network-bandwidth) section). This mechanism automatically reduces the CPU load of the virtual machine (slows down its CPU) when it is necessary to speed up the completion of migration and help it complete successfully, even when the virtual machine memory transfer is too slow. Use this flag if a standard migration cannot complete due to high virtual machine activity.

You can also start the migration by creating a VirtualMachineOperations (`vmop`) resource with the `Evict` type manually:
To migrate a virtual machine to a specific target node, specify the node name using the `--target-node-name option`. For example, to migrate the virtual machine to the `production-1` node, run:

```bash
d8 v migrate -n project-1 linux-vm --target-node-name production-1
```

As a result, a virtual machine operation will be created with the specific node selector `kubernetes.io/hostname: production-1`, where `production-1` is the node name.

You can also start the migration by manually creating a [VirtualMachineOperation](/modules/virtualization/cr.html#virtualmachineoperation) (`vmop`) resource of type `Migrate`:

```yaml
d8 k create -f - <<EOF
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachineOperation
metadata:
generateName: evict-linux-vm-
generateName: migrate-linux-vm-
namespace: project-1
spec:
# virtual machine name
virtualMachineName: linux-vm
# operation to evict
type: Evict
type: Migrate
# Defines the Migrate operation.
migrate:
nodeSelector:
# Additionally, you can set any suitable node selector.
kubernetes.io/hostname: production-1
# Allow CPU slowdown by AutoConverge mechanism to guarantee that migration will complete.
force: true
EOF
```

{{< alert level="info" >}}
To avoid a virtual machine becoming unschedulable, the node selector must not conflict with other placement rules such as virtual machine affinity, node selectors, and virtual machine class node selector rules.
{{< /alert >}}

{{< alert level="info" >}}
Targeted migration to a specific node is not available in the Community Edition.

If you don’t need to specify target node parameters, you can omit the `migrate` field or evict the virtual machine to another suitable node using the `d8 v evict` command, or by creating a [VirtualMachineOperation](/modules/virtualization/cr.html#virtualmachineoperation) resource of type `Evict`.
{{< /alert >}}

To track the migration of a virtual machine immediately after the `vmop` resource is created, run the command:

```bash
Expand Down Expand Up @@ -2434,9 +2459,9 @@ The AutoConverge mechanism works in two stages:
To configure the migration policy, use the [`.spec.liveMigrationPolicy`](/modules/virtualization/cr.html#virtualmachine-v1alpha2-spec-livemigrationpolicy) parameter in the virtual machine configuration. The following options are available:

- `AlwaysSafe`: Migration is always performed without slowing down the CPU (AutoConverge is not used). Suitable for cases where maximum virtual machine performance is important, but it requires high network bandwidth.
- `PreferSafe` (used as the default policy): Migration is performed without slowing down the CPU (AutoConverge is not used). However, you can start migration with CPU slowdown using the VirtualMachineOperation resource with parameters `type=Evict` and `force=true`.
- `PreferSafe` (used as the default policy): Migration is performed without slowing down the CPU (AutoConverge is not used). However, you can start migration with CPU slowdown using the [VirtualMachineOperation](/modules/virtualization/cr.html#virtualmachineoperation) resource with parameters `type=Migrate` and `force=true`.
- `AlwaysForced`: Migration always uses AutoConverge, meaning the CPU is slowed down when necessary. This guarantees migration completion even with poor network, but may reduce virtual machine performance.
- `PreferForced`: Migration uses AutoConverge, meaning the CPU is slowed down when necessary. However, you can start migration without slowing down the CPU using the VirtualMachineOperation resource with parameters `type=Evict` and `force=false`.
- `PreferForced`: Migration uses AutoConverge, meaning the CPU is slowed down when necessary. However, you can start migration without slowing down the CPU using the [VirtualMachineOperation](/modules/virtualization/cr.html#virtualmachineoperation) resource with parameters `type=Migrate` and `force=false`.

#### Migration with insufficient network bandwidth

Expand All @@ -2455,7 +2480,7 @@ Example of a situation where migration cannot be completed due to insufficient n

![](./images/livemigration-example.png)

Example of performing migration of the same virtual machine using the `--force` flag of the `d8 v evict` command (which enables the AutoConverge mechanism): here you can clearly see that the CPU frequency decreases step by step to reduce the memory change rate.
Example of migrating the same virtual machine using the `--force` flag of the `d8 v migrate` command (which enables AutoConverge). The example shows the CPU frequency decreasing step by step to reduce the memory change rate.

![](./images/livemigration-example-autoconverge.png)

Expand Down
Loading
Loading