---
title: "Using Kubernetes to orchestrate VMs"
source: "https://www.tigera.io/blog/using-kubernetes-to-orchestrate-vms/"
description: "Learn how to add KubeVirt to your cluster, using Calico networking, and then use Calico network policy to secure the VMs."
---

[Technical Blog](https://www.tigera.io/category/technical-blog/)

# Using Kubernetes to orchestrate VMs

By [Reza Ramezanpour](https://www.tigera.io/blog/author/rezar/) on Sep 16, 2020 • 5 min read



The benefits of containers and using Kubernetes for container orchestration are very well known. But what do you do if you have a workload that is not amenable to being containerized? Perhaps you have a third-party VM-based workload that you yourself can’t easily containerize, or perhaps requires a different kernel or base OS than your Kubernetes platform is running. 






What you would really want is a way for Kubernetes to orchestrate VMs alongside standard container based pods, in a way that looks and feels just like an ordinary pod. Two recent projects that aim to allow you to do just this are [KubeVirt](http://kubevirt.io/) and OpenShift [CNV](http://www.openshift.com/blog/openshift-4-3-creating-virtual-machines-on-kubernetes-with-openshifts-cnv).






In this blog I’ll get hands on with KubeVirt in a step-by-step guide that you can follow yourself to add KubeVirt to your cluster, using Calico networking, and then use Calico network policy to secure the VMs.






## Before we begin






I’m using Ubuntu 20.04 and two bare metal servers for my development cluster. Although I have an explanation on how to create a similar development cluster in “Step 1”, you can safely skip it if you already have a different Kubernetes or OpenShift environment of choice.






Requirements:








- At least one host with 2 CPUs, 4GB Ram and 20GB of storage

- kubectl command line utility

- SSH client






## Step 1: Create a cluster






Before we begin creating a cluster let’s make our host suitable for Kubernetes. Check out this excellent [tutorial](http://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/) and prepare your host.






Let’s create a Kubernetes Cluster






```
`sudo kubeadm init --pod-network-cidr=192.168.0.0/16`
```






Execute the following commands to configure kubectl:






```
`mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config`
```






Remove the taints on the master so that you can schedule pods on it.






```
`kubectl taint nodes --all node-role.kubernetes.io/master-`
```






It should return the following:






```
`node/<your-hostname> untainted`
```






## Step 2: Install Calico






Install Calico using latest manifest






```
`kubectl apply -f http://docs.projectcalico.org/manifests/calico.yaml`
```






## Step 3: Install KubeVirt






Using namespaces, we can isolate resources to logical blocks and manage them easier.






```
`kubectl create namespace kubevirt`
```






It is recommended to use a host that can support hardware virtualization, to ensure your host(s) are capable you can use `virt-host-validate` binary.






```
`virt-host-validate qemu QEMU: Checking for hardware virtualization :PASS`
```






If your host is missing this command you can install it using your distro package manager or simply check if the kvm folder is available using  `ls /dev/kvm`.






By default, KubeVirt tries to leverage hardware emulation. However, this feature is not available in all environments in this case you can enable software emulation using:






```
`kubectl create configmap -n kubevirt kubevirt-config --from-literal debug.useEmulation=true`
```






Apply these manifests and run the KubeVirt operator to automatically install all the required resources.






```
`kubectl apply -f http://github.com/kubevirt/kubevirt/releases/download/v0.32.0/kubevirt-operator.yaml kubectl apply -f http://github.com/kubevirt/kubevirt/releases/download/v0.32.0/kubevirt-cr.yaml`
```






You can check KubeVirt installation progress using this command.






```
`kubectl -n kubevirt wait kv kubevirt --for condition=Available`
```






## Step 4: Create a simple VM






First let’s create a namespace to isolate our resources for this demo.






```
`kubectl create namespace kv-policy-demo`
```






Using Virtual Machine Instance (VMI) custom resources we can now create VMs that are fully integrated with Kubernetes.






```
`kubectl create -f - <<EOF apiVersion: kubevirt.io/v1alpha3 kind: VirtualMachineInstance metadata: name: vmi-cirros namespace: kv-policy-demo labels: special: l-vmi-cirros spec: domain: devices: disks: - disk: bus: virtio name: containerdisk resources: requests: memory: 64M volumes: - name: containerdisk containerDisk: image: kubevirt/cirros-registry-disk-demo:latest EOF`
```






**Note: If you are using software emulation then starting up a VM can be very slow and it might take 5-6 minutes for VM to finishing coming up with an IP address**.






Create a service to map to the SSH port:






```
`kubectl create -f - <<EOF apiVersion: v1 kind: Service metadata: name: vmi-cirros-ssh-svc namespace: kv-policy-demo spec: ports: - name: crrios-ssh-svc nodePort: 30000 port: 27017 protocol: TCP targetPort: 22 selector: special: l-vmi-cirros type: NodePort EOF`
```






Confirm we can access VMs using SSH by accessing via the service node port using your node’s IP address. The default password is `gocubsgo`.






```
`ssh cirros@10.1.2.3 -p 30000`
```






Confirm that the VM can access the outside world by pinging google from your new VM.






```
`ping www.google.com -c 5`
```






## Step 5: Add network security






Apply the following policy to isolate the VM in its namespace. This locks down all incoming connects to SSH only, and prevents the VM from making outgoing connections. (Depending on your VM, you’ll want a different policy, but this simple policy is good for this tutorial.)






```
`kubectl create -f - <<EOF apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: only-allow-ingress-ssh-to-vm namespace: kv-policy-demo spec: podSelector: matchLabels: special: l-vmi-cirros policyTypes: - Ingress - Egress ingress: - from: ports: - port: 22 EOF`
```






SSH into the VM and try to ping google again. 






You will not be able to since the policy will prevent all communication originated from the pod to the outside world. This is pretty powerful – you can secure your VMs using the same paradigms as securing pods!






## Cleanup






To cleanup the namespace and VM I used in this guide, you can run this command






```
`kubectl delete namespace kv-policy-demo`
```








**If you enjoyed this blog then you may also like:**








- Learn more about KubeVirt: [how to access VM console](http://kubevirt.io/user-guide/#/usage/graphical-and-console-access) and [how to install a Windows VM](http://kubevirt.io/user-guide/#/creation/virtio-win)

- Free online training at [projectcalico.org/events](http://projectcalico.org/events) or subscribe to [Calico Essentials](https://info.tigera.io/rs/805-GFH-732/images/Calico-Essentials-Datasheet.pdf) for personalized training & workshops

- Learn about [Calico Enterprise](http://docs.projectcalico.org/calico-enterprise/)



[How-To](https://www.tigera.io/tags/how-to/)[Open Source](https://www.tigera.io/tags/open-source/)[Project Calico](https://www.tigera.io/tags/project-calico/)

## Related posts

[![From Merged PR to Governed Pod: Automating AI Agent Deployment on Kubernetes](https://www.tigera.io/app/uploads/2026/10/From-Merged-PR-to-Governed-Pod-featured.png)](https://www.tigera.io/blog/from-merged-pr-to-governed-pod-automating-ai-agent-deployment-on-kubernetes/)

#### [From Merged PR to Governed Pod: Automating AI Agent Deployment on Kubernetes](https://www.tigera.io/blog/from-merged-pr-to-governed-pod-automating-ai-agent-deployment-on-kubernetes/)

By [Alister Baroi](https://www.tigera.io/blog/author/alister-baroi/)
on Oct 13, 2026

In short, automating the AI agent lifecycle is this year’s pitch: Google Cloud’s walkthrough of 30th July 2026 turns the whole thing into a conversation with a coding agent. On Kubernetes the deploy half of...

[Read more](https://www.tigera.io/blog/from-merged-pr-to-governed-pod-automating-ai-agent-deployment-on-kubernetes/)

[![Save the Address, Save the Cloud: A Hands-on KubeVirt Live Migration Workshop](https://www.tigera.io/app/uploads/2026/07/Save-the-Address-Save-the-Cloud-A-Hands-on-KubeVirt-Live-Migration-Workshop.png)](https://www.tigera.io/blog/save-the-address-save-the-cloud-a-hands-on-kubevirt-live-migration-workshop/)

#### [Save the Address, Save the Cloud: A Hands-on KubeVirt Live Migration Workshop](https://www.tigera.io/blog/save-the-address-save-the-cloud-a-hands-on-kubevirt-live-migration-workshop/)

By [Reza Ramezanpour](https://www.tigera.io/blog/author/rezar/)
on Jul 9, 2026

In the previous post in this series, we covered why Virtual Machine (VM) Live Migration in Kubernetes is difficult: a VM’s IP is its identity, and the “new” VM on the destination node has to...

[Read more](https://www.tigera.io/blog/save-the-address-save-the-cloud-a-hands-on-kubevirt-live-migration-workshop/)

[![What’s new in Calico: Spring 2026 Release](https://www.tigera.io/app/uploads/2026/06/Whats-New-in-Calico-NEW-TEMPLATE-2026.png)](https://www.tigera.io/blog/whats-new-in-calico-spring-2026-release/)

[Company Blog](https://www.tigera.io/category/company-blog/)

#### [What’s new in Calico: Spring 2026 Release](https://www.tigera.io/blog/whats-new-in-calico-spring-2026-release/)

By [Veronika Smolik](https://www.tigera.io/blog/author/veronika-smolik/)
on Jun 2, 2026

Kubernetes has come a long way since its debut in 2014. It’s gone from running a couple of containerized microservices to orchestrating fleets of production workloads spanning everything from AI agents to full scale VMs...

[Read more](https://www.tigera.io/blog/whats-new-in-calico-spring-2026-release/)

<!-- plugin=object-cache-pro client=phpredis metric#hits=6179 metric#misses=17 metric#hit-ratio=99.7 metric#bytes=2241153 metric#prefetches=0 metric#store-reads=411 metric#store-writes=34 metric#store-hits=423 metric#store-misses=6 metric#sql-queries=37 metric#ms-total=915.32 metric#ms-cache=58.65 metric#ms-cache-avg=0.1321 metric#ms-cache-ratio=6.4 -->
