Skip to content

Introduction

Welcome to the world of containerized microservices and Kubernetes—where scalability, flexibility, and resilience define the future of modern application development.

This book is the second half of a story. In my companion book, Building Microservices with Containers, we build a small online store as a set of independent services and run it on your own machine with Docker Compose. In this book we take that same store to Azure and build everything it needs to run in production: the network, the Kubernetes cluster, the databases, the secrets, the routing, the monitoring and the pipelines—all provisioned with Terraform.

Why Kubernetes, Azure and Terraform?

Microservices let teams build, deploy, and scale services independently, but running many services introduces its own challenges: deployment, orchestration, scaling, and keeping everything healthy. Kubernetes, now the de facto standard for orchestrating containers, solves those problems. It restarts failed containers, scales services up and down, rolls out new versions without downtime, and gives services a stable way to find each other.

Microsoft Azure offers Kubernetes as a managed service, Azure Kubernetes Service (AKS), together with managed databases, secret storage, networking and monitoring that integrate with it. Terraform, developed by HashiCorp, lets you define all of that infrastructure as code. Together they give you:

  • Automated provisioning with version-controlled infrastructure
  • Consistency across environments (dev and prod)
  • Scalability for microservices, with governance and security built in
  • Fewer manual errors and a clear record of every change

What You'll Build

Throughout the book we build one platform and run one system on it: the online store from the companion book, using the same container images.

flowchart LR
  user([Browser]) -->|https store.example.com| gw
  user -->|https auth.example.com| gw
  subgraph AKS["AKS cluster in a private spoke network"]
    gw[Gateway API<br/>routing] --> sf[Storefront]
    gw --> adm[Admin site]
    gw -->|/api/products| prod[Product API]
    gw -->|/api/orders| ord[Order API]
    gw --> kc[Keycloak]
    ord --> prod
    ord -->|OrderPlaced| mq[(RabbitMQ)]
    mq --> nw[Notification worker]
  end
  prod -->|private endpoint| sql[(Azure SQL Database)]
  ord -->|private endpoint| pg[(PostgreSQL<br/>Flexible Server)]
  kc --> pg
  AKS -->|workload identity| kv[Key Vault]
  AKS -->|pull images| acr[Container Registry]
  AKS --> mon[Azure Monitor<br/>Grafana]

A customer opens https://store.example.com in the browser. The request reaches the cluster's Gateway, which routes it by path: the storefront page, the admin site, or one of the two APIs. When the customer places an order, the Order API checks prices with the Product API, saves the order in PostgreSQL and publishes an OrderPlaced event to RabbitMQ, where the notification worker picks it up. The databases are Azure-managed and reachable only through private endpoints; passwords and connection details come from Key Vault through each service's own identity; the images come from your private container registry; and every request leaves logs, metrics and traces in Azure Monitor.

From the Companion Book to This Book

If you've finished Building Microservices with Containers, here is how each part of the store changes when it moves to Azure:

On your machine (companion book) On Azure (this book)
Images built with docker build Images built in Azure Container Registry
compose.yaml runs the store A Helm chart deploys the store to AKS, later through GitOps
The nginx API gateway container Kubernetes Gateway API routes on AKS
SQL Server container for the Product API Azure SQL Database, with passwordless sign-in
PostgreSQL containers for orders and Keycloak Azure Database for PostgreSQL Flexible Server
Passwords in a .env file Azure Key Vault, read by each service's own workload identity
RabbitMQ container RabbitMQ on AKS, run by its Kubernetes operator
Keycloak container Keycloak on AKS, run by its Kubernetes operator
Logs on the console Container Insights, managed Prometheus, Grafana and Application Insights
Compose health checks Kubernetes probes, disruption budgets and spreading across zones
(not needed on one machine) Autoscaling of pods and nodes, proven with a load test

Who This Book Is For

This book is ideal for:

  • Cloud engineers and DevOps professionals who want practical experience building an AKS platform with Terraform
  • Platform engineers who need a working reference for identity, networking, ingress, scaling and observability on AKS
  • Solutions architects looking to design scalable cloud-native platforms and understand the trade-offs
  • Developers who built microservices and want to see what it takes to run them in production

What You Should Know First

  • Docker and the store: you've worked through the companion book, or at least can run its samples. The services themselves are not explained again here.
  • Kubernetes basics: pods, deployments and services. If they're new to you, the official Kubernetes Basics tutorial covers them in an afternoon.
  • Terraform basics: what a provider, a resource and state are. The Get Started with Terraform on Azure tutorial is a good primer; the book explains everything else as it goes.

What You Need

  • An Azure subscription you control. The free trial's limits are too small for an AKS cluster with managed databases; use a pay-as-you-go or Visual Studio subscription.
  • Permissions on that subscription: Contributor to create resources, plus Role Based Access Control Administrator to grant the identities the platform needs (or Owner on a personal sandbox subscription). The book never needs a tenant-wide administrator role in Microsoft Entra ID, because every identity it creates is a managed identity.
  • Tools: Azure CLI, Terraform, kubectl and kubelogin (az aks install-cli installs both), Helm, Git and Visual Studio Code. Docker is optional: the images are built in Azure Container Registry.
  • A domain name you can delegate, for the HTTPS chapters. Without one you can still follow along over HTTP using the gateway's IP address.

What It Costs

The labs build one small dev environment and add to it chapter by chapter. TODO: daily cost of the dev environment, priced in the Azure pricing calculator once the platform chapters are rewritten.

Two ways to keep the bill under control:

  • Keep it running between labs if you work through several chapters in a row; each lab builds on the previous one.
  • Destroy it with terraform destroy when you take a break of more than a day or two, and recreate it from code when you come back. Every lab ends with a Cleanup section that says what to keep and what to remove.

How This Book Is Organized

The book is organized in parts. The Table of Contents lists every chapter that's ready.

  • Part I: Foundations. Infrastructure as Code, the target architecture of the store on Azure, and the Terraform project every later chapter adds to.
  • Part II: Build the platform. Log Analytics, the hub-spoke network, the container registry, the AKS cluster and its node pools, Key Vault, and the managed databases.
  • Part III: Run the store. Workload identity and secrets, deploying the store from the companion book, stateful services, Gateway API routing, and DNS and TLS.
  • Part IV: Operate at scale. Observability, autoscaling and resilience, the security baseline, upgrades, backup and disaster recovery, troubleshooting, and cost and teardown.
  • Part V: Automate. Pipelines for Terraform and for images, and GitOps with Argo CD.
  • Optional: more platform services. Redis, Storage, Event Hubs, Front Door, and a private cluster with Bastion.
  • Appendices. A kubectl cheat sheet, a production-readiness checklist and a glossary.

Each lab follows the same structure, described in How the Labs Work.

Dev vs Prod

The labs deploy a dev environment that's sized to learn on and cheap to run. The same Terraform code describes a prod environment through a second variables file, prod.tfvars, which you'll read but not apply. The differences:

Area dev (what the labs build) prod (what prod.tfvars describes) Why
AKS tier Free Standard Standard adds the uptime SLA for the control plane
Node pools 2 small system nodes; 1-4 app nodes 3 larger system nodes; 3-10 app nodes Headroom and availability for real traffic
Availability zones Nodes spread across zones Pods required to spread across zones Survive the loss of a zone
PostgreSQL Burstable tier, no high availability General Purpose, zone-redundant high availability, geo-redundant backups Fail over without data loss
Azure SQL Database Serverless, pauses when idle Provisioned, zone-redundant Predictable performance
Cluster API access Public endpoint limited to your IP address Same, or a private cluster with Bastion A private API server removes the public endpoint entirely
Resource locks Off, so terraform destroy works On Protect production from accidental deletion
Security monitoring Optional Microsoft Defender for Containers Threat detection and vulnerability scanning

The labs use dev because it shows every concept at a fraction of the cost; nothing in the design changes between the two.

This book is more than a technical manual—it’s a guide to thinking like a cloud architect. By the end, you’ll not only know how to deploy cloud infrastructure with Terraform, but how to design it with purpose, security, and scale in mind.

Let’s get started.