This blog walks you through a complete DevOps workflow:
- Login to Azure
- Create Azure Container Registry (ACR)
- Build & push a Docker image
- Deploy it to Azure Kubernetes Service (AKS)
We’ll use a simple web server app instead of Python.
π§ Architecture Overview
Local (azure-client)
↓
Docker Build
↓
Azure Container Registry (ACR)
↓
Azure Kubernetes Service (AKS)
↓
Public Web App (via Service)
π Step 1: Login to Azure
Using Azure CLI
az login
If multiple subscriptions:
az account set --subscription "Your-Subscription-Name"
Using Azure Portal
- Go to https://portal.azure.com
- Search → Resource Groups
Select your resource group (example):
demo-rg-devops
π¦ Step 2: Create Azure Container Registry (ACR)
Option 1: Azure CLI
az acr create \
--resource-group demo-rg-devops \
--name devopsregistry01 \
--sku Basic \
--location eastus
Option 2: Azure Portal
- Search → Container Registries
- Click Create
- Fill:
- Registry Name:
devopsregistry01 - Region: East US
- Pricing Tier: Basic
- Registry Name:
- Click Review + Create
π Step 3: Login to ACR
az acr login --name devopsregistry01
π Step 4: Create Simple Web App (Docker)
Move to your working directory:
cd /root/webapp
π Create index.html
<h1>Welcome to DevOps Demo App π</h1>
<p>Deployed using ACR & AKS</p>
π Create Dockerfile
# Simple Nginx Web Server
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
π³ Step 5: Build Docker Image
docker build -t devopsregistry01:latest .
π·️ Step 6: Tag Image for ACR
docker tag devopsregistry01:latest devopsregistry01.azurecr.io/devops-webapp:latest
π€ Step 7: Push Image to ACR
docker push devopsregistry01.azurecr.io/devops-webapp:latest
☸️ Step 8: Create AKS Cluster
az aks create \
--resource-group demo-rg-devops \
--name devops-aks-cluster \
--node-count 1 \
--enable-addons monitoring \
--generate-ssh-keys \
--attach-acr devopsregistry01
π Step 9: Connect to AKS
az aks get-credentials \
--resource-group demo-rg-devops \
--name devops-aks-cluster
Verify:
kubectl get nodes
π Step 10: Deploy Application to Kubernetes
π Create Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
spec:
replicas: 2
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: devopsregistry01.azurecr.io/devops-webapp:latest
ports:
- containerPort: 80
Apply:
kubectl apply -f deployment.yaml
π Create Service
apiVersion: v1
kind: Service
metadata:
name: webapp-service
spec:
type: LoadBalancer
selector:
app: webapp
ports:
- port: 80
targetPort: 80
Apply:
kubectl apply -f service.yaml
π Step 11: Access the Application
Get external IP:
kubectl get svc webapp-service
Example output:
EXTERNAL-IP: 20.xx.xx.xx
Open in browser:
http://<EXTERNAL-IP>
π You should see:
Welcome to DevOps Demo App π
Deployed using ACR & AKS
π Final Summary
| Component | Name |
|---|---|
| Resource Group | demo-rg-devops |
| ACR | devopsregistry01 |
| Image | devops-webapp:latest |
| AKS Cluster | devops-aks-cluster |
| Deployment | webapp-deployment |
| Service | webapp-service |
⚠️ Common Issues & Fixes
❌ Image Pull Error
kubectl describe pod <pod-name>
✔ Fix: Ensure ACR is attached to AKS
❌ External IP Pending
✔ Wait 2–5 minutes (Azure LoadBalancer provisioning)
❌ Push Failed
✔ Ensure:
az acr login --name devopsregistry01
π‘ Pro Tips
- Use
az acr buildto skip local Docker - Enable autoscaling in AKS for production
- Use Helm charts for better deployments
- Integrate CI/CD (Azure DevOps / GitHub Actions)
π― Conclusion
You’ve successfully:
- Built a Docker image
- Stored it in ACR
- Deployed it to AKS
- Exposed it to the internet
This is the core DevOps pipeline used in real-world production environments.
No comments:
Post a Comment