In our previous article, we walked through the steps of installing Photon Controller into our ESXi environment using the new Photon Controller Installer UI. In this article, we will learn how to provision our first Virtual Machine using Photon Controller and the Photon CLI. Before we get started, we first need to initialize our Photon Controller instance and create some of the initial configurations such as Tenants, Resource Tickets, Projects, Flavors, Images & Networks.
- Test driving VMware Photon Controller Part 1: Installation
- Test driving VMware Photon Controller Part 2: Deploying first VM
- Test driving VMware Photon Controller Part 3a: Deploying Kubernetes
- Test driving VMware Photon Controller Part 3b: Deploying Mesos
- Test driving VMware Photon Controller Part 3c: Deploying Docker Swarm
Tenants, Resource Tickets & Projects
As mentioned in the previous article, Photon Controller is a multi-tenant system which allows you to create different tenants for your different consumers like HR, Finance or Engineering for example.
Each tenant is associated with a Security Group that maps to a set of users/groups that can access the tenant's resources. This capability is only available when the Lightwave Identity Source is configured during the initial deployment of Photon Controller. A Resource Ticket represents an collection of compute, storage and networking resources with specific capabilities, limits and quotas that is associated at the tenant level. These resources can then be sub-divided into something consumable called Projects that draws its quotas and limits from their respective Resource Tickets. You can have multiple Resource Tickets and Projects in a given Tenant, but each Project is mapped to a specific Resource Ticket.
Here is an example on how you might use Resource Tickets and Projects. Lets say you have some "High" performant resources which is for your developers working on a very important application for the business, so you create a Gold Resource Ticket. You then also have some "OK" performant resources for developers that are prototyping new ideas and do not necessary care for high end resources, so you create a Silver Resource Ticket. Obviously, there are several "important" components that make up this single application that is being developed. Based on the individual component teams requirements, you decide to create Project A and Project B with their respective resource requirements which pull from the Gold Resource Ticket. You can also have the same folks working on other Projects which pull from a completely different Resource Ticket like the one shown in the Silver Resource Ticket.
Note: For those of you who are familiar with VMware's vCloud Director (vCD) product, you can think of Tenant -> Resource Ticket -> Project similiar to vCD's Organization -> Provider VDC -> Organization VDC concept. vSphere is not a multi-tenant system, but you could also think of its Clusters -> Resource Pool similiar to Resource Ticket -> Project.
Lets go ahead and create a Tenant, Resource Ticket and Project using the Photon CLI. Although you can create these objects using the Photon Controller Management UI, I have found that the UI actually enforces additional parameters than the CLI when creating Resource Tickets. We will stick with the CLI for now but you are more than welcome to use the UI for these sections if you wish.
Step 1 - If you have not done so already, set the target of your Photon CLI to the Photon Controller instance you deployed from the previous article
./photon target set http://[IP]:28080
Step 2 - Create a tenant by running the following command and specifying a name:
./photon -n tenant create Engineering
Step 3 - To use the tenant we just created, we will need to set the tenant by running the following command and specifying the name of our tenant:
./photon tenant set Engineering
When creating a Resource Ticket, there are only two mandatory limits that you need to specify which is the VM's memory (GB) and the number of VMs (COUNT). The syntax to the limits param is a comma separated tuple that consists of Name (e.g. vm.memory), Value (e.g. 16) and Units (e.g. GB, MB, KB, COUNT).
Step 4 - We will create a Resource Ticket called gold-ticket and set the memory limit to 16GB with max number of VMs to 100 by running the following command:
./photon -n resource-ticket create --name gold-ticket --limits "vm.memory 16 GB, vm 100 COUNT"
Step 5 - Next, we will create a Project called secret-project which will just consume the full limits of our Gold Resource Ticket by running the following command:
./photon -n project create --resource-ticket gold-ticket --name secret-project --limits "vm.memory 16 GB, vm 100 COUNT"
Step 6 - Lastly, to use the Project we just created, we will need to set the project by running the following command and specifying the name of our Project:
./photon project set secret-project
When creating Resource Tickets and Projects, you also have the option of creating your own user-defined cost. In the example below, I have something called foo which can have max of 50 and bar which can have a max of 5. We can then consume these user-defined cost when creating our Project as you can see in the example below.
./photon -n resource-ticket create --name silver-ticket --limits "vm.memory 16 GB, vm 100 COUNT, foo 50 COUNT, bar 5 COUNT"
./photon -n project create --resource-ticket silver-ticket --name beta-project --limits "vm.memory 16 GB, vm 100 COUNT foo 25 COUNT, bar 2 COUNT"
Images, Flavors & Networks
When a new VM is instantiated from Photon Controller, it is constructed from an Image along with a VM and Disk Flavor. An Image can be either an OVF/OVA or VMDK residing in the Photon Controller Image Store. A Flavor describes the amount of resources being consumed by the VM from the Resource Ticket. There are two types of Flavors today, one for VM and one for Disk. Although a Disk Flavor is required as part of creating the VM, it is currently not used for anything today and do not actually count against the Resource Ticket. Obviously this behavior may change in the future. Lastly, if you recall from our initial setup of Photon Controller, we had specified the VM network in which all VMs would be assigned to. You also have the option of associating additional networks in Photon Controller in case you want to provide access to different networking capabilities to your VMs which we will quickly cover as well.
Lets go ahead and run through a simple Image and Flavor configuration which we will be using the VMware PhotonOS 1.0 TP2 OVA.
Step 1 - Download the VMware PhotonOS 1.0 TP2 OVA
Step 2 - Before uploading, lets take a quick look at the current image store by running the following command:
./photon image list
We can see that there is currently only one image which is the Photon Controller Management VMDK that was used to stand up our Photon Controller instance. You will find some additional details such as the Replication Type which can either be EAGER (replicate immediately) or ON_DEMAND (replicate when requested) as well as the State, Size and Replication Progress.
Step 3 - To upload our PhotonOS OVA, we will run the following command:
./photon -n image create photon-1.0TP2.ova -n photon-1.0TP2.ova -i EAGER
Step 4 - Once the image has been successfully uploaded, we can get more details by specifying the image ID by running the following command:
./photon image show bca0f75d-c7c6-4cbd-8859-6010c06b0359
Step 5 - Before we create our VM and Disk Flavor, lets have a look at the Flavors that have already been created by running the following command:
./photon flavor list
There is a total of 5 Flavors that are available out of the box. The mgmt-vm* VM and Disk Flavor is used for deploying the Photon Controller Management VM and you can see the default configurations that are used. The cluster-* VM and Disk Flavors are the default configurations used for the different Cluster Orchestration solutions that Photon Controller supports. You will notice that the configuration are quite large and the reason for this is that these Flavors have been designed for scale and throughput. When we get to the different Cluster Orchestration articles, you will see how these will be important based on the available resources you have in your environment.
Step 6 - We will now create a new VM Flavor called tiny-photon-vm with a cost for CPU count of 1 and MEM count of 2GB by running the following command:
./photon -n flavor create --name tiny-photon-vm --kind "vm" --cost "vm.cpu 1.0 COUNT, vm.memory 2.0 GB, vm.cost 1.0 COUNT"
Step 7 - We will also create a new Disk Flavor called tiny-photon-disk using the ephemeral-disk type with a cost of 1 by running the following command:
./photon -n flavor create --name tiny-photon-disk --kind "ephemeral-disk" --cost "ephemeral-disk 1.0 COUNT"
Optionally, you can also create new Flavors based on the user-defined costs. Here is an example consuming our foo and bar attributes:
./photon -n flavor create --name custom-photon-vm --kind "vm" --cost "vm.cpu 1.0 COUNT, vm.memory 2.0 GB, vm.count 1.0 COUNT, foo 5 COUNT, bar 1 COUNT"
Step 8 - If we now list our Flavors again, we should see the three new Flavors that we had just created.
You can also quickly view all Images and Flavors using the Photon Controller Management UI by clicking on the upper right hand corner on the "Cog Wheel" as shown in the screenshot below.
Step 9 - If you wish to add additional networks to be used in Photon Controller, you can run the following command and specifying the information from your environment:
./photon -n network create --name dev-network --portgroups "VM Network" --description "Dev Network for VMs"
Step 10 - To get a list of all available networks, you can run the following command:
./photon network list
VM & Disk Creation
With all the pieces in place, we are now ready to create our first VM! If you remember from the previous section, to create a VM you must provide an Image and VM and Disk Flavor. We will be using the PhotonOS Image which we will need the ID that was generated earlier. We will also be using the tiny-photon-vm VM Flavor as well as the tiny-photon-disk Disk Flavor. The disks argument below accepts a disk name (can be anything you want to call it), the Disk Flavor and whether it is a boot disk (boot=true) or capacity in case where it is an additional disk.
Step 1 - To create the VM we described above, run the following command and specifying the Image ID from your environment:
./photon vm create --name vm-1 --image bca0f75d-c7c6-4cbd-8859-6010c06b0359 --flavor tiny-photon-vm --disks "disk-1 tiny-photon-disk boot=true"
Step 2 - Using the VM ID that was provided, we can now power on the VM by running the following command:
./photon vm start b0854f44-11da-4175-b6c5-657cacbcd113
Step 3 - Once the VM has been powered on, we can also pull some additional information such as the IP Address from the VM by running the following command:
./photon vm show b0854f44-11da-4175-b6c5-657cacbcd113
Note: You may need to re-run the above command in case the IP Address does not show up immediately.
If you wish to confirm that you can login to the PhotonOS VM that we just deployed from our Image, go ahead and ssh in as root and the default password is changeme which you should get prompted to change. One important thing to be aware of is that all VMs created from the Images are created as VMware Linked Clone (copy-on-write), so that is why the process is extremely fast and efficient.
Step 4 - We can also get additional networking details such as the VM's MAC Address and the current state by running the following command
./photon vm networks b0854f44-11da-4175-b6c5-657cacbcd113
We can also create a VM that contains more than one disk. The example below is using our PhotonOS Image and adding a secondary 5GB disk:
./photon -n vm create --name vm-2 --image bca0f75d-c7c6-4cbd-8859-6010c06b0359 --flavor tiny-photon-vm --disks "disk-1 tiny-photon-disk boot=true, disk-2 tiny-photon-disk 5"
If we wanted to add additional disks after a VM has been created, we just need to create a new Disk and associate that with a Disk Flavor. In the example below, we will create a new Disk Flavor using the persistent-disk type and then create a new disk called data-disk with capacity of 10GB
./photon -n flavor create --name persist-disk --kind "persistent-disk" --cost "persistent-disk 1.0 COUNT"
./photon disk create --name data-disk --flavor persist-disk --capacityGB 10
We can get more details about a specific disk such as the state (attached/detached), capacity, etc. by running the following command and specifying the Disk ID:
./photon disk show 55f425e8-2de4-4d30-b819-64c4fd209c3c
To attach a Disk to a VM, we just need to run the following command specifying the Disk ID as well as the VM ID:
./photon vm attach-disk --disk 55f425e8-2de4-4d30-b819-64c4fd209c3c 4e66e4c9-693e-42b3-9e1e-0d96044a6a42
To detach a Disk from a VM, we just need to run the following command specifying the Disk ID as well as the VM ID:
./photon vm detach-disk --disk 55f425e8-2de4-4d30-b819-64c4fd209c3c 4e66e4c9-693e-42b3-9e1e-0d96044a6a42
I also wanted to quickly mention that you can also provision a VM using the Photon Controller Management UI. To do so, you need to be in the Project view and click on three dots next to the name of the Project as seen in the screenshot below.
Lastly, we will clean up the two VMs along with the disk that we had created.
./photon disk delete 55f425e8-2de4-4d30-b819-64c4fd209c3c
./photon stop b0854f44-11da-4175-b6c5-657cacbcd113
./photon vm delete b0854f44-11da-4175-b6c5-657cacbcd113
./photon vm delete 4e66e4c9-693e-42b3-9e1e-0d96044a6a42
Although we had to cover a few new concepts before we could provision our first VM, hopefully it gave you a better understanding of how Photon Controller works under the hood. The nice thing now is that because we have already done all the heavy lifting such as setting up a Tenant, Resource Ticket & Project, when we take a look at setting up the different Cluster Orchestration solutions, the provisioning workflows should be pretty straight forward 🙂
tami says
hi, thanks a lot i have 2 question
1-what is difference between typical vms and vms deployed with photon controller?
2-why we should use photon controler? whats benefit?
Cormac Hogan says
Hi Will, I don't think you need the :28080 port added to the IP address in step 1, right?
Cormac Hogan says
Never mind Will. There are instances where specifying the load balancer port is necessary. I found out the hard way - https://github.com/vmware/photon-controller/issues/24 😀
Ananda Kammampati says
Nothing major but just wanted to share.
You need a comma (,) after "vm 100 COUNT". Or else you'll get : Error parsing limits, should be: , ...
This one worked for me.
photon -n project create --resource-ticket silver-ticket --name beta-project --limits "vm.memory 16 GB, vm 100 COUNT, foo 25 COUNT, bar 2 COUNT"
Ananda Kammampati says
There are a couple of things that doesn't seem to match up. May be its just my environment, not sure.
For example, "vm-2" was never started manually with the photon command. But when the 10GB persistent disk was added to "vm-2", it somehow got powered on (?!). But still "photon vm list" command shows "vm-2" state as STOPPED.
Also "vm-1" never managed to get an IP address assigned.
(Wondering what others see)