Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blog: Managing KubeVirt VMs with Ansible #916

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

0xFelix
Copy link
Member

@0xFelix 0xFelix commented Aug 25, 2023

What this PR does / why we need it:

This post explains how to manage KubeVirt VMs with the kubevirt.core Ansible collection.

Note: YouTube video still needs to be uploaded and link changed in post.

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/L labels Aug 25, 2023
@0xFelix
Copy link
Member Author

0xFelix commented Aug 25, 2023

/hold Change YouTube link in post first

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 25, 2023
@kubevirt-bot kubevirt-bot added the kind/blog Label for blog entries label Aug 25, 2023
Copy link

@jcanocan jcanocan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! :) Just a small comment.


While working with existing VMs is already quite useful, it would be even better to control the entire lifecycle of KubeVirt `VirtualMachines` from Ansible. This is made possible by the `kubevirt_vm` module provided by the `kubevirt.core` collection.

The `kubevirt_vm` module is a thin wrapper around the [kubernetes.core.k8s](https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html) module and it allows you to control the essential fields of a KubeVirt `VirtualMachine`'s specification. In true Ansible fashion, this module tries to be as idempotent as possible and only makes changes to objects within Kubernetes if necessary. With its `wait` feature, it is possible to delay further tasks until a VM was successfully created or updated and is in the ready state or the VM was successfully deleted.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `kubevirt_vm` module is a thin wrapper around the [kubernetes.core.k8s](https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html) module and it allows you to control the essential fields of a KubeVirt `VirtualMachine`'s specification. In true Ansible fashion, this module tries to be as idempotent as possible and only makes changes to objects within Kubernetes if necessary. With its `wait` feature, it is possible to delay further tasks until a VM was successfully created or updated and is in the ready state or the VM was successfully deleted.
The `kubevirt_vm` module is a thin wrapper around the [kubernetes.core.k8s](https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html) module and it allows you to control the essential fields of a KubeVirt `VirtualMachine`'s specification. In true Ansible fashion, this module tries to be as idempotent as possible and only makes changes to objects within Kubernetes if necessary. With its `wait` feature, it is possible to delay further tasks until a VM was successfully created or updated and the VM is in the ready state or was successfully deleted.

Copy link
Contributor

@aburdenthehand aburdenthehand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff. I've made a couple of suggestions, and added the youtube link for the demo.


This article will review some of the features and their use associated with this initial release.

Note: There is also a video version of this blog, which can be found on [YouTube](insertlink).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note: There is also a video version of this blog, which can be found on [YouTube](insertlink).
Note: There is also a video version of this blog, which can be found on [YouTube](https://youtu.be/GVROaPgJD_8).


Before diving into the featureset of the collection itself, let's review why the collection was created in the first place.

While incorporating KubeVirt and Kubernetes has the potential to disrupt the workflows of teams that typically manage VM infrastructure, including the end users themselves, many of the same paradigms remain:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/incorporating/adopting/ ?
At least, the use of 'incorporating' here I think requires an additional subject that KubeVirt and K8s are being incorporated in to.

- In many cases, communicating with KubeVirt VMs makes use of the same protocols and schemes as non-Kubernetes based environments.
- The management of VMs still represents a challenge.

For these reasons and more, it is only natural that a tool, like Ansible, is introduced within the KubeVirt community. Not only can it help manage the KubeVirt Kubernetes resources, like `VirtualMachines`, but also to enable the extensive Ansible ecosystem for managing guest configurations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For these reasons and more, it is only natural that a tool, like Ansible, is introduced within the KubeVirt community. Not only can it help manage the KubeVirt Kubernetes resources, like `VirtualMachines`, but also to enable the extensive Ansible ecosystem for managing guest configurations.
For these reasons and more, it is only natural that a tool, like Ansible, is introduced within the KubeVirt community. Not only can it help manage KubeVirt and Kubernetes resources, like `VirtualMachines`, but also to enable the extensive Ansible ecosystem for managing guest configurations.


## What next?

While the content included within this writeup only provided a brief introduction and usage of the newly released `kubevirt.core` collection. Nevertheless, it is the hope that it helped to showcase the integration now available between KubeVirt and Ansible, including how easy it is to manage KubeVirt assets. A next potential iteration could be to expose a VM via a Kubernetes `Service` using one of the methods described in [this article](https://kubevirt.io/user-guide/virtual_machines/service_objects/#service-objects) instead of a secondary interface as was covered in this walkthrough. Not only does it leverage existing models outside the KubeVirt ecosystem, but helps enable a uniform method for exposing content.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
While the content included within this writeup only provided a brief introduction and usage of the newly released `kubevirt.core` collection. Nevertheless, it is the hope that it helped to showcase the integration now available between KubeVirt and Ansible, including how easy it is to manage KubeVirt assets. A next potential iteration could be to expose a VM via a Kubernetes `Service` using one of the methods described in [this article](https://kubevirt.io/user-guide/virtual_machines/service_objects/#service-objects) instead of a secondary interface as was covered in this walkthrough. Not only does it leverage existing models outside the KubeVirt ecosystem, but helps enable a uniform method for exposing content.
This has been a brief introduction to the concepts and usage of the newly released `kubevirt.core` collection. Nevertheless, we hope that it helped to showcase the integration now available between KubeVirt and Ansible, including how easy it is to manage KubeVirt assets. A next iteration could be to expose a VM via a Kubernetes `Service` using one of the methods described in [this article](https://kubevirt.io/user-guide/virtual_machines/service_objects/#service-objects) instead of a secondary interface as was covered in this walkthrough. Not only does it leverage existing models outside the KubeVirt ecosystem, but it helps to enable a uniform method for exposing content.

@0xFelix
Copy link
Member Author

0xFelix commented Sep 4, 2023

@jcanocan @aburdenthehand Updated the PR with your suggestions.

Copy link
Contributor

@aburdenthehand aburdenthehand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, two more of the tiniest nits


This article will review some of the features and their use associated with this initial release.

Note: There is also a video version of this blog, which can be found on [YouTube](https://youtu.be/GVROaPgJD_8).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note: There is also a video version of this blog, which can be found on [YouTube](https://youtu.be/GVROaPgJD_8).
Note: There is also a video version of this blog, which can be found on the [KubeVirt YouTube channel](https://youtu.be/GVROaPgJD_8).

While adopting KubeVirt and Kubernetes has the potential to disrupt the workflows of teams that typically manage VM infrastructure, including the end users themselves, many of the same paradigms remain:

- Kubernetes and the resources associated with KubeVirt can be represented in a declarative fashion.
- In many cases, communicating with KubeVirt VMs makes use of the same protocols and schemes as non-Kubernetes based environments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- In many cases, communicating with KubeVirt VMs makes use of the same protocols and schemes as non-Kubernetes based environments.
- In many cases, communicating with KubeVirt VMs makes use of the same protocols and schemes as non-Kubernetes-based environments.

@0xFelix
Copy link
Member Author

0xFelix commented Sep 4, 2023

@aburdenthehand Adressed!

@aburdenthehand
Copy link
Contributor

/lgtm
Thanks @0xFelix !

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 4, 2023
@0xFelix
Copy link
Member Author

0xFelix commented Sep 4, 2023

/hold cancel

@kubevirt-bot kubevirt-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 4, 2023
Copy link

@jcanocan jcanocan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking amazing! Just a few comments.

ansible-playbook play-create.yml
```

Once the playbook completes successfully, the defined VM will be running in the `kubevirt-ansible` namespace, which can be confirmed by querying for `VirtualMachines` in this namespace.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Once the playbook completes successfully, the defined VM will be running in the `kubevirt-ansible` namespace, which can be confirmed by querying for `VirtualMachines` in this namespace.
Once the playbook completes successfully, the defined VM will be running in the `kubevirt-ansible` namespace, which can be confirmed by querying for `VirtualMachines` in this namespace:

label_selector: app=test
```

Use the `ansible-inventory` command to confirm the VM becomes added to the Ansible inventory.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use the `ansible-inventory` command to confirm the VM becomes added to the Ansible inventory.
Use the `ansible-inventory` command to confirm the VM becomes added to the Ansible inventory:

ansible-inventory -i inventory.kubevirt.yml --list
```

Next, make use of the host by querying for all of the facts exposed by the VM using the setup module.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Next, make use of the host by querying for all of the facts exposed by the VM using the setup module.
Next, make use of the host by querying for all of the facts exposed by the VM using the setup module:


## Introduction

Infrastructure teams managing virtual machines (VMs) and the end users of these systems make use of a variety of tools as part of their day-to-day world. One such tool that is shared amongst these two groups is Ansible, an agentless automation tool for the enterprise. To simplify both the adoption and usage of KubeVirt as well as to integrate seamlessly into existing workflows, the KubeVirt community is excited to introduce the release of the first version of the KubeVirt collection for Ansible, `kubevirt.core`, which includes a number of tools that you do not want to miss.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the KubeVirt community is excited to introduce the release of the first version of the KubeVirt collection for Ansible, ...

Link to Ansible website?

This post explains how to manage KubeVirt VMs with the kubevirt.core
Ansible collection.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 4, 2023
@0xFelix
Copy link
Member Author

0xFelix commented Sep 4, 2023

@jcanocan Addressed

@jcanocan
Copy link

jcanocan commented Sep 4, 2023

@jcanocan Addressed

Nice job! :)
/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 4, 2023
@phoracek
Copy link
Member

phoracek commented Sep 5, 2023

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: phoracek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 5, 2023
@kubevirt-bot kubevirt-bot merged commit 55867f8 into kubevirt:main Sep 5, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/blog Label for blog entries lgtm Indicates that a PR is ready to be merged. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants