AKS

Managed Kubernetes

Azure Container Platform Guide

1. Introduction

  • Overview of Azure Container Platform
  • Key Features and Benefits
  • Common Use Cases

2. Getting Started with Azure Containers

  • Prerequisites and Setup
  • Overview of Azure Container Registry (ACR)
  • Overview of Azure Kubernetes Service (AKS)
  • Choosing the Right Azure Container Solution

3. Azure Container Registry (ACR)

  • Creating and Configuring ACR
  • Managing Container Images
  • Integrating ACR with AKS
  • Security Best Practices for ACR

4. Azure Kubernetes Service (AKS)

  • Introduction to Kubernetes on Azure
  • Setting Up AKS Clusters
  • Configuring Networking for AKS
  • Scaling and Autoscaling AKS
  • Monitoring and Logging in AKS

5. Deploying and Managing Containers on Azure

  • Deployment Options (CI/CD with Azure DevOps, Helm, etc.)
  • Managing Applications and Workloads
  • Updating and Rolling Back Deployments
  • Managing Secrets and ConfigMaps

6. Security in Azure Container Platform

  • Identity and Access Management (IAM) in AKS
  • Network Security (NSG, Firewalls, and Policies)
  • Using Azure Policy for Compliance
  • Security Best Practices for AKS and ACR

7. Monitoring and Logging

  • Monitoring Cluster Health with Azure Monitor
  • Setting Up Alerts and Notifications
  • Logging and Analytics with Azure Log Analytics
  • Integrating with Third-Party Monitoring Tools

8. Scaling and Performance Optimization

  • Horizontal and Vertical Scaling in AKS
  • Optimizing Resource Usage
  • Using Azure Autoscale Features
  • Best Practices for Performance Tuning

9. Disaster Recovery and High Availability

  • Backup and Restore Strategies
  • High Availability (HA) in AKS
  • Configuring Azure Site Recovery
  • Best Practices for Business Continuity

10. Advanced Topics

  • Using AKS with Virtual Nodes and ACI
  • Integrating Azure Active Directory (AAD) with AKS
  • Using Azure Arc for Multi-Cloud AKS Management
  • Hybrid Cloud Scenarios with Azure Stack and AKS

11. Troubleshooting and FAQs

  • Common Issues and Solutions
  • Diagnosing Networking Problems
  • Troubleshooting Deployment Failures
  • Frequently Asked Questions

12. Additional Resources

  • Azure Documentation and Learning Resources
  • Community and Support
  • Further Reading and Blogs
  • Tools and Extensions for Azure Containers

Azure Kubernetes Service (AKS) Tutorial

Azure Kubernetes Service (AKS) is a managed Kubernetes service that simplifies deploying, managing, and scaling containerized applications in Azure. This guide covers creating an AKS cluster, deploying an application, and managing resources.

Table of Contents

  1. Introduction to AKS
  2. Prerequisites
  3. Creating an AKS Cluster
  4. Connecting to the AKS Cluster
  5. Deploying an Application to AKS
  6. Scaling and Updating the Application
  7. Monitoring and Logging

Introduction to AKS

AKS is a managed Kubernetes service that handles the Kubernetes control plane, allowing you to focus on deploying and managing applications without worrying about infrastructure.

Benefits of AKS

  • Managed Control Plane: Azure manages Kubernetes master node operations.
  • Scaling: Automatically scales nodes and pods based on demand.
  • Integrated Security: Integrates with Azure Active Directory for secure access.
  • Monitoring: Built-in Azure Monitor integration for tracking performance.

Prerequisites

  • Azure CLI: Install the Azure CLI if you haven’t already. Download it here.
  • Azure Subscription: Ensure you have an active Azure subscription.

Login to Azure

Log in to your Azure account using the Azure CLI:

az login

Creating an AKS Cluster

  1. Set Environment Variables (optional):
   RESOURCE_GROUP=myResourceGroup
   CLUSTER_NAME=myAKSCluster
   LOCATION=eastus
  1. Create a Resource Group:
az group create --name $RESOURCE_GROUP --location $LOCATION
  1. Create the AKS Cluster:
  az aks create --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --node-count 3 --enable-addons monitoring --generate-ssh-keys

This command creates a 3-node AKS cluster with monitoring enabled.

Connecting to the AKS Cluster

  1. Install kubectl (if not already installed):
az aks install-cli
  1. Connect to the Cluster:
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME
  1. Verify Connection:
kubectl get nodes

Deploying an Application to AKS

  1. Create a Deployment:
kubectl create deployment my-app --image=nginx
  1. Expose the Deployment:
kubectl expose deployment my-app --port=80 --type=LoadBalancer
  1. Check the Service IP:
kubectl get service my-app

Scaling and Updating the Application

  1. Scale the Deployment:
kubectl scale deployment my-app --replicas=5
  1. Update the Deployment (e.g., change the image):
kubectl set image deployment/my-app nginx=nginx:1.19.0
  1. Check the Status of the Update:
kubectl rollout status deployment/my-app

Monitoring and Logging

Enabling AKS Monitoring

When creating the AKS cluster with the --enable-addons monitoring flag, AKS integrates with Azure Monitor.

  1. View Cluster Metrics: Go to the Azure Portal, navigate to your AKS cluster, and select Insights under Monitoring to view performance metrics and set alerts.

  2. Access Logs: Logs for containers and nodes are available through Azure Monitor for troubleshooting and resource management.

Sample Azure Devops Yaml file

trigger:
- master  # Adjust according to your branch name

variables:
  imageName: nippy/myimage  # The base name for the Docker image
  imageTag: $(Build.BuildId)  # Automatically uses the build ID as the image tag

jobs:
- job: BuildAndDeploy
  pool:
    vmImage: 'ubuntu-latest'
  
  steps:
  - task: Docker@2
    inputs:
      containerRegistry: 'dockerhub'  # Reference to your Docker Hub service connection
      repository: '$(imageName)'  # Image name to build and push
      command: 'buildAndPush'  # Command to build and push the Docker image
      Dockerfile: '**/Dockerfile'  # Path to your Dockerfile
      tags: '$(imageTag)'  # Tag for the Docker image, using the build ID

  - script: |
      ls -l  # List files to verify the environment
      echo "Building Kubernetes deployment manifest..."
      sed "s|{{imageTag}}|$(imageTag)|g" deployment.yaml > deployment_replaced.yaml  # Replace placeholder with actual image tag
      cat deployment_replaced.yaml      
    displayName: 'Replace image tag in deployment.yaml'

  - task: Kubernetes@1
    inputs:
      connectionType: 'Azure Resource Manager'  # Using Azure Resource Manager for connection
      azureSubscriptionEndpoint: 'Free Trial(1)(98391885-1dc7-4963-93d0-7590a267b3f7)'  # Your Azure subscription
      azureResourceGroup: 'azure-devops'  # Resource group containing the AKS cluster
      kubernetesCluster: 'dev09'  # Name of the AKS cluster
      namespace: 'default'  # Kubernetes namespace to deploy into
      command: 'apply'  # Command to apply the configuration
      useConfigurationFile: true  # Indicate that a configuration file will be used
      configuration: 'deployment_replaced.yaml'  # The updated deployment file to apply
      secretType: 'dockerRegistry'  # Type of secret for authentication
      containerRegistryType: 'Azure Container Registry'  # Type of container registry being used