DEV Community

Jay Gordon for Microsoft Azure

Posted on

Azure Cloud Shell Tips for SysAdmins Part IV - View and Modify your VM.

As an Azure Advocate, one of the things I spend my time doing is learning the easiest ways for beginners to use Microsoft Azure. Today I want to share with you a few ways to utilize some tools that are built right into Azure.

In my last blog post Using Azure CLI I took you deeper into the tools available in Azure.

Today I will use the Cloud Shell to view and modify the VM I created last time.

Why from the Cloud Shell?

Simply put, because it's always there for you in Azure. No matter where you are in the world, if you log into your Azure Cloud Shell you're able to work on your Azure solution. You can execute remote jobs, automate services using tools like Ansible or modify your Kubernetes cluster. It's all possible right from the Azure Cloud Shell in the browser.

The Azure CLI tool will once again be the focus of this tutorial. I will run through commands that will show you how to get info on a running VM and execute commands to modify it from the Cloud Shell

Requirements.

You won't need much to get started. If you don't have a Microsoft Azure account yet, you can sign up for $200 in credit and 12 months worth of free services.

Querying Azure Resource Manager

First, open a cloud shell, this can be done by going to the cloud shell logo in the portal, right of the search bar or navigate directly by going to https://shell.azure.com.

Now I forgot the name of my resource group. Dang. I guess I will start by querying via the CLI for the resource groups I currently have in use:

jay@Azure:~$ az group list --output table
Name                        Location    Status
--------------------------  ----------  ---------
cloud-shell-storage-eastus  eastus      Succeeded
DefaultResourceGroup-EUS    eastus      Succeeded
devtoapp                    eastus      Succeeded
jaydestro-blog              centralus   Succeeded
NetworkWatcherRG            eastus2     Succeeded
Enter fullscreen mode Exit fullscreen mode

See how I added the --output table portion to the command? I did this to make the output a bit more human readable. Without adding the --output command with a format I'd like (json,jsonc,table,tsv,yaml,none) the default output is JSON. While JSON is great to work with when declaring what my infrastructure might be or maybe for a document database, it's not the easiest to read when trying to work on resources.

I used the Azure CLI application to query Azure Resource Manager. I am now reminded that devtoapp is the Resource Group that my VM is running in. Now I will get info on the VM. The -d flag specifically states to provide additional details on the resource being queried.

jay@Azure:~$ az vm list -g devtoapp -d --output table
Name        ResourceGroup    PowerState    PublicIps      Fqdns         Location    Zones
----------  ---------------  ------------  -------------  ------------------------------------  ----------  -------
devtoappvm  devtoapp         VM running    13.90.240.117  devtoappvm.eastus.cloudapp.azure.com  eastus
Enter fullscreen mode Exit fullscreen mode

Now we have the basics, the name is devtoappvm and there's a public IP address. What kind of CPU? How much memory? Do I have to ssh into the server to get this? Of course not!

To check what my VM size is, I can run a quick command and grep for the output I am looking for:

jay@Azure:~$ az vm show -g devtoapp -n devtoappvm |grep vmSize
    "vmSize": "Standard_DS1_v2"
Enter fullscreen mode Exit fullscreen mode

The documentation for General purpose virtual machine sizes states this is a pretty low end machine. Giving me only 1 vCPU and 3.5 GB of memory. In the next section we'll modify to a new VM type so I can get some more horsepower for my server.

Word of warning!

Do not do these commands on a production server unless you're ready to have potential downtime. These are commands that are meant to be instructional. A production system may not have the proper redundancy to handle an outage. In the case of this demo tutorial, I am working with a sever that serves no real purpose, so showing you how to execute these commands serves no risk. But if I were to do this in production I would take the following precautions:

  • Work with my team to ensure notice is given on maintenance
  • Ensure there is proper backups of the system we are working with, test they are working
  • Verify you have redundancy in the application, is this a Single Point of Failure? If so, time to check out Designing reliable Azure applications

Modifying a VM

Time to upgrade the VM size and upgrade my Standard_DS1_v2 up to a Standard_DS3_v2 which will provide me with 4 vCPU and 14GB of RAM. That's plenty of horsepower to allow me to build and process data for my application.


jay@Azure:~$ az vm resize --resource-group devtoapp --name devtoappvm --size Standard_DS3_v2
 - Running ..
Enter fullscreen mode Exit fullscreen mode

The VM will restart during this process then will map the disks with data and operating system to the new VM. Be prepared for a few minutes of downtime during this process while Azure Resource Manager modifies your VM with it's new configuration.

When this has completed I will get some JSON output stating all the information on the server as the output. This provides me with details that my server was successfully upgraded:

{
  "additionalCapabilities": null,
  "availabilitySet": null,
  "diagnosticsProfile": null,
  "hardwareProfile": {
    "vmSize": "Standard_DS3_v2"
  },
Enter fullscreen mode Exit fullscreen mode

I can now ssh in and start working with this new, bigger VM!

azureuser@devtoappvm:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:          14002         581       12358           0        1062       13112
Swap:             0           0           0
azureuser@devtoappvm:~$

Enter fullscreen mode Exit fullscreen mode

Time to install my new app, but there's an issue...

azureuser@devtoappvm:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            6.9G     0  6.9G   0% /dev
tmpfs           1.4G  680K  1.4G   1% /run
/dev/sda1        29G  2.6G   27G   9% /
tmpfs           6.9G     0  6.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           6.9G     0  6.9G   0% /sys/fs/cgroup
/dev/sda15      105M  3.6M  101M   4% /boot/efi
/dev/sdb1        28G   45M   26G   1% /mnt
tmpfs           1.4G     0  1.4G   0% /run/user/1000

Enter fullscreen mode Exit fullscreen mode

I need way more disk space than 27GB. What to do?

What's Next?

In part V I will show you how to add a new disk, format and mount it for use with your Linux server all from the Azure Cloud Shell!

Till then, keep learning, keep trying new stuff and of course reach out to myself on Twitter at @jaydestro.

Top comments (1)

Collapse
 
successhawk profile image
Nathan Hawk

Good stuff, but I really wanted to see you parse some JSON. I believe you manually parsed and typed it in every case.