Last active
January 19, 2022 08:59
-
-
Save alicefr/fb63133ec172532087b7605d6b173f9a to your computer and use it in GitHub Desktop.
Import VM disk image and modify it in the cluster in KubeVirt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl apply -f import-original-image.yaml | |
# Wait until the DV import has finished. Now you have imported the original image on your k8s cluster | |
# Modify the initial image with virt-customizee by using virtctl guestfs command. You can install additional packages or modify certain files | |
$ virtctl guestfs pvc-with-cloud-init | |
Use image: registry:5000/kubevirt/libguestfs-tools@sha256:4cfe1c07cc33999ed05bd43873b7a30b1b9127a4ae4922333e68a1bcd35169ce | |
The PVC has been mounted at /disk | |
If you don't see a command prompt, try pressing enter. | |
$ ls /disk/ | |
disk.img | |
virt-customize --run-command 'echo "My awesome image" > /tmp/hello' --install cloud-init -a /disk/disk.img | |
exit | |
# Now create VMs using the pvc-with-cloud-init as source | |
$ kubectl apply -f vm-with-updated-dv.yaml | |
$ kubectl get vm | |
NAME AGE STATUS READY | |
vm 2m25s Running True | |
$ virtctl console vm | |
Successfully connected to vm console. The escape sequence is ^] | |
vm login: fedora | |
Password: | |
[fedora@vm ~]$ cat /tmp/hello | |
My awesome image | |
[fedora@vm ~]$ rpm -qa | grep cloud-init | |
cloud-init-19.4-2.fc32.noarch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: cdi.kubevirt.io/v1beta1 | |
kind: DataVolume | |
metadata: | |
name: pvc-with-cloud-init | |
annotations: | |
cdi.kubevirt.io/storage.bind.immediate.requested: "true" | |
spec: | |
source: | |
registry: | |
url: docker://registry:5000/kubevirt/fedora-with-test-tooling-container-disk:devel | |
pvc: | |
accessModes: | |
- ReadWriteOnce | |
resources: | |
requests: | |
storage: 10G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: kubevirt.io/v1 | |
kind: VirtualMachine | |
metadata: | |
labels: | |
kubevirt.io/vm: vm | |
name: vm | |
spec: | |
dataVolumeTemplates: | |
- metadata: | |
name: dv | |
spec: | |
pvc: | |
accessModes: | |
- ReadWriteOnce | |
resources: | |
requests: | |
storage: 10G | |
storageClassName: local | |
source: | |
pvc: | |
name: pvc-with-cloud-init | |
namespace: default | |
running: true | |
template: | |
metadata: | |
labels: | |
kubevirt.io/vm: vm | |
spec: | |
domain: | |
devices: | |
disks: | |
- disk: | |
bus: virtio | |
name: datavolumedisk1 | |
resources: | |
requests: | |
memory: 2Gi | |
terminationGracePeriodSeconds: 0 | |
volumes: | |
- dataVolume: | |
name: dv | |
name: datavolumedisk1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment