Creating and managing virtual machines
demo.sh script which you've run above has set up Virtlet, started virtual machine with cirros image, started a nginx pod which is exposed via Service.
Let's check how it all works.
The script will ssh into a
cirros-vm before finishing. Switch to another console and list the pods:
kubectl get pod
nginx pod are both listed. Now list the services:
kubectl get svc
Now go back to the first console where you are logged in the
cirros-vm. If you disconnected from it you can reconnect with
virtletctl ssh [email protected] -- -i virtlet/examples/vmkey.
Check that you have internet access:
ping 18.104.22.168 ping mirantis.com
Make sure that the cluster network is also accessible from within the pod. Retrieve some data:
Disconnect from the VM using Ctrl-D.
View Pod details
kubectl get and
kubectl describe commands to view details for the
View the logs of a Pod
kubectl logs command to view the logs for the
kubectl logs cirros-vm
Attach to the VM
kubectl attach command to attach to the VM console:
kubectl attach -it cirros-vm
To exit use
CTRL-] key combination.
Create new Ubuntu VM
Now you can create another virtual machine. Let's create Ubuntu VM from Virtlet examples:
cat examples/ubuntu-vm-with-testuser.yaml kubectl apply -f examples/ubuntu-vm-with-testuser.yaml
This example also shows how cloud-init script can be used. Here new user:
testuser is created and also an ssh key is injected.
Wait for ubuntu VM:
kubectl get pod -w
Now attach to the VM using testuser/testuser credentials:
kubectl attach -it ubuntu-vm-with-testuser
Check if it also has internet connection using the same method which was used for
Use in Deployment
Because Virtlet VMs are just normal pods you can create Deployment, DaemonSet or even StatefulSet from Virtual Machines:
cat examples/deploy-cirros-vm.yaml kubectl apply -f examples/cirros-vm-deployment.yaml
When it's ready you can scale it:
kubectl scale --replicas=2 deploy/cirros-deployment