Add examples with kubevirt
* Add helpers to install kubevirt and its dependencies
* Add examples how to use kubevirt
Related-Prod: PRODX-3456
Change-Id: I3ade65df5f8ddff39f35605104851833d74690a1
diff --git a/kubevirt/examples/20-boot-vm-multus/cirros-net1.yaml b/kubevirt/examples/20-boot-vm-multus/cirros-net1.yaml
new file mode 100644
index 0000000..f9710fb
--- /dev/null
+++ b/kubevirt/examples/20-boot-vm-multus/cirros-net1.yaml
@@ -0,0 +1,47 @@
+---
+apiVersion: kubevirt.io/v1
+kind: VirtualMachine
+metadata:
+ labels:
+ kubevirt.io/vm: cirros-net1
+ name: cirros-net1
+spec:
+ running: false
+ template:
+ metadata:
+ labels:
+ kubevirt.io/vm: cirros-net1
+ spec:
+ domain:
+ devices:
+ disks:
+ - disk:
+ bus: virtio
+ name: containerdisk
+ - disk:
+ bus: virtio
+ name: cloudinitdisk
+ interfaces:
+ - name: default
+ masquerade: {}
+ - name: ovn-net1
+ bridge: {}
+ resources:
+ requests:
+ memory: 128Mi
+ terminationGracePeriodSeconds: 0
+ networks:
+ - name: default
+ pod: {} # Stock pod network
+ - name: ovn-net1
+ multus: # Secondary multus network
+ networkName: net1
+ volumes:
+ - containerDisk:
+ image: docker.io/jumpojoy/kubevirt-cirros:0.6.2
+ name: containerdisk
+ - cloudInitNoCloud:
+ userData: |
+ #!/bin/sh
+ echo 'printed from cloud-init userdata'
+ name: cloudinitdisk
diff --git a/kubevirt/examples/20-boot-vm-multus/cirros-net2.yaml b/kubevirt/examples/20-boot-vm-multus/cirros-net2.yaml
new file mode 100644
index 0000000..8fc08fb
--- /dev/null
+++ b/kubevirt/examples/20-boot-vm-multus/cirros-net2.yaml
@@ -0,0 +1,47 @@
+---
+apiVersion: kubevirt.io/v1
+kind: VirtualMachine
+metadata:
+ labels:
+ kubevirt.io/vm: cirros-net2
+ name: cirros-net2
+spec:
+ running: false
+ template:
+ metadata:
+ labels:
+ kubevirt.io/vm: cirros-net2
+ spec:
+ domain:
+ devices:
+ disks:
+ - disk:
+ bus: virtio
+ name: containerdisk
+ - disk:
+ bus: virtio
+ name: cloudinitdisk
+ interfaces:
+ - name: default
+ masquerade: {}
+ - name: ovn-net2
+ bridge: {}
+ resources:
+ requests:
+ memory: 128Mi
+ terminationGracePeriodSeconds: 0
+ networks:
+ - name: default
+ pod: {} # Stock pod network
+ - name: ovn-net2
+ multus: # Secondary multus network
+ networkName: net2
+ volumes:
+ - containerDisk:
+ image: docker.io/jumpojoy/kubevirt-cirros:0.6.2
+ name: containerdisk
+ - cloudInitNoCloud:
+ userData: |
+ #!/bin/sh
+ echo 'printed from cloud-init userdata'
+ name: cloudinitdisk
diff --git a/kubevirt/examples/20-boot-vm-multus/network-attachment.yaml b/kubevirt/examples/20-boot-vm-multus/network-attachment.yaml
new file mode 100644
index 0000000..0681674
--- /dev/null
+++ b/kubevirt/examples/20-boot-vm-multus/network-attachment.yaml
@@ -0,0 +1,47 @@
+---
+apiVersion: "k8s.cni.cncf.io/v1"
+kind: NetworkAttachmentDefinition
+metadata:
+ name: net1
+ namespace: default
+spec:
+ config: '{
+ "cniVersion": "0.3.1",
+ "type": "kube-ovn",
+ "server_socket": "/run/openvswitch/kube-ovn-daemon.sock",
+ "provider": "net1.default.ovn"
+ }'
+
+---
+apiVersion: "k8s.cni.cncf.io/v1"
+kind: NetworkAttachmentDefinition
+metadata:
+ name: net2
+ namespace: default
+spec:
+ config: '{
+ "cniVersion": "0.3.1",
+ "type": "kube-ovn",
+ "server_socket": "/run/openvswitch/kube-ovn-daemon.sock",
+ "provider": "net2.default.ovn"
+ }'
+---
+apiVersion: kubeovn.io/v1
+kind: Subnet
+metadata:
+ name: net1
+spec:
+ protocol: IPv4
+ provider: net1.default.ovn
+ cidrBlock: 192.168.1.0/24
+ gateway: 192.168.1.1
+---
+apiVersion: kubeovn.io/v1
+kind: Subnet
+metadata:
+ name: net2
+spec:
+ protocol: IPv4
+ provider: net2.default.ovn
+ cidrBlock: 192.168.2.0/24
+ gateway: 192.168.2.1
diff --git a/kubevirt/examples/20-boot-vm-multus/run.sh b/kubevirt/examples/20-boot-vm-multus/run.sh
new file mode 100755
index 0000000..8d55316
--- /dev/null
+++ b/kubevirt/examples/20-boot-vm-multus/run.sh
@@ -0,0 +1,31 @@
+EXAMPLES_DIR=$(cd $(dirname "$0")/.. && pwd)
+WORKDIR=$(cd $(dirname "$0") && pwd)
+source ${EXAMPLES_DIR}/lib.sh
+
+command=$1
+
+function run {
+ echo "Creating network attachments"
+ kubectl apply -f network-attachment.yaml
+
+ echo "Creating VMs"
+ for vm in cirros-net1 cirros-net2; do
+ kubectl apply -f $vm.yaml
+
+ echo "Starting VM $vm"
+ virtctl start $vm
+ done
+ echo "Waiting VM is Running."
+ wait_vm_state cirros-net1 Running
+ wait_vm_state cirros-net2 Running
+}
+
+function cleanup {
+ for f in $(ls *.yaml); do
+ kubectl delete -f $f
+ done
+}
+
+pushd $WORKDIR
+$command
+popd