Skip to content

soaand01/aksAGIC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ AKS with Application Gateway Ingress Controller (AGIC)

Azure Kubernetes Terraform

A comprehensive guide to setting up Azure Kubernetes Service (AKS) with Application Gateway Ingress Controller for scalable and secure web applications.


πŸ“‹ Table of Contents


πŸ” Overview

This project demonstrates how to integrate Azure Kubernetes Service (AKS) with Application Gateway Ingress Controller (AGIC) to provide:

  • βœ… Layer 7 load balancing with SSL termination
  • βœ… Web Application Firewall (WAF) protection
  • βœ… Auto-scaling capabilities
  • βœ… High availability and fault tolerance
  • βœ… Secure networking with VNet peering

πŸ—οΈ Architecture

Internet β†’ Application Gateway (WAF) β†’ AKS Cluster β†’ NGINX Pods
              ↓
         Public IP + SSL

Key Components:

  • Application Gateway: Entry point with WAF protection
  • AKS Cluster: Container orchestration platform
  • AGIC: Kubernetes ingress controller
  • VNet Peering: Secure communication between networks

πŸ“‹ Prerequisites

Before you begin, ensure you have:

  • Azure CLI installed and configured
  • kubectl installed
  • Azure subscription with appropriate permissions
  • Resource Group created
  • AKS cluster already provisioned

βš™οΈ Setup Instructions

1️⃣ Environment Variables

First, configure your environment variables:

# πŸ”§ Export your variables
export rgName=dev
export aksName=dev-aks
export pipName=dev-pip
export appgwVnetName=dev-appgw-vnet
export appgwSnetName=dev-appgw-snet-01
export location=westeurope
export appgwName=dev-appgw
export wafPolicyName=dev-waf-policy
export aksVnetName=dev-vnet

2️⃣ Infrastructure Setup

Create Public IP

# 🌐 Create public IP for Application Gateway
az network public-ip create \
  -n $pipName \
  -g $rgName \
  -l $location \
  --allocation-method Static \
  --sku Standard

Create Virtual Network

# πŸ—οΈ Create VNet for Application Gateway
az network vnet create \
  -n $appgwVnetName \
  -g $rgName \
  -l $location \
  --address-prefix 10.0.0.0/16 \
  --subnet-name $appgwSnetName \
  --subnet-prefix 10.0.0.0/24

Create WAF Policy

# πŸ›‘οΈ Create Web Application Firewall policy
az network application-gateway waf-policy create \
  --name $wafPolicyName \
  --resource-group $rgName

Create Application Gateway

# πŸšͺ Create Application Gateway with WAF v2
az network application-gateway create \
  -n $appgwName \
  -l $location \
  -g $rgName \
  --sku WAF_v2 \
  --public-ip-address $pipName \
  --vnet-name $appgwVnetName \
  --subnet $appgwSnetName \
  --priority 100 \
  --waf-policy $wafPolicyName

3️⃣ Enable AGIC

# πŸ”— Enable Application Gateway Ingress Controller on AKS
appgwId=$(az network application-gateway show -n $appgwName -g $rgName -o tsv --query "id")
az aks enable-addons \
  -n $aksName \
  -g $rgName \
  -a ingress-appgw \
  --appgw-id $appgwId

4️⃣ Network Peering

# πŸ”„ Create VNet peerings for secure communication
aksVnetId=$(az network vnet show -n $aksVnetName -g $rgName -o tsv --query "id")
az network vnet peering create \
  -n AppGWtoAKSVnetPeering \
  -g $rgName \
  --vnet-name $appgwVnetName \
  --remote-vnet $aksVnetId \
  --allow-vnet-access

appGWVnetId=$(az network vnet show -n $appgwVnetName -g $rgName -o tsv --query "id")
az network vnet peering create \
  -n AKStoAppGWVnetPeering \
  -g $rgName \
  --vnet-name $aksVnetName \
  --remote-vnet $appGWVnetId \
  --allow-vnet-access

πŸš€ Deployment

Deploy the sample NGINX application:

# πŸ“¦ Clone the repository and deploy
git clone https://github.com/soaand01/aksAGIC.git
cd aksAGIC/deployment

# 🐳 Deploy NGINX application
kubectl create namespace nginx
kubectl apply -f nginx-deployment.yaml -n nginx
kubectl apply -f nginx-service.yaml -n nginx
kubectl apply -f nginx-ingress.yaml -n nginx

πŸ“ Project Structure

aksAGIC/
β”œβ”€β”€ πŸ“„ README.md
└── πŸ“ deployment/
    β”œβ”€β”€ 🐳 nginx-deployment.yaml    # NGINX deployment with 5 replicas
    β”œβ”€β”€ 🌐 nginx-service.yaml       # ClusterIP service on port 8080
    └── πŸšͺ nginx-ingress.yaml       # Ingress configuration for AGIC

πŸ§ͺ Testing

Get Ingress IP Address

# πŸ” Check your ingress IP
kubectl get ingress -n nginx

# πŸ“Š Monitor pod status
kubectl get pods -n nginx -o wide

# πŸ“ˆ Check service endpoints
kubectl get endpoints -n nginx

Verify Application Gateway

# 🌐 Get Application Gateway public IP
az network public-ip show \
  --resource-group $rgName \
  --name $pipName \
  --query ipAddress \
  --output tsv

πŸ“Š Monitoring

Monitor your deployment with these commands:

# πŸ“ˆ Watch pods in real-time
kubectl get pods -n nginx -w

# πŸ” View ingress controller logs
kubectl logs -n kube-system -l app=ingress-appgw

# πŸ“Š Check Application Gateway backend health
az network application-gateway show-backend-health \
  --name $appgwName \
  --resource-group $rgName

🧹 Cleanup

To clean up resources:

# πŸ—‘οΈ Delete Kubernetes resources
kubectl delete namespace nginx

# πŸ—‘οΈ Delete Azure resources
az network application-gateway delete --name $appgwName --resource-group $rgName
az network public-ip delete --name $pipName --resource-group $rgName
az network vnet delete --name $appgwVnetName --resource-group $rgName

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

Anderson Soares Lopes

GitHub LinkedIn


⭐ If you found this project helpful, please give it a star! ⭐

Made with ❀️ by Anderson Soares

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published