In this post i will show you how to run your windows server workloads and needs in KubeVirt. Also probably what usecase when you need this.
Background
I work for a company that has workloads running on Windows Servers, and the cost of using public cloud windows is quite high. To address this challenge, I proposed a solution to host the Windows servers on bare metal as service servers (already bootstrapped with Kubespray). This approach not only provides better latency since the servers are in our country (Indonesia), but it also significantly reduces costs.
Prerequisite
1. Virualization Enabled
Make sure your kubernetes nodes already enable Virtualization
2. Presistent Backend Storage
You need storageclass kubernetes with presistent backend storage like CEPH, Longhorn, vSAN or whatever.
3. Understand What Kubevirt Do
If you has't understand what kubevirt do, is basicly do what kvm and qemu automation with YAML kubernetes. Go checkout kubevirt.io
4. Installed the KubeVirt and Container Data Importer Engine
Follow the guide from official docs, or here my previouse introduction about kubevirt
5. Virt Plugin Kubectl
We need this plugin to make our life easier, install it with krew.sigs.k8s.io
Let's Deploy Your Windows
In this blog i will use cloudbase.it image, bacause the image is already cloudinit-able or some people may say "Cloud Native"
1. Download the Image
Download the image where ever you can access your your cluster with kubectl
2. Forward Your CDI Upload Proxy
kubectl port-forward svc/cdi-uploadproxy -n cdi 6969:443
3. Upload With Virt Plugin
kubectl virt image-upload \
--image-path=./windows_server_2012_kvm.qcow2 \
--pvc-name=iso-winserver-r12 \
--access-mode=ReadWriteOnce \
--pvc-size=20G \
--storage-class=kind-local \
--uploadproxy-url=https://localhost:6969 \
--insecure
4. Specifiying Your VM
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
creationTimestamp: 2023-04-10T15:03:08Z
generation: 1
labels:
kubevirt.io/os: windows
name: windowsvm1
spec:
running: true
template:
metadata:
creationTimestamp: null
labels:
kubevirt.io/domain: windowsvm1
spec:
domain:
cpu:
cores: 4
devices:
disks:
- disk:
bus: virtio
name: disk0
- cdrom:
bus: sata
readonly: true
name: cloudinitdisk
machine:
type: q35
resources:
requests:
memory: 4096M
volumes:
- name: disk0
persistentVolumeClaim:
claimName: iso-winserver-r12
- cloudInitConfigDrive:
userData: |
#ps1
net user Administrator THizisMypzzzowrd
name: cloudinitdisk