Wednesday, June 26, 2013

How to create a VM on Nutanix Cluster running KVM ?

I will go in depth on configuration modification done for running Nutanix cluster on KVM later.
(if you are interested, i like this doc

KVM Architecture Overview - Google Drive )

For now, let us take a Nutanix cluster running KVM and create VM on it.

[root@NTNX-12AM2K480036-A Create]# lsb_release   - vmware -v
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch

[root@NTNX-12AM2K480036-A Create]# virsh nodeinfo
CPU model:           x86_64
CPU(s):              24
CPU frequency:       1600 MHz
CPU socket(s):       1
Core(s) per socket:  6
Thread(s) per core:  2
NUMA cell(s):        2
Memory size:         49486468 KiB

virsh sysinfo (smbiosDump) - dmidecode on linux works as well.
<sysinfo type='smbios'>
    <entry name='vendor'>American Megatrends Inc.</entry>
    <entry name='version'>2.1b      </entry>
    <entry name='date'>10/28/2011</entry>
    <entry name='release'>8.16</entry>

Step 1.

- Login to nutanix Controller VM and Create Iscsi disk on Nutanix Container ( ncli ctr ls)
a. ncli vdisk create name=kvm-training-disk9 ctr-name=xyz  max-capacity=16

ncli> vdisk ls names=kvm-training-disk9
    Name                      : kvm-training-disk9
    Container ID              : 779
    Max Capacity              : 16 GB (17,179,869,184 bytes)
    ISCSI Target              :
    ISCSI LUN                 : 0

b. On KVM terminal - Verify that you are able to see the iscsi targets.

[root@NTNX-12AM2K480036-A ~]# sudo  iscsiadm -m discovery -t sendtargets -p|egrep "iso|disk9" ( esxcfg-scsidevs -m),1,1,1

c. Define the pool - same as creating datastore vmkfstools -C

 virsh pool-define-as --name kvm-training-disk9 --type iscsi --source-host \
--source-dev \
--target /dev/disk/by-path
Pool kvm-training-disk9 defined

where name can be specific to VM name, is internal CVM IP, source dev is iqn name
of the iscsi lun, and  have it defined in /disk/by-path.

[root@NTNX-12AM2K480036-A by-path]# cd /dev/disk/by-path
root@NTNX-12AM2K480036-A by-path]# ls

d. Activate the pool

[root@NTNX-12AM2K480036-A ~]# virsh pool-list
Name                 State      Autostart
CentOS-6.4.iso       active     no
default              active     yes
(it shows only active pools)

[root@NTNX-12AM2K480036-A ~]# virsh pool-list --all -- shows all the pool (esxcfg-scsidevs )
Name                 State      Autostart
CentOS-6.4.iso       active     no
default              active     yes
kvm-training-disk9   inactive   no

Activate the pool
virsh # pool-start kvm-training-disk9
Pool kvm-training-disk9 started

Autostart the pool if there is a reboot
virsh # pool-autostart kvm-training-disk9
Pool kvm-training-disk9 marked as autostarted

virsh # pool-list ( esxcfg-scsidevs -m)
Name                 State      Autostart
CentOS-6.4.iso       active     no
default              active     yes
kvm-training-disk9   active     yes

Verify the config
[root@NTNX-12AM2K480036-A ~]# virsh pool-dumpxml kvm-training-disk9
<pool type='iscsi'>
  <capacity unit='bytes'>17179869184</capacity>
  <allocation unit='bytes'>17179869184</allocation>
  <available unit='bytes'>0</available>
    <host name=''/>
    <device path=''/>

List the volume

[root@NTNX-12AM2K480036-A ~]# virsh vol-list --pool kvm-training-disk9 (esxcfg-scsidevs -m)

Name                 Path
unit:0:0:0           /dev/disk/by-path/

[root@NTNX-12AM2K480036-A ~]# virsh vol-info --pool kvm-training-disk9 unit:0:0:0
Name:           unit:0:0:0
Type:           block
Capacity:       16.00 GiB
Allocation:     16.00 GiB

Create the VM with following config
cat ~/KVM/Create/disk9 ( chmod +x)

#!/usr/bin/env bash

virt-install \
  --description "CentOS 6.4 - minimal desktop" \
  --connect qemu:///system \
  --name kvm-training9 \
  --disk vol=kvm-training-disk9/unit:0:0:0,format=raw,cache=none,io=native,bus=virtio \
  --ram 1024 \
  --vcpu 1 \
  --graphics vmc,port=5905,listen= \
  --os-type linux \
  --os-variant rhel6 \
  --disk vol=CentOS-6.4.iso/unit:0:0:0,format=raw,io=native,bus=ide,device=cdrom \
  --noautoconsole \
  --wait 0  --network network=VM-Network,model=virtio \

run ~/KVM/Create/disk9

[root@NTNX-12AM2K480036-A by-path]# virsh list ( similar to vim-cmd vmsvc/getallvms or vm-support -V esxcli vm  process list)
 Id    Name                           State
 1     NTNX-12AM2K480036-A-CVM        running

52    kvm-training9                  running

virsh # dumpxml 52  ---- like vmx file <domain type='kvm' id='52'>
  <description>CentOS 6.4 - minimal desktop</description>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
    <type arch='x86_64' machine='rhel6.4.0'>hvm</type>
    <boot dev='hd'/>
  <clock offset='utc'/>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native'/>
      <source dev='/dev/disk/by-path/'/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw' io='native'/>
      <source dev='/dev/disk/by-path/'/>
      <target dev='hdc' bus='ide'/>
      <alias name='ide0-1-0'/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    <controller type='usb' index='0'>
      <alias name='usb0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    <controller type='ide' index='0'>
      <alias name='ide0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    <interface type='network'>
      <mac address='52:54:00:3e:4c:f5'/>
      <source network='VM-Network'/>
      <target dev='vnet6'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    <serial type='pty'>
      <source path='/dev/pts/6'/>
      <target port='0'/>
      <alias name='serial0'/>
    <console type='pty' tty='/dev/pts/6'>
      <source path='/dev/pts/6'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5909' autoport='no' listen=''>
      <listen type='address' address=''/>
      <model type='cirrus' vram='9216' heads='1'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
  <seclabel type='dynamic' model='selinux' relabel='yes'>

 [root@NTNX-12AM2K480036-A Create]# ps -ef|grep qemu |grep training9- similar to vmx module in vmware
qemu     14276     1  0 15:44 ?        00:00:42 /usr/libexec/qemu-kvm -name kvm-training9 -S -M rhel6.4.0 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -uuid 81f4f17f-b9e8-d533-1b89-6295c5ff6048 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/kvm-training9.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/dev/disk/by-path/,if=none,id=drive-virtio-disk0,format=raw,cache=none,aio=native -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/dev/disk/by-path/,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw,aio=native -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=36,id=hostnet0,vhost=on,vhostfd=39 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:3e:4c:f5,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

virt-top (esxtop) -1,2,3
 virt-top 17:40:34 - x86_64 24/24CPU 1600MHz 48326MB
9 domains, 8 active, 8 running, 0 sleeping, 0 paused, 1 inactive D:0 O:0 X:0
CPU: 1.0%  Mem: 22008 MB (22008 MB by guests)

    1 R  23K  25K   96   89 NTNX-12AM2K4 vnet0
   43 R  723    0    9    0 gasmith-trai vnet2
    52 R    0    0    0    0 kvm-training vnet6

We have virt_install in Nutanix CVM to automate these steps ( create iscsi disk, create pool and install VM)

 .CVM:$ ./virt_install --cdrom /ImageStore/win7.iso --disk 128 --nic VM-Network --vnc_port 5999 --os_type windows --os_variant win7 --name kvm-testing-win27

2013-06-27 11:21:43 INFO Preparing nutanix disks: 0%
2013-06-27 11:21:46 INFO Preparing nutanix disks: 50%
2013-06-27 11:21:46 INFO Preparing nutanix disks: 100%
2013-06-27 11:21:46 INFO Creating libvirt storage pools: 0%
2013-06-27 11:21:50 INFO Creating libvirt storage pools: 50%
2013-06-27 11:21:52 INFO Creating libvirt storage pools: 100%
2013-06-27 11:21:52 INFO Running virt-install

 ( connect to VNC -:99 disable Adapt and max quality in vnc viewer)
Connect to the console and install the CentOS.(virt-manager)

virsh # list --all (vmsvc/getallvms)
 Id    Name                           State
 1     NTNX-12AM2K480036-C-CVM        running
 40    kvm-training03                 running
 41    kvm-training6                  running
 42    kvm-training4                  running
 47    kvm-testing-win21              running
 48    kvm-testing-win24              running
 -     kvm-testing-win99              shut off

virsh # start kvm-testing-win99  -- vim-cmd vmsvc/power.on
Domain kvm-testing-win99 started