Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

AZ-204 Develop Azure compute

solutions (25-30%)
All code can be found here: https://github.com/AdminTurnedDevOps/AZ204
Code

Implement IaaS Solutions


Provision VMs
Provisioning virtual machines is the practice of creating a deployable and usable
virtual machine that can be used for any purpose (web server, to host a backend
application, etc.)

The four primary ways are:

Azure portal in the Virtual Machine Blade.

ARM Templates using the Microsoft.Compute/virtualMachines API resource.

PowerShell with the AZ module using the New-AzVm cmdlet.

AZ CLI using the az vm create command and switch.

Configure VMs for remote access


Configuring VMs for remote access is so you or others can access the virtual
machine. Not only from a connection perspective, but from an application
availability perspective. For example, let's say you are hosting a website on a
Linux server and the web server is Nginx. Without port 80 or 443 being open, the
user (or you) will not be able to access the serve.r

The three primary ways are:

Creating an Network Security Group NSG in Azure and creating a port


rule to allow inbound connectivity. After creation, the NSG can be
connected to the virtual machines. The inbound connectivity rule can
allow the following: (demo here in the portal)

All public IP's to access the VMs

AZ204 Develop Azure compute solutions 2530% 1


Only certain ports to access the VMs

Only certain IP addresses to access the VMs

When creating a virtual machine, under Inbound port rules, you can allow
PUBLIC inbound port rules, meaning ANYONE can RDP or SSH into the
virtual machine from a network level. They still need a username,
password/SSH key to access the VM. (demo here in the portal)

All virtual machines are created with a default NSG. The default NSG can
be modified with an inbound or outbound port rule. (demo here in the
portal)

Create Container Images for Solutions by Using Docker (code in


GitHub found here)
Container images Docker images) provide a base for your application (think
golden image). The container image can then be used and deployed throughout
the environment.

The two ways of building a Docker image is:

Traditional Docker files (demo here and code found in GitHub)

Using ACR Tasks. ACR tasks is a new way to create, run, push, and patch
containers that are stored in Azure Container Registry ACR. (demo here
and code found in GitHub)

az acr build --image $image --registry $registry $source

Publishing a Docker Image to Azure Container Registry (code in


GitHub here)
ACR Azure Container Registry) is very much like Docker Hub, for example. ACR
is a place in Azure that you can store custom-built or pre-made Docker images.
Once the Docker images are stored in ACR, they can be updated, deployed, and
managed all in ACR. For example, let's say you have new code that you want to
be pushed into a Docker image, you can push that code into a Docker image that
exists in ACR.

AZ204 Develop Azure compute solutions 2530% 2


There is one primary way to push an image to ACR. The primary way is using the
AZ CLI with the az acr command.
Before pushing an image to ACR, has an ACR been created? If not, you can create
one by using:

az acr create -n ACR_name -g your_resource_group --sku Standard

OR from the Azure portal in the ACR Blade

Once an ACR has been created, you can do the following:

az login - To ensure you are logged into Azure with the AZ CLI

az acr login - To log into the Azure Container Registry

docker tag - To tag the Docker image with the ACR name

docker push - To push the Docker image to ACR

Run containers by using Azure Container Instance (ACI)


Azure Container instances are a way of deploying containers in Azure without
having to use AKS or deploying Docker containers on-prem. Think of it like
running Docker locally, except it's in the cloud. The key feature is that even
though containers won't be orchestrated, you can still host containers that are
aren't ephemeral because containers can be tied to a storage account.

The three primary ways to create an ACI is:

Through the web portal in the ACI blade

With Azure CLI using the az container create command and switch.

With Azure PowerShell using the New-AzContainerGroup cmdlet.

Create ARM templates


Azure Resource Manager ARM templates are a way to define your infrastructure
or network as code. Using ARM you can not only automate the way you do
deployments, but ensure others can work on the code with you.

The three primary ways to work with ARM template are:

AZ204 Develop Azure compute solutions 2530% 3


Microsoft has Azure QuickStart Templates that allow you to get a pre-
defined environment that you can modify at any time. There are
quickstart templates for anything from VMs to vNets to serverless and
anything in-between. (demo here and code found in GitHub)

In Visual Studio Community or paid), there is a project template called


Azure Resource Group and by using that project template, you can
select an Azure QuickStart template it right from Visual Studio instead of
cloning the ARM template from GitHub. (demo here and code found in
GitHub)

In VS Code there is an extension called Azure Resource Manager ARM


tools that allow you to easily work with ARM templates. in VS Code when
you open up ARM templates, you will see an ARM TEMPLATE OUTLINE
pane that allows you to work with the params, resources, and outputs.
When you, for example, click on a parameter name or a resource name in
the ARM TEMPLATE OUTLINE, you will be automatically taken to where
the code that parameter or resource exists. (demo here and code found in
GitHub)

Create Azure App Service Web Apps

Azure web apps are a serverless function in Azure that allow you to deploy
code for say, a web application, and have the web app run without needing to
create a server to host the code.

There are three primary ways to deploy a web app:

The Azure portal on the web apps blade

Ensure when you are creating a web app, you choose the proper app
service plan. The app service plan is the server, in so many words,
that the serverless web app resides on. The F1 class of app service
plans is free.

AZ CLI (code can be found here)

AZ204 Develop Azure compute solutions 2530% 4


az webapp create ← Command and switched used for webapp creation.

PowerShell using the Azure PowerShell module (code can be found here)

Enable diagnostics logging


Diagnostic logs is a built-in debugger that allows you to see any logs that
may pertain to an issue with an Azure app service. Not only does diagnostic
logging allow you to see logs after the fact, but you can also capture logs in
real time.

Azure allows for up to five different diagnostic settings to send different logs
and metrics. The six defaults that exist in every web app creation are:

AppServiceHTTPLogs

AppServiceConsoleLogs

AppServiceAppLogs

AppServiceFileAuditLogs

AppServiceAuditLogs

AllMetrics

To enable diagnostic logging for Windows web apps:

Log into the Azure web portal and go to the app services blade

Click on the web app that you want to turn on diagnostic logging for

Search for App Service Logs under Monitoring

Here you will see the log options

AZ204 Develop Azure compute solutions 2530% 5


To enable diagnostic logging for Linux web apps:

Log into the Azure web portal and go to the app services blade

Click on the web app that you want to turn on diagnostic logging for

Search for App Service Logs under Monitoring

Under Application Logging, you can turn on File System logs.

AZ204 Develop Azure compute solutions 2530% 6


Deploy code to a web app
Azure App Services are serverless web applications, which allow you to
deploy code and run it without the need of a server. With serverless, there's
no more needing to configure a server, RAM, hard disk space, etc.. You simply
deploy code.

There are two primary ways to deploy code for the scope of the AZ204

💡 There is a third and very valuable way, using CICD to deploy code
with Azure Pipelines Azure DevOps) or GitHub Actions CICD. The
reason why that option is not listed here is because it does not
come up in the exam objectives for the AZ204. I do recommend,
for your own knowledge, to check out Azure Pipelines. You can see
a getting started guide found here.

 The Web Portal

 Go to the Azure App Services blade

AZ204 Develop Azure compute solutions 2530% 7


 Click on the app service you wish to deploy code to.

 Under Deployment click on Deployment Center

4. Under Deployment Center there are several places to deploy code


from. Because my code is in GitHub, I will be using GitHub. The source
control location will differ.

5. Use the App Service build service build provider

AZ204 Develop Azure compute solutions 2530% 8


6. Choose what repository and branch your code is in

Click the finish button.

 Azure CLI

 az webapp up - Code can be found here.

Configure web app settings including SSL, API, and

AZ204 Develop Azure compute solutions 2530% 9


connection strings
App settings are specific configuration settings that the application needs to
run, for example, a connection string to a database or an SSL string.

There are two primary ways to configure webapp configurations:

 The web Portal:

 Go to the Azure App Services blade

 Click on the app service you wish to deploy code to

 Under Settings click on Configuration

You can now set up your configuration settings.

 Azure CLI

 az webapp config connection-string set - Code found here.

There is one primary way to configure SSL

 To Configure SSL

 Go to the Azure App Services blade

 Click on the app service you wish to deploy code to.

 Go to TLS/SSL Settings under Configuration

There you can upload or buy a .PKG SSL cert for the web app.

AZ204 Develop Azure compute solutions 2530% 10


Implement autoscaling rules, including scheduled
autoscaling, and scaling by operational
or system metrics
AutoScaling is a way for an application to scale up or scale down Azure
resources depending on the applications load.
For example, let's say you have an application running on an Azure virtual
machine and the current size is B1ms , but the application is taking far more
than 2GB of RAM, which is causing the virtual machine to freeze and become
unusable. With autoscaling, as soon as the server reaches a certain threshold,
Azure will autoscale that virtual machine up to a larger size.

Azure Monitor has an autoscaling portion that allows you to set schedules.
For example, let's say you know that an application you are managing gets
utilized far more Monday-Friday vs Saturday and Sunday. You can set up
Azure Monitor autoscaling to scale up VMs Monday-Friday then scale them
back down Saturday and Sunday.
Below is a list of current autoscaling solutions for Microsoft

Azure Virtual Machines autoscale via virtual machine scale sets which is


a set of identical virtual machines managed in one place.

Service Fabric allows you to build and operate scalable distributed


applications. Service Fabric also uses virtual machine scale sets.

Azure App Service has built-in autoscaling, so you don't need to worry


about the management overhead.

Azure Cloud Services has built-in autoscaling at the role.

There are three primary ways you can set up virtual machine scale sets:

 From the Azure web portal under the virtual machine scale sets blade

 PowerShell

 PowerShell has an AZ module that contains cmdlets to manage and


create virtual machine scale sets. You can find an example here.

AZ204 Develop Azure compute solutions 2530% 11


 Azure CLI

 AZ CLI provides the az vmss command to manage and create virtual


machine scale sets. You can find an example here.

Implement Azure Functions


Implement Input and Output Bindings for a Function
Bindings are a way of connecting another resource to the function. Bindings
can be connected as input bindings, output bindings, or both. Data from the
bindings is provided to the function as parameters. Bindings are essentially a
way for the Azure Function to connect to other resources.
For example, let's say you had some backend code for an eCommerce
website and you wanted to set up the ability for users to pay with PayPal.
You could have a binding to make a call to PayPal for the ability to use it in
the backend code that is being hosted via Azure Functions.

The primary way you will see this done is from C#. You can find a code
example here.

Implement Function Triggers by Using Data Operations,


Timers, and Webhooks
Triggers are what tells an Azure Function to run, meaning, the trigger triggers
the Azure Function to kick off and complete the task.
If you aren't familiar with what a webhook is, it's a way for a web page to be
altered with custom callbacks. A webhook is also a way for an application to
provide other applications real-time data.

To implement Timers in Azure Functions from the UI

 Go to the Azure Functions blade in the Azure Portal

 Choose your Azure Function

AZ204 Develop Azure compute solutions 2530% 12


3. You will be presented with a screen to create a new function. Click the
New function button.

4. Choose where you want to create the function from. In this case, you can
choose In-portal

AZ204 Develop Azure compute solutions 2530% 13


4. You will now see the option to choose the timer trigger

To using Timers in Azure Functions using C# and Visual Studio:

 Open Visual Studio and create a new Azure Functions project.

AZ204 Develop Azure compute solutions 2530% 14


Configure the new project

AZ204 Develop Azure compute solutions 2530% 15


In the options for how you want to create the new Azure functions
application, scroll down and choose Timer trigger

AZ204 Develop Azure compute solutions 2530% 16


The C# code for the timers can be found here.

To create a new webhooks in Azure Functions:

 Log into the Azure web portal and go to the Azure Functions blade

 Click on an Azure Function or if you don't have one, create a new one.

 Once in the function app, create a new function trigger

AZ204 Develop Azure compute solutions 2530% 17


4. Click on the In-portal option

5. You can now choose the Webhook + API option

Implement Azure Durable Functions

AZ204 Develop Azure compute solutions 2530% 18


Durable Azure Functions are stateful Azure Functions.

Stateful - Store data and requires backend storage. Kind of like a hard
drive

Stateless - Doesn't store data. Kind of like RAM

There are two primary ways to do this:

 The portal

 C# with Visual Studio

For the C# with Visual Studio solution, this is a great resource from Microsoft.

For creating Durable Azure Functions in the portal:

 Log into the Azure web portal and go to the Azure Functions blade

 Click on an Azure Function or if you don't have one, create a new one.

 Once in the function app, create a new function trigger

4. Click on the In-portal option

AZ204 Develop Azure compute solutions 2530% 19


5. Click on More templates...

6. Type Durable in the search field and you will see many options for durable
Azure Functions

AZ204 Develop Azure compute solutions 2530% 20

You might also like