Visit (Unfortunately My cloud credits ran out)
Deployment is Automated - simply run deploy.sh script
This project sets up an Azure Kubernetes Service (AKS) cluster using Terraform and deploys an nginx web server with 2 replicas, exposed via a LoadBalancer over HTTP. It uses Azure Blob Storage as a remote backend for Terraform state, with a storage account created automatically and randomized for uniqueness. A bash script automates deployment and ensures the external IP is assigned. All code is in this public GitHub repo.
-
Authenticated with Azure:
- Ran
az loginto log in via the browser. - Set subscription:
az account set --subscription "<subscription-id>".
- Ran
-
Wrote Terraform Config:
- Used AzureRM provider version
~> 3.0inprovider.tf(avoids subscription key requirement in 4.0+). - Created
provider.tf,main.tf, andvariables.tfto define:- A resource group (
aks-assignment-rg). - A storage account (prefix
aksstate+ random suffix) and container (tfstate) for Terraform state. - A 2-node AKS cluster (
my-aks-cluster) with kubenet networking. - Assigned a SystemAssigned identity to the cluster, granting Contributor role permissions.
- A resource group (
- Used AzureRM provider version
-
Deployed the Cluster:
- Initialized:
terraform init(first locally, then with remote backend). - Deployed storage resources first, then configured remote backend in Blob Storage via
deploy.sh. - Applied:
terraform apply -auto-approve(two phases in script). - Took ~5-10 minutes to provision.
- Outputs: Shows
cluster_name,resource_group_name,storage_account_name, and an external IP command.
- Initialized:
-
Connected to the Cluster:
- Fetched kubeconfig:
az aks get-credentials --resource-group aks-assignment-rg --name my-aks-cluster - Verified:
kubectl get nodes(saw 2 nodes).
- Fetched kubeconfig:
-
Wrote Kubernetes YAMLs:
k8s/deployment.yaml: Deploysnginx:latestwith 2 replicas on port 80.k8s/service.yaml: Exposes it with a LoadBalancer on port 80.
-
Automated Deployment:
- Created
deploy.shto:- Deploy resource group and storage account first (Terraform).
- Configure the remote backend with a unique storage account name.
- Deploy the AKS cluster.
- Fetch kubeconfig and apply YAMLs.
- Loop to wait for the external IP (up to 2 minutes).
- Created
-
Ran the Script:
- Made it executable:
chmod +x deploy.sh - Executed:
./deploy.shto handle everything in one go.
- Made it executable:
-
Verify Pods:
kubectl get pods- Look for 2
nginxpods withSTATUS: RunningandREADY: 1/1.
-
Get External IP:
kubectl get service nginx-service- Note the
EXTERNAL-IP(e.g.,4.156.88.136or currentlyhttp://51.8.25.138/).
-
Test the App:
- Command:
curl http://<external-ip> - Output: HTML with
<h1>Welcome to nginx!</h1>. - Browser: Open
http://<external-ip>to see the welcome page. - Tested with:
curl http://4.156.88.136(previous run).curl http://51.8.25.138/(currently running instance).
- The script also tests it automatically with
curl.
- Command:
-
External IP Delay:
- Hiccup: The LoadBalancer IP sometimes took longer than expected to assign.
- Fix: Added a loop in
deploy.shto check every 10 seconds for up to 2 minutes, ensuring it captures the IP when ready.
-
Terraform Version Choice:
- Hiccup: AzureRM 4.0+ requires a subscription key in the provider block, complicating setup.
- Fix: Used
~> 3.0inprovider.tfto rely onaz loginauthentication, making deployment simpler for this assignment.
-
HTTPS Attempt:
- Hiccup: Tried adding HTTPS with a self-signed TLS certificate, but it caused browser warnings and added complexity.
- Fix: Reverted to HTTP to keep the demo simple and avoid self-signed cert warnings for reviewers.
-
Terraform State Management:
- Hiccup: Local state file wasn’t ideal for consistency; initial backend setup failed due to timing and uniqueness issues.
- Fix: Added a remote backend with Azure Blob Storage, automated storage account creation with a randomized name (e.g.,
aksstatex7k9p2m), and split deployment indeploy.shto create storage first.
-
Learning Curve:
- Hiccup: New to AKS and Terraform syntax.
- Fix: Used the Terraform AKS Guide and trial-and-error to get it working.
provider.tf,main.tf,variables.tf: Terraform config for AKS and remote state backend (using AzureRM ~> 3.0).k8s/deployment.yaml,k8s/service.yaml: Kubernetes manifests fornginx.deploy.sh: Automation script with backend setup, error checking, and IP loop..gitignore: Excludes sensitive files (e.g.,terraform.tfstate).
- To avoid charges:
terraform destroy(removes all resources).
- Added color-coded output in
deploy.shfor better readability. - Included an automatic
curltest in the script to verifynginxresponds. - Used a remote Terraform backend in Azure Blob Storage for state management.
- Added screenshots to visually confirm the setup works.



