Skip to content

Commit

Permalink
update and add session 04 and topics closes #16 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
billspat authored Oct 20, 2023
1 parent 1d9cd37 commit 8f6a4fc
Show file tree
Hide file tree
Showing 14 changed files with 727 additions and 9 deletions.
247 changes: 247 additions & 0 deletions docs/exercises/exercise_vm_via_cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
## CLI Interface Tutorial / Exercise

*for the MSU Cloud Computing Fellowship*

This tutorial walks through using the CLI with code you can copy, modify and try. This will run in the Azure portal "cloud shell" if you have set it up to use the CLI interface (not the PowerShell interface)

You can refer to the original tutorial which is perhaps more clear, but doesn't quite fit our situation : [Quickstart: Create a Linux virtual machine with the Azure CLI](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-cli)

If you follow this - please don't delete your resource group!

In the code below, lines that start with `#` are comments only, but the other lines are commands. You can copy/paste one command at at time
into the CLI of the cloud shell. Since these are long commands, a long command can be broken up using the line-continuation character which is the back-slash `\` so one command are all the lines until the last one that does not end with a back-slash

### First, Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.

To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also open Cloud Shell in a separate browser tab by going to https://shell.azure.com/bash. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and select Enter to run it.

### Exploratory Commands

The Azure CLI command line always starts with the base command `az` and is followed by the type of resource you are working with, followed by
the subcommand you are running, followed by additional options.

If you are running these on your computer, you will first have to run the command `az login` You may not have to do this
if you are using the Azure portal cloud shell (since you are already logged in)

To see the Azure account you are currently running in, try

`az account show`

example output (in JSON format):
```
{
"environmentName": "AzureCloud",
"homeTenantId": "22177130-642f-41d9-9211-74237ad5687d",
"id": "45155965-8c04-4910-b30d-900000b9c631",
"isDefault": true,
"managedByTenants": [],
"name": "MSU Cloud Computing Fellowship",
"state": "Enabled",
"tenantId": "22177130-642f-41d9-9211-74237ad5687d",
"user": {
"name": "[email protected]",
"type": "user"
}
}
```

To see the list of storage accounts you have access to, try the following command.

Before running these command, we've used you really need to edit anything that you see in angle brackets. For example, where
you see `<mygroupname>` put in your actual resource group name.

`az storage account list -g <mygroupname>`

The documentation for this command and others related to storage accounts is here: <br>
https://learn.microsoft.com/en-us/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-show

An example command they give looks like this:

`az storage account show -g MyResourceGroup -n MyStorageAccount`

In their examples, you just have to know that you need to replace your group and storage account names for the parameters.


### Try running the following commands

Before running these commands you really need to edit anything that you see in angle brackets. For example, where
you see `<mygroupname>` put in your actual resource group name.

```bash
# create a VM and all of the items needed for it : OS Disk, network security group, etc.
# replace the names with your own group and other names.
# Remember to change the group and VM name

az vm create \
--resource-group <mygroupname> \
--name <mytestvm> \
--image Debian11 \
--public-ip-sku Standard \
--admin-username azureuser \
--tags 'activity=cli_tutorial' \
--generate-ssh-keys

```

Here is a real example command for my own resource group:

```
az vm create \
--resource-group ccf23_billspat \
--name billspat-tutorial-vm \
--image Debian11 \
--public-ip-sku Standard
--admin-username billspat \
--tags 'activity=cli_tutorial' \
--generate-ssh-keys
```

The output will look something like this:

```
{
"fqdns": "",
"id": "/subscriptions/047e742e-cb26-41e6-a9d6-9d42c67f43e6/resourceGroups/ccf22_billspat/providers/Microsoft.Compute/virtualMachines/billspat-tutorial-vm",
"location": "northcentralus",
"macAddress": "00-22-48-8F-48-C2",
"powerState": "VM running",
"privateIpAddress": "10.4.0.5",
"publicIpAddress": "20.236.78.140",
"resourceGroup": "ccf23_billspat",
"zones": ""
}
```
Copy and paste that somewhere for reference last.

**Now give that VM a purpose and install a web server**. There are many webserver that you can install, but nginx is easy to install and open source. You can do this in two ways

1) use the CLI to run a command on the VM directly
```
az vm run-command invoke \
--resource-group <mygroupname> \
--name <mytestvm> \
--command-id RunShellScript \
--scripts "sudo apt-get update && sudo apt-get install -y nginx"
```

2) use SSH to connect to the VM and run it directly. that will be for another tutorial!

The output from the command above will be something like

```JSON
{
"value": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"message": "Enable succeeded: \n[stdout]\ne libnginx-mod-http-xslt-filter.\r\nPreparing to unpack .../23-libnginx-mod-http-xslt-filter_1.14.2-2+deb10u4_amd64.deb ...\r\nUnpacking libnginx-mod-http-xslt-filter (1.14.2-2+deb10u4) ...\r\nSelecting previously unselected package libnginx-mod-mail.\r\nPreparing to unpack .../24-libnginx-mod-mail_1.14.2-2+deb10u4_amd64.deb ...\r\nUnpacking libnginx-mod-mail (1.14.2-2+deb10u4) ...\r\nSelect etc

```

**Open port 80 for web traffic**

By default, only SSH connections are opened when you create a Linux VM in Azure. Use az vm open-port to open TCP port 80 for use with the NGINX web server:

```bash
az vm open-port --port 80 --resource-group mygroupname --name mytestvm
```

**check that it's working**

Put the IP address from the output above (or use the portal to find it) into your browser to see if you can connect,. If so, then great! you've just built a web server.

**Delete everything**

You can't delete your how resource group, but luckily we used tags to create the VM so we can just delete resource by tag.

You can use the portal to delete these resources, but if here are commands to do it with the CLI. You can delete things by name, like this

```bash
az vm delete \
--resource-group mygroup \
--name myvm
```

but every resource has a unique ID, and can be deteled using that ID with the command
`az resource delete --ids IDVALUE` You can get those IDs using `az resource list...`

```bash
# list all resources just created (change the tag to match what you used if necessary)
az resource list --tag activity=cli_tutorial

# The CLI can filter and change the format of it's output
# list ONLY the resource IDs using the "query" and tabular output
az resource list --tag activity=cli_tutorial --query "[].id" -o table

# delete them all using a shell loop (tsv does not output a header line)
IDS=$(az resource list --tag activity=cli_tutorial --query "[].id" -o tsv)
for id in $IDS; do az resource delete --ids $id; done

```
### Complete example commands (using my resource group)

```bash
az vm create \
--resource-group ccf22_billspat \
--name billspat-tutorial-vm \
--image Debian \
--public-ip-sku Standard \
--admin-username billspat \
--tags 'activity=cli_tutorial' \
--generate-ssh-keys

# copy and paste the output of that

az vm run-command invoke \
--resource-group ccf22_billspat \
--name billspat-tutorial-vm \
--command-id RunShellScript \
--scripts "sudo apt-get update && sudo apt-get install -y nginx"

az vm open-port --port 80 --resource-group ccf22_billspat --name billspat-tutorial-vm

# list all resources just created
az resource list --tag activity=cli_tutorial

# list ONLY the resource IDs using the "query" and tabular output
az resource list --tag activity=cli_tutorial --query "[].id" -o table

# delete them all using a shell loop (tsv does not output a header line)
IDS=$(az resource list --tag activity=cli_tutorial --query "[].id" -o tsv)
for id in $IDS; do az resource delete --ids $id; done

```

**bonus points**: set shell variables for the resource group and name and use them in the commands. For example

```bash
RG=ccf22_billspat
VMNAME=billspat-tutorial-vm
az vm create \
--resource-group $RG \
--name $VMNAME \
--image Debian \
--public-ip-sku Standard \
--admin-username billspat \
--tags 'activity=cli_tutorial' \
--generate-ssh-keys

# ... do other stuff, then delete

az vm delete \
--resource-group $RG \
--name $VMNAME
```


### References:


- Quickstart: Create a Linux virtual machine with the Azure CLI https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-cli
- Azure Command-Line Interface (CLI) documentation https://learn.microsoft.com/en-us/cli/azure/
- All `az vm...` command options : https://learn.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest
- Use tags to organize your Azure resources (with the Azure CLI)! https://techcommunity.microsoft.com/t5/azure/use-tags-to-organize-your-azure-resources-with-the-azure-cli/m-p/1798955
-
Binary file added docs/img/storage/azportal_storage_screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ Each approximately 2-week session consists of

3. [Cloud Storage](./sessions/03_cloud_storage.md)
* Meeting **October 6, 3pm**
* Assignment/Exercise: [analyzing weather data in the cloud](./exercises/exercise_using_the_cloud_to_summarize_and_visualize_data.md)

4. Databases and Data Analytics Systems on the Cloud for research

4. Interfaces to build cloud resources
* Meeting **October 20, 3pm**
* Exercises: Using SQL database for research data
* Assignment/Exercise: [analyzing weather data in the cloud](./exercises/exercise_using_the_cloud_to_summarize_and_visualize_data.md)

5. Big Data Systems and the cloud
5. Databases, Data Analytics Systems, and Big Data on the Cloud
* Meeting **November 3, 3pm**:
* Exercise: Using R and Python on a databricks cluster
* Exercise: Using SQL databases to store and summarize weather data.

6. Serverless Cloud Computing
* Meeting **November 17, 3pm**
Expand Down
4 changes: 2 additions & 2 deletions docs/sessions/03_cloud_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Cloud storage was engineered to save millions of files for millions of users and

- Exercise: [Azure Storage Pricing](../exercises/storage_pricing_exercise.md)

<!-- https://learn.microsoft.com/en-us/azure/storage/files/storage-files-quick-create-use-windows?source=recommendations -->
- Exercise: [Create an SMB Azure file share and connect it to a Windows VM using the Azure portal]https://learn.microsoft.com/en-us/azure/storage/files/storage-files-quick-create-use-windows]

## Readings

Expand Down Expand Up @@ -72,7 +72,7 @@ Notes:
- Knowledge of Linux systems (mount points, fstab, etc) required


**Optional: Python And Blob Storage**

This describes an a different method for moving files to/from cloud storage: using code. This does not require you to 'mount' the storage to your VM.

Expand Down
61 changes: 61 additions & 0 deletions docs/sessions/04_organization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: 4 - Cloud Services Organization
---

# Session 4: Cloud Services Organization

![disorganized wiring](http://www.itrw.net/wp-content/uploads/2016/06/server_spaghetti_1.jpg)


## Goals
This is a collection of topics about the organizational aspects of cloud computing so may seem unfocused but each topic is important
for successful application of cloud computing. We hope to provide you with the following understanding of:

- what options for interacting with cloud services
- Understand difference between the cloud manager and resource you've created
- Know how to use program to automate the creation and deletion of cloud resources
- How to find basic cost estimates
- what are the "service levels" and the related responsibilities for different kinds of cloud resources, and how does that help you choose a service


## Introduction

We might think of using cloud computing in 3 areas:

1. using the resources (which is our real goal),
2. definining and creating these resources, and
3. managing them.

We may need a virtual machine to run our program to calculate or analyze our data, but we need to determine the properties of that virtual machine and create it first. Surrounding all of that is how we interact with the cloud service to do that, how we estimate and observe the costs, manage and identify all the other components a cloud VM needs, and make it as secure as possible.

I'm lumping all of these last pieces into 'managing' cloud resources. It may be the most boring of all the topics. The concepts may cover any resource you create in the cloud, and in general apply to all cloud service providers. However the details of _how_ you do it are very specific to each cloud vendor. In fact the methods may be convoluted or less than straightforward, so there are many companies that provide additional tools just to manage cloud resources in a more consistent or easier way than the cloud providers allow you


## Interfaces to Cloud Services

In session one we talked about the client/server model of computing which is so ubiquotous is seems like the _only_ model of computing.

The core of the cloud model is that "everything has an API" or Application Programming Interface: the commands that can be used for code-to-code interaction.

Note the "Interface" we are discussing here is for interacting with Azure to manage resources.
Once created, the resources themselves may have their OWN interface, which is highly dependent on the resource (for example, the
interface to a Microsoft Windows virtual machine is the remote desktop client and then of course Windows itself)

#### Interfaces Reading:

- [Interfacing with Cloud Services](../topics/intro_to_cloud_interfaces.md)

#### Interfaces Activity:

- Introduction the the Cloud Shell https://docs.microsoft.com/en-us/azure/cloud-shell/overview
- [Create a Linux virtual machine with the Azure Command Line Interface ( CLI) ](../exercises/exercise_vm_via_cli.md)

## Other topics:

- [Moving Data in the cloud](../topics/moving_data/moving_data_in_cloud.md)
- [Staying Organized in Azure](../topics/staying_organized_in_azure.md)
- [Costs](../topics/azure_cloud_cost_basics.md)
- [Monitoring](../topics/monitoring_in_azure.md)
- [Service Level Model of cloud computing](../topics/service_level_model_of_cloud.md)


Loading

0 comments on commit 8f6a4fc

Please sign in to comment.