Scenario - Persistent Storage Volume Provisioning and Availability for Virtual Machines
In this scenario, we will learn about how to provision a virtual machine on OpenShift Virtualization with Purestorage.
Step 1 - Deploy a virtual machine using the OpenShift command line tool
Let’s start by building VM using the oc
command line tool.
Task 1: Generate an SSH keypair
In order to interact with our virtual machine, let’s create an ssh keypair.
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
Task 2: Create an Openshift Secret with our SSH key:
ID_RSA_PUB=$(cat ~/.ssh/id_rsa.pub)
cat << EOF | oc apply -f -
---
apiVersion: v1
kind: Secret
metadata:
name: authorized-keys
namespace: vmtest
data:
key: $(cat ~/.ssh/id_rsa.pub | base64 -w0)
EOF
Task 3: Create an Openshift Virtual Machine
cat << EOF | oc apply -f -
---
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: centos-stream9-example
namespace: vmtest
spec:
dataVolumeTemplates:
- metadata:
name: centos-stream9-example-ds-centos-stream9
spec:
sourceRef:
kind: DataSource
name: centos-stream9
namespace: openshift-virtualization-os-images
storage:
resources: {}
instancetype:
name: u1.medium
preference:
name: centos.stream9
runStrategy: Always
template:
spec:
domain:
devices: {}
resources: {}
terminationGracePeriodSeconds: 180
volumes:
- name: centos-stream9-example-ds-centos-stream9
dataVolume:
name: centos-stream9-example-ds-centos-stream9
- name: cloudinitdisk
cloudInitNoCloud:
userData: |-
#cloud-config
user: cloud-user
accessCredentials:
- sshPublicKey:
propagationMethod:
noCloud: {}
source:
secret:
secretName: authorized-keys
EOF
The above created a VM called centos-stream9-example
that we will use for the rest of the labs.
Once the VM is running we can log into this VM using this command (if you do so make sure to exit again by pressing Ctrl-D
or typing exit
followed by pressing Enter
):
virtctl ssh cloud-user@centos-stream9-example -i ~/.ssh/id_rsa -t "-o StrictHostKeyChecking=no"
Step 2 - Deploy a Virtual Machine using the Openshift Console
Start by logging in to the OpenShift console if you haven’t already.
Task 1: Create a new VM
Navigate to the virtualzation > overview menu
Click the Create Virtual Machine
button
Select the Centos Stream image. We can also use the default instance type.
Verify that our StorageClass is set to px-csi-db
and click
Create VirtualMachine
This will automatically start the virtual machine after a short provisioning process.
It can take a couple of minutes for our VM to boot the first time
Explore the tabs for this virtual machine. We can view metrics, configure snapshots, and even view the YAML configuration to make automating easy.
The Virtual Machine name will be different in your environment
Click Next
to move on to the next challenge