AZURE KUBERNETES SERVICES (AKS)
Step-by-Step Guide to Setting Up Azure Kubernetes Service (AKS) π
Azure Kubernetes Service (AKS) allows you to deploy, manage, and scale containerized applications using Kubernetes without handling complex infrastructure. Hereβs a clear step-by-step guide to setting it up.
π οΈ Step 1: Sign in to Azure Portal
- Go to Azure Portal.
- Sign in with your Microsoft Azure account.
π¦ Step 2: Create an AKS Cluster
- Click “Create a resource” (top left corner).
- Search for “Kubernetes Service” and select “Create”.
π§ Step 3: Configure Basics
β
Subscription: Select your Azure subscription.
β
Resource Group: Create a new one or use an existing one.
β
Kubernetes Cluster Name: Enter a unique name (e.g., myAKSCluster).
β
Region: Choose a data center closest to your users.
β
Kubernetes Version: Choose the latest stable version.
π» Step 4: Configure Node Pools
- Choose Node Size (Standard_B2s is good for testing, but you can scale later).
- Set Node Count (start with 1 or 2 for testing).
- Enable Auto-scaling (optional, useful for scaling workloads).
π Step 5: Authentication & Networking
- Authentication:
- Choose System-assigned Managed Identity for security.
- Enable RBAC (Role-Based Access Control) for access control.
- Networking:
- Select Azure CNI (Advanced) for better networking control.
- Keep HTTP Application Routing disabled (unless needed).
β Step 6: Review & Create
- Click “Review + Create”.
- Verify all configurations.
- Click “Create” (Deployment may take 5-10 minutes).
π Step 7: Connect to Your AKS Cluster
Once deployed, you need to connect using Azure CLI.
- Install Azure CLI (if not installed)
az login - Get AKS Credentials
az aks get-credentials –resource-group MyResourceGroup –name myAKSCluster - Verify Cluster Connection
kubectl get nodes - If it returns a list of nodes, your cluster is working! π
π¦ Step 8: Deploy an Application to AKS
Letβs deploy a simple NGINX web server to AKS.
1. Create a deployment.yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
– name: nginx
image: nginx:latest
ports:
– containerPort: 80
2. Deploy it using:
kubectl apply -f deployment.yaml
3. Verify deployment:
kubectl get pods
4. You should see running pods! π
π Step 9: Expose Your App to the Internet
1. Create a service to expose the app:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
– protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
2. Apply the service:
kubectl apply -f service.yaml
3. Get the external IP:
kubectl get service nginx-service
4. Open the EXTERNAL-IP in a browser to see the running app! π
π οΈ Step 10: Scale & Manage the Cluster
- Scale the deployment:
kubectl scale deployment nginx-deployment –replicas=5 - Monitor logs:
kubectl logs -f <pod-name> - Delete the deployment (if needed):
kubectl delete deployment nginx-deployment
ποΈ Step 11: Delete the AKS Cluster (If Not Needed)
To avoid costs, delete the cluster:
az aks delete –resource-group MyResourceGroup –name myAKSCluster –yes –no-wait