AZ-104: Deploy and manage Azure compute resources

Note: สำหรับ Blog นี้ ผมย้ายมาจาก Notion ที่เขียนไว้ตอนเดือน 9-10 ปีที่แล้วนะครับ บาง Service อย่าง Azure AD มีเปลี่ยนชื่อเป็น Microsoft Entra ID เป็นต้นครับ

Configure virtual machines

งานอะไรควรใช้ IaaS (virtual machines)

  • test and development
  • website hosting
  • storage, backup, and recovery มาจัดการเพิ่มตาม Shared Response ของ IAAS
  • high-performance computing
  • big data analysis

Plan virtual machines

  • มันแก้ที่หลังไม่ได้
    - Start with the network - จะให้อยู่ใน vnet ไหนต้องคิดก่อนให้จบ
    - Choose a name for the virtual machine กำหนด naming convention ให้เรียบร้อย จะได้จัดการได้
  • รู้ Workload ก่อนจะทำงานแบบไหน
    - location/size of the virtual machine.
    Note workload: General purpose / Compute optimized / Memory optimized / Storage optimized / GPU / HPC
  • Review the pricing model and estimate your costs.
    - VM: Compute expenses(per-minute) / Consumption-based (per-secobd) / Reserved Virtual Machine Instances (สัญญาใช้ระยะยาว)
    - Storage Cost: Azure Disk (Standard / Premium)
  • Select an operating system for the virtual machine.0
    - Azure Marketplace Windows (ถ้ามี License ทำ Hybrid Benefit ลด costs) / Linux
    - ทำ 64 bits image ขึ้นมา deploy
  • ถ้าจะแก้ เช่น Resizing virtual machines ทำได้ แต่มีเงื่อนไข + downtime

Determine virtual machine storage

  • Disk Type
    - Operating system disk
    - Temporary disk (Win D: / Linux: /dev/sdb) เป็น temp อย่าเอา Data ลงหายนะ
    - Data disks
  • Recommend: managed disks / Premium Storage (SSD) / multiple Storage disks (เพิ่มหัวอ่าน Read/Write)

Lab: Configure virtual machines: Interactive lab simulation
Knowledge Check: Configure virtual machines

Configure virtual machine availability

การทำ maintenance และจัดการ downtime มาจาก 3 ส่วนได้แก่

  • Unplanned hardware maintenance
  • Unexpected downtime
  • Planned maintenance จัดการโดย Microsoft โดยจะดูตาม Shared Responsibility Model

Create availability sets - Availability Set เป็นตัวที่ช่วยให้ VM มี High Availability โดยมี

  • คำที่ต้องรู้ 2 คำ
    - Update Domain: ช่วยป้องกันปัญหา Planned Downtime เช่น การ Update Patch/ upgrade/ rollout และต้องมีการ Reboot โดยปกติ Azure เตรียมไว้ให้ 5 แต่เลือก 20 Update Domain
    - Fault Domain ช่วยป้องกันปัญหา Unplanned Downtime เช่น Hardware ใน Rack นั้นพัง ดังนั้นเพิ่ม Fault Domain หลายอัน จะช่วยลดปัญหาได้ ทางแก้กระจาย VM คนละ Update Domain / Fault Domain
  • สิ่งทีต้องสนใจ availability sets: redundancy / separation of application tiers (แยก APP /DB) / load balancing / use managed disks

availability zones - Physical ที่แยกออกจากกัน โดย 1 Region มี 3 Zone

AZ เอามาลด Single Point of Failure โดยแบ่ง 2 categories

  • Zonal services: pin each resource to a specific zone
    Ex Azure VM / Azure managed disks / Standard IP addresses
  • Zone-redundant services: replicates automatically across all zones.
    Ex. Azure Storage / Azure SQL Database

vertical and horizontal scaling

  • vertical ขยาย HW: scale up/scale down //Required Restart
  • horizontal ขยายเครื่อง: scale out/scale in
  • Consider: limitations / flexibility / reprovisioning (removing an existing VM and replacing it with a new VM ต้องเตรียมการ Availability + Data)

Implement Azure Virtual Machine Scale Sets

  • ที่ต้องสนใจ
    - automatic adjusted capacity (ตาม thresholds ที่ระบบคิดว่า acceptable performance for a positive customer experience)
    - scale out / scale in
    - scheduled events - ถ้ารู้ว่ามีงานประจำ เวลาแน่นอน เช่น งาน COB/EOD เพิ่ม Instance แล้ว
    - overhead ตอนสร้าง Instance
  • Create Virtual Machine Scale Sets
  • Implement autoscale
  • Configure autoscale

Lab: Configure virtual machine availability: Interactive lab simulation
Knowledge Check: Configure virtual machine availability: Knowledge check

Configure virtual machine extensions

extension : post-deployment configuration and automation tasks for Azure VM แต่งานจริงๆใช้ได้หมด deployment/provisioning/post-deployment ****แต่งานง่ายๆไม่ซับซ้อน ทำได้จาก Azure Portal / CLI / PowerShell / ARM Template

Ref: Azure VM extensions and features for Windows - Azure Virtual Machines | Microsoft Learn

Custom Script Extensions

  • accessing your virtual machine's Extensions page แยกของ Windows / Linux
  • ประเด็นที่ต้องสนใจ time out 90 minutes / dependencies (Network / Storage) / failure event (Connection / Disk Space) / sensitive data (credential)

Implement Desired State Configuration

configuration IISInstall
{
   Node "localhost"
   {
      WindowsFeature IIS
      {
         Ensure = "Present"
         Name = "Web-Server"
      }
   }
}

Knowledge check: Configure virtual machine extensions

Note:
- VMSS มีพวก Extension / Custom Script Extension นะ กดเหมือนกัน
- จะใช้งานกดที่ VMSS > Instance > Upgrade (Apply ทุก Change เกิดขึ้นใน Template (Size / Extension …. )

Configure Azure App Service plans

อ่านอันนี้แล้วอ๋อเลย ตอนใช้จริงๆ ยอมรับว่าจำก่อนว่าต้องสร้าง Plan > Web

-App Service plans vs App Service

  • App Service plans - จอง Infra
    - Free or Shared tier: shared VM instance / can't scale outฃ
    - Basic, Standard, Premium, or Isolated tier: ลง App ได้หลายอัน ใน VM instance เดียวกัน / รองรับ deployment slots / สร้าง VM instance ตามจำนวนที่กำหนด
    Note: App Service plans ตอนสร้างกำหนด
    - Region
    - Number of VM instances
    - Size of VM instances
  • App Service - Deploy Web

-App Service plans คิดพวกนี้ก่อนใช้งาน

  • cost savings + multiple applications in one plan: ใช้ Resource ให้คุ้มค่า แต่ละ Plan มี Spec ต่างกัน Disk / Auto Scale เป็นต้น แต่อย่างให้มัน capacity เดวได้ Down หมด วางแผนให้ดี
  • application isolation: แยก plan ในกรณีที่ใช้ Resource เยอะ และไม่อยากใช้ Policy Scale ร่่วมกัน App อื่นๆ หรือต้องการใช้ Region ต่างกับ Plan

-Scale up and scale out Azure App Service

  • scaled up and down at any time by changing the pricing tier of the plan
  • manually adjusting plan tiers (control your overall costs ต้องดูว่าอะไรเพิ่ม แล้วขยับ Plan)
  • auto scale to support users and reduce costs และไม่ต้อง redeployment
  • scaling for other Azure services - Auto Scale ต้องปรับให้ล้อกัน เช่น APP / DB ไม่งั้นจะเกิดปัญหาคอขวดได้

- Configure Azure App Service auto scale

  • Minimum instance count (Normal State > Maximum instance count (Scale-out/hourly cost)
  • Scale
    - Manual
    - Auto Scale
    >> Metric-based: Rule + scale margin + Default instance count (ถ้า Metricไม่ work)
    >> Time-based rules (or, schedule-based)
    - Notifications

Knowledge Check: Configure Azure App Service plans

Configure Azure App Service

-Feature ของ App Service

  • รองรับ ASP.NET, Java, Ruby, Node.js, PHP, Python, Go
  • DevOps / HA / Auto Scale
  • Security and compliance
  • SaaS platforms and on-premises data
  • Application templates - WordPress, Joomla, and Drupal.
  • Visual Studio integration - API / mobile / Serverless - Support

-Create an app with App Service

  • Initial
    - Name: App Name มันจะไปต่อใน url <<App Name>>.azurewebsites.net //Custom DNS ได้
    - Publish: Code / Container
    - Runtime stack:
    - Operating system: Windows / Linux
    - App Service plan: Region
  • Post-creation settings: Always On (เปิดตลอด แม้ว่าไม่มี request) / ARR affinity (กรณีที่ Multi-Instance จะช่วย Client Route มา Instance เดียวกันเสมอ) / Connection strings
  • CI/CD
    - Automated deployment (continuous integration): Azure DevOps / GitHub / Bitbucket
    - Manual deployment: Git / CLI (webapp up) / Visual Studio / FTP(S)

-Create deployment slots

deployment slots ช่วยให้มี Environment ในการทดสอบ ก่อนขึ้นจริง ด้วย Environment ที่เหมือนกัน

  • validation ทดสอบ ก่อนขึ้นจริง และ restoring to last known good site กรณีที่มีปัญหา
  • reductions in downtime สามารถแบ่ง Traffic ได้
  • Auto swap

-Add deployment slots

  • Slot-specific app settings and connection strings
  • Continuous deployment settings
  • Azure App Service authentication settings
  • Swapped settings versus slot-specific settings

-Secure your App Service app

  • Allow Anonymous requests (no action)
  • Allow only authenticated requests / Log in with <provider>
  • Logging and tracing\
  • security module is configured by using app settings (Filter ก่อนเข้า App เรา)\
  • The security module handles several tasks for your app
    - Authenticate users with the specified provider
    - Validate, store, and refresh tokens
    - Manage the authenticated session
    - Inject identity information into request headers

Create custom domain names

-Backup and Restore

  • Standard or Premium tier + Azure storage account and container in the same subscription
    ** ระวัง firewall on back-up destination
  • Default full backups (แต่ทำ partial ได้) โดยที่เก็บได้
    - Configuration settings
    - File content
    - Any database connected to your app MSSQL + Azure XXX
  • backup จะมี 2 ไฟล์ Zip + XML (manifest)

-Use Azure Application Insights (.NET, Node.js and Java)

  • IT
    - Request rates, response times, and failure rates เอามาดูว่าหน้าไหนเรียกบ่อย จะได้เอามาจัดเป็น Priority ในปรับจูน Performance
    - Dependency rates, response times, and failure rates ดู 3rd Party API/ Lib /font
    - Exceptions
    - Performance counters
    - Host diagnostics
    - Diagnostic trace logs - trace events with requests and diagnose issues
    - Custom events and metrics
  • Marketing / SEO
    - Page views and load performance (อันนี้กึ่งๆ IT)
    - User and session counts

Lab: Configure Azure App Service

อื่นๆ

  • อันนี้ App Service มี Local Git เหมือนกันนะ Clone / Set Remote / Push
  • DDOS in PowerShell Testing Scaling Out

Knowledge check: Configure Azure App Service

Configure Azure Container Instances

Compare containers to virtual machines:

  • flexibility and speed >>> Deployment ไว
  • testing ขึ้นไว และทดสอบก่อนขึ้น ACI โดยใช้ docker ลองที่ local ได้
  • workload density(improve your resource utilization)
CompareContainersVirtual machines
IsolationA container typically provides lightweight isolation from the host and other containers, but a container doesn't provide as strong a security boundary as a virtual machine.A virtual machine provides complete isolation from the host operating system and other virtual machines. This separation is useful when a strong security boundary is critical, such as hosting apps from competing companies on the same server or cluster.
Operating systemContainers run the user modeVirtual machines run a complete operating system (CPU, memory, and storage).
Deployment- Docker-individual containers
- Azure Kubernetes Service-multiple containers
- individual VM: Windows Admin Center or Hyper-V Manager
- multiple VM: PowerShell / System Center Virtual Machine Manager.
Persistent storageContainers use Azure Disks for local storage for a single node, or Azure Files (SMB shares) for storage shared by multiple nodes or servers.Virtual machines use a virtual hard disk (VHD) for local storage for a single machine, or an SMB file share for storage shared by multiple servers.
Fault toleranceIf a cluster node fails, any containers running on the node are rapidly recreated by the orchestrator on another cluster node.Virtual machines can fail over to another server in a cluster, where the virtual machine's operating system restarts on the new server.

-Azure Container Instances

  • Public IP connectivity and DNS names + FQDN - Custom sizes.
  • Persistent storage. direct mounting Azure Files file shares.
  • Linux and Windows containers
  • Co-scheduled groups - scheduling of multi-container groups that share host machine
  • Virtual network deployment

ACI: container groups = pod ใน K8S) - Pattern นิยมเอา Container Front / Back ขึ้นไปด้วยกัน

  • allocates resources ตาม Container Required เช่นมี 2 Image อันละ 1 CPU ตัว Container Group ได้ 2 CPU
  • deploy ARM template (ACI + Other เช่น Azure Files / YAML file (Only ACI)
  • External client access - one or more ports on the IP address / DNS+FDQN
  • Port mapping - ไม่รองรับ Container ออก Port ไหน container groups exposed port นั้นเลย
  • ตอนเอา Container ยัดลงกลุ่มเดียวกัน app updates / log / เปิด app monitoring

Note: ACI Multi-Container Group: Shared Resource / Init Container เอาไว้เตรียมพร้อม เช่น Run Script etc. / Linux Only

Lab: Configure Azure Container Instances
Knowledge Check: Configure Azure Container Instances

ACI มีแอบจัดการยาก ถ้าจะแก้ เช่น Scale เพิ่ม Resource ต้องไป
Delete ACI > แก้ ARM Template > Re-deploy

Configure Azure Kubernetes Service

  • Explore Azure Kubernetes Service terminology (Base-On K8S ถ้าเข้าใจแล้วข้ามไปเลย)
  • Pools: A pool is a group of nodes that have an identical configuration.
  • Nodes: A node is an individual VM that runs containerized applications.
  • Pods: A pod is a single instance of an application. A pod can contain multiple containers.
  • Container
  • Deployment: A deployment has one or more identical pods managed by K8S.
  • Manifest: YAML describes a deployment.
  • NOTE
    - The kubelet is the Kubernetes agent that processes the orchestration requests from the Azure-managed node, and scheduling of running the requested containers.
    - The kube-proxy component handles virtual networking on each node. The proxy routes network traffic and manages IP addressing for services and pods.

- Configure Azure Kubernetes Service networking

  • Kubernetes service types
    • Cluster IP: internal IP address in AKS
    • NodePort: port mapping >> Allow direct access to the application with the node IP address and port
    • LoadBalancer: configure an external IP address, and connect the requested pods //มันทำ internal and external LoadBalancer
    • ExternalName:Create a specific DNS entry.
  • Kubernetes pods
    • Node 1 > n pods > Container (pod 1: Container 1)
    • specify maximum resource limits
  • Ref: A quick introduction to AKS | PPT (slideshare.net)

- Configure Azure Kubernetes Service storage

across pods

  1. storage volumes - store, retrieve, and persist data across pods and through the application lifecycle มี 2 แบบ
    - Kubernetes DataDisk resource (Azure Disks)
    - Azure Files (SMB 3.0)

for pod

  1. storage classes - บอก Storage Type ต่างๆ ที่จะให้ Pod ใช้
  2. persistent volumes - pod lifecycle (Manage by Kubernetes API)
    - ใช้ Azure Disks / Azure Files ดูจาก concurrent access / performance tier
  3. persistent volume claims - pod ใช้งานตรง bind จาก persistent volumes

Ref:

- Configure Azure Kubernetes Service scaling - Scale มี 3 แบบ

  1. Manually scale pods or nodes
  2. Automatically scale pods โดยใช้ตัว horizontal pod autoscaler (HPA) ดู Metrics ทุก 30 วินาที ต้องพิจารณา
    - number of pods (replicas) : min / max
    - scaling metrics : เลือกว่าจะดูจากอะไร CPU / Mem ….
    - cooldown for scaling events : อาจจะเจอปัญหา race events แบบว่ากำลังจะจัดการ replicas เพิ่มแล้ว metrics เปลี่ยน จัดการโดยปรับ cooldown / delay values
    - tuning cooldown values
  3. Automatically scale clusters ต้องพิจารณา
    - combining with HPA : ใช้ร่วมกับ Automatically scale pods (HPA)
    - scale-out events : ถ้า Resource ไม่พอตอนสร้าง Pod มันจะเสียเวลาสร้าง Node ใหม่ นาน
    - burst scaling to Azure Container Instances :
    - scale-in events : threshold + not being needed for 10 minutes is scheduled for deletion by default
    - avoiding single pods : มันจะสร้าง node ใหม่ช้ากว่า

Configure AKS burst scaling to Azure Container Instances

Lab: Configure Azure Kubernetes Service
Knowledge Check: Configure Azure Kubernetes Service

Manage virtual machines with the Azure CLI (Lab ล้วนๆ)

Create a Windows virtual machine in Azure (ข้าม Lab ได้)

Host a web application with Azure App Service (Lab ล้วนๆ)

Protect your virtual machine settings with Azure Automation State Configuration (Lab ตอนท้าย)

What is Azure Automation State Configuration?

  • PowerShell DSC
    - A declarative management platform to configure, deploy, and control systems.
    - idempotent - Script execute ยังไงต้องเหมือนเดิม และต้อง handle error ด้วยนะ
  • Azure Automation
    - A service used to write, manage, and compile PowerShell Desired State Configuration (DSC) configurations, import DSC resources, and assign configurations to target nodes.
    - virtual machines in same consistent state
  • Local Configuration Manager (LCM)
    - responsible for updating the state of a node
    - Step: Gets the current state > Test Compares State .mof > Set Updates the node
  • LCM modes
    - Push mode: Easy Mode An administrator manually sends, or pushes, the configurations
    - Pull mode: For Complex Environments
    (0) Set Pull Server State
    (1) Client Check State
    (2) Pull Server ส่ง configuration

Exercise - Set up a DSC and configure a desired state
knowledge check

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.