This the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Running Photon OS on Microsoft Azure

You can use Photon OS as a run-time environment for Linux containers on Microsoft Azure. You can set up and run the cloud-ready version of Photon OS as an instance of a virtual machine in the Azure cloud. Once Photon OS is running, you can deploy a containerized application in Docker.

Note: These instructions apply to Photon OS 2.0 and 3.0. There is no Photon OS 1.0 distribution image for Microsoft Azure.

1 - Prerequisites for Running Photon OS on Azure

Before you use Photon OS with Microsoft Azure, perform the following prerequisite tasks:

  1. Verify that you have a Microsoft Azure account. To create an account, see https://azure.microsoft.com

  2. Install the latest version of Azure CLI. See Install Azure CLI 2.x and Get started with Azure CLI 2.x.

  3. Verify that that you have a pair of SSH public and private keys.

  4. Download and extract the Photon OS VHD file.

    VMware packages Photon OS as a cloud-ready virtual hard disk (VHD file) that you can download for free from Packages URL. This VHD file is a virtual appliance with the information and packages that Azure needs to launch an instance of Photon in the cloud. After you have downloaded the distribution archive, extract the VHD file from it. You will later need to upload this VHD file to Azure, where it will be stored in an Azure storage account. For more information, see Downloading Photon OS.

2 - Set Up Azure Storage and Uploading the VHD

You can use either the Azure Portal or the Azure CLI to set up your Azure storage space, upload the Photon OS VHD file, and create the Photon OS VM.

Setting Up Using the Azure Portal

You can use the Azure portal to set up Photon OS in the Azure cloud. The following instructions are brief. Refer to the Azure documentation for details.

  1. Log in to the Azure portal at http://portal.azure.com.
  2. Create a resource group. In the toolbar, choose Resource Groups, click +Add , fill in the resource group fields, and choose Create.
  3. Create a storage account. In the toolbar, choose Storage Accounts, click +Add , fill in the storage account fields (and the resource group you just created), and choose Create.
  4. Select the storage account.
  5. Scroll down the storage account control bar, click Containers (below BLOB SERVICE), click +Container , fill in the container fields, and choose Create.
  6. Select the container you just created.
  7. Click Upload and upload the Photon OS VHD image file to this container.
  8. Once the VHD file is uploaded, refer to the Azure documentation for instructions on how to create and manage your Photon OS VM.

Setting Up Using the Azure CLI

You can use the Azure CLI 2.x to set up Photon OS.

Note: Except where overridden with parameter values, these commands create objects with default settings.

  1. Create a resource group.

    From the Azure CLI, create a resource group.

    az group create \
     --name <your_resource_group> \
     --location westus
    
  2. Create a storage account

    Create a storage account associated with this resource group.

    az storage account create \
        --resource-group <your_resource_group> \
        --location westus \
        --name <your_account_name> \
        --kind Storage \
        --sku Standard_LRS
    
  3. List the Keys for the Storage Account

    Retrieve the keys associated with your newly created storage account.

    az storage account keys list \
        --resource-group <your_resource_group> \
        --account-name <your_account_name>
    
  4. Create the Storage Container

    Create a storage container associated with your newly created storage account.

    Note: The sample create.sh script, described below, does this for you programmatically.

    az storage container create \
        --account-name <your_account_name> \
        --name <your_container_name>
    
  5. Verify Your Setup in the Azure Portal

    1. Log into the Azure portal using your account credentials.
    2. From the left toolbar, click Storage Accounts. You should see your storage accounts.
    3. Select the storage account.
    4. Scroll down the storage account control bar and click Containers (below BLOB SERVICE). You should see the container you created.
  6. Upload the Photon OS Distribution to Your Storage Container

    The Photon OS distribution for Azure is 16GB. You can download it locally or to a mounted, shared location.

    az storage blob upload \
        --account-name <your_account_name> \
        --account-key <your_account_key> \
        --container-name <your_container_name> \
        --type page \
        --file <vhd_path> \
        --name <vm_name>.vhd
    

Example Setup Script

You can use the following script (create.sh) to upload your VHD file programmatically and create the VM. Before you run it, specify the following settings:

  • resource_group name
  • account_name
  • account_key (public or private)
  • container_name
  • public_key_file
  • vhd_path and and vm_name of the Photon OS VHD distribution file

The following script returns the complete IP address of the newly created VM.

#!/bin/bash
vhd_path=$1
vm_name=$2
export PATH=$PATH:/root/azure_new/bin/az
echo PATH=$PATH
resource_group=""
account_name=""
account_key=""
container_name="mydisks"
url="https://${account_name}.blob.core.windows.net/${container_name}/${vm_name}.vhd"
public_key_file="/root/azure_new/jenkins.pub"
echo "########################"
echo "#   Create container   #"
echo "########################"
/root/azure_new/bin/az storage container create --account-name ${account_name} --name ${container_name}
echo "##################"
echo "#   Upload vhd   #"
echo "##################"
/root/azure_new/bin/az storage blob upload --account-name ${account_name} \
    --account-key ${account_key} \
    --container-name ${container_name} \
    --type page \
    --file ${vhd_path} \
    --name ${vm_name}.vhd
echo "##################"
echo "#   Create vm    #"
echo "##################"
echo "az vm create --resource-group ${resource_group} --location westus --name ${vm_name} --storage-account ${account_name} --os-type linux --admin-username michellew --ssh-key-value ${public_key_file} --image ${url} --use-unmanaged-disk ... ..."
/root/azure_new/bin/az vm create --resource-group ${resource_group} --location westus --name ${vm_name} --storage-account ${account_name} --os-type linux --admin-username michellew --ssh-key-value ${public_key_file} --image ${url} --use-unmanaged-disk

3 - Remove Photon OS From Azure

You can use the following delete.sh script to programmatically and silently remove the VM instance, VHD file, and container.

Consider deleting idle VMs so that you are not charged when not in use.

Before you run it, specify the following settings:

  • resource_group name (from step 1, above)
  • account_name (from step 2, above)
  • account_key (public or private) (from step 3, above)
  • container_name (from step 4, above)
  • public_key_file
  • vm_name of the Photon OS VHD distribution file

delete.sh

#!/bin/bash
vm_name=$1
resource_group=""
account_name=""
account_key=""
container_name="mydisks"
url="https://${account_name}.blob.core.windows.net/${container_name}/${vm_name}.vhd"
public_key_file="/root/azure_new/jenkins.pub"
exit_code=0
echo "##################"
echo "#   Delete vm    #"
echo "##################"
echo "az vm list  --resource-group ${resource_group} ... ..."
/root/azure_new/bin/az vm list  --resource-group ${resource_group}
echo "az vm delete --resource-group ${resource_group} --name ${vm_name} --yes ... ..."
/root/azure_new/bin/az vm delete --resource-group ${resource_group} --name ${vm_name} --yes
if [$? -ne 0];then
   exit_code=1
fi
echo "az vm list  --resource-group ${resource_group} ... ..."
/root/azure_new/bin/az vm list  --resource-group ${resource_group}
echo "##############$####"
echo "#   Delete vhd    #"
echo "###############$###"
echo "az storage blob list --account-name ${account_name} --container-name ${container_name} ... ..."
/root/azure_new/bin/az storage blob list --account-name ${account_name} --container-name ${container_name}
echo "az storage blob delete --account-name ${account_name} --container-name ${container_name} --name ${vm_name}.vhd ... ..."
/root/azure_new/bin/az storage blob delete --account-name ${account_name} --container-name ${container_name} --name ${vm_name}.vhd
if [$? -ne 0];then
   exit_code=1
fi
echo "az storage blob list --account-name ${account_name} --container-name ${container_name} ... ..."
/root/azure_new/bin/az storage blob list --account-name ${account_name} --container-name ${container_name}
echo "########################"
echo "#   Delete container   #"
echo "########################"
/root/azure_new/bin/az storage container delete --account-name ${account_name} --name ${container_name}
/root/azure_new/bin/az storage container delete --account-name ${account_name} --name vhds
exit ${exit_code}

You can now proceed to Deploying a Containerized Application in Photon OS.