Project 3: Microservices on AKS with Azure Container Registry, Bicep and GitHub Actions CI/CD

Microsoft Azure Architect Technologies AZ 300 100 min min read Updated: Nov 17, 2026 Advanced
Project 3: Microservices on AKS with Azure Container Registry, Bicep and GitHub Actions CI/CD
Advanced Topic 3 of 3

What We Build

text GitHub repo -> Actions: build image -> push to ACR -> deploy to AKS | AKS (3 nodes, zones) : web (frontend) -> orders-api -> Azure SQL / Cosmos DB (private) Ingress controller + public IP, Container insights to Log Analytics, ACR attached to AKS (AcrPull)

Step 1: Infrastructure with Bicep

bicep param location string = resourceGroup().location param suffix string = uniqueString(resourceGroup().id) resource acr 'Microsoft.ContainerRegistry/registries@2023-07-01' = { name: 'acr${suffix}' location: location sku: { name: 'Standard' } properties: { adminUserEnabled: false } } resource law 'Microsoft.OperationalInsights/workspaces@2022-10-01' = { name: 'law-aks-${suffix}' location: location properties: { sku: { name: 'PerGB2018' }, retentionInDays: 30 } } resource aks 'Microsoft.ContainerService/managedClusters@2024-05-01' = { name: 'aks-shop' location: location identity: { type: 'SystemAssigned' } properties: { dnsPrefix: 'aksshop' agentPoolProfiles: [{ name: 'system', count: 3, vmSize: 'Standard_D2s_v5', mode: 'System', availabilityZones: ['1', '2', '3'], enableAutoScaling: true, minCount: 3, maxCount: 6 }] oidcIssuerProfile: { enabled: true } securityProfile: { workloadIdentity: { enabled: true } } addonProfiles: { omsagent: { enabled: true, config: { logAnalyticsWorkspaceResourceID: law.id } } } } } output acrName string = acr.name output acrLogin string = acr.properties.loginServer
bash az group create -n rg-aks -l centralindia az deployment group create -g rg-aks -f aks.bicep az aks update -g rg-aks -n aks-shop --attach-acr <acrName> # lets AKS pull images (AcrPull) az aks get-credentials -g rg-aks -n aks-shop kubectl get nodes

Step 2: App and Dockerfile

dockerfile FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . USER 10001 EXPOSE 8080 CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]
bash az acr build -r <acrName> -t orders-api:v1 ./orders-api # build in the cloud, no local Docker needed az acr repository list -n <acrName> -o table

Step 3: Kubernetes Manifests

yaml apiVersion: apps/v1 kind: Deployment metadata: { name: orders-api } spec: replicas: 3 selector: { matchLabels: { app: orders-api } } template: metadata: { labels: { app: orders-api } } spec: containers: - name: orders-api image: <acrName>.azurecr.io/orders-api:v1 ports: [{ containerPort: 8080 }] resources: { requests: { cpu: 100m, memory: 128Mi }, limits: { cpu: 500m, memory: 256Mi } } readinessProbe: { httpGet: { path: /health, port: 8080 }, initialDelaySeconds: 5 } livenessProbe: { httpGet: { path: /health, port: 8080 }, initialDelaySeconds: 15 } --- apiVersion: v1 kind: Service metadata: { name: orders-api } spec: selector: { app: orders-api } ports: [{ port: 80, targetPort: 8080 }] --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: { name: orders-api } spec: scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: orders-api } minReplicas: 3 maxReplicas: 10 metrics: [{ type: Resource, resource: { name: cpu, target: { type: Utilization, averageUtilization: 70 } } }]
bash kubectl apply -f k8s/ kubectl get pods,svc,hpa az aks approuting enable -g rg-aks -n aks-shop # managed NGINX ingress (check current add-on guidance) kubectl apply -f k8s/ingress.yaml

Step 4: Workload Identity for Secrets and Data

  • Create a user-assigned managed identity, add a federated credential linked to the Kubernetes service account
  • Give the identity a role such as Key Vault Secrets User or database access
  • Annotate the service account and pod. The app then uses DefaultAzureCredential with no secrets

Step 5: GitHub Actions Pipeline

yaml ame: build-and-deploy on: { push: { branches: [main] } } permissions: { id-token: write, contents: read } env: ACR: myacr IMAGE: orders-api jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Build and push image run: az acr build -r $ACR -t $IMAGE:${{ github.sha }} ./orders-api - uses: azure/aks-set-context@v4 with: { resource-group: rg-aks, cluster-name: aks-shop } - name: Deploy run: | kubectl set image deployment/orders-api orders-api=$ACR.azurecr.io/$IMAGE:${{ github.sha }} kubectl rollout status deployment/orders-api --timeout=120s
  • Tag images with the commit SHA, not latest, so releases are traceable and can be rolled back with kubectl rollout undo
  • Add steps for tests, image scanning (Defender for Containers) and deploy to staging before production

Step 6: Observe and Test

  1. Open Container insights to see node and pod CPU and memory
  2. Kill a pod with kubectl delete pod and watch the Deployment recreate it
  3. Load test and watch the HPA add pods, and the cluster autoscaler add nodes
  4. Push a code change and watch the pipeline roll it out with zero downtime

Review

PillarNotes
Reliability3 zones, probes, replicas, rolling updates, backups for stateful data
SecurityWorkload identity, ACR with no admin user, private cluster option, Azure Policy for Kubernetes, image scanning
CostAutoscaling, Spot node pools for batch, right-size requests and limits, stop dev clusters
OperationsBicep, GitHub Actions, Container insights, upgrade channels
PerformanceHPA, cluster autoscaler, caching, node sizing

Clean Up

bash az group delete -n rg-aks --yes --no-wait

Conclusion

You deployed containers to AKS with infrastructure in Bicep, images in ACR, manifests with probes and autoscaling, workload identity and a GitHub Actions pipeline using federated login.

Quick Summary: Bicep; image; manifests; identity; pipeline; observe; review; cleanup.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators