
Hola chicos
Paso a paso para la configuración:
1. Preparar la red base
La VNet puede separarse así:
vnet-enterprise-prod 10.10.0.0/16│├─ snet-aks 10.10.0.0/20├─ snet-apim 10.10.17.0/24├─ snet-appgw 10.10.20.0/24├─ snet-private-endpoints 10.10.19.0/24└─ AzureFirewallSubnet 10.10.18.0/26
La separación por subredes permite aislar responsabilidades y aplicar NSG, UDR y políticas de red específicas. Application Gateway v2 debe vivir en su propia subnet. Microsoft Learn
Ejemplo Terraform simplificado:
resource "azurerm_virtual_network" "main" { name = "vnet-enterprise-prod" location = azurerm_resource_group.main.location resource_group_name = azurerm_resource_group.main.name address_space = ["10.10.0.0/16"]}
2. Crear Azure Firewall para egress
En este diseño el Firewall no forma parte del camino de entrada.
El flujo es:
Pods / AKS Nodes ↓UDR 0.0.0.0/0 ↓Azure Firewall ↓Internet / External APIs
AKS admite userDefinedRouting como tipo de salida, de modo que puedes obligar al tráfico outbound a pasar por Azure Firewall. Microsoft Learn
Ejemplo conceptual de ruta:
resource "azurerm_route" "aks_default" { name = "default-to-firewall" address_prefix = "0.0.0.0/0" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.10.18.4"}
La Route Table debe asociarse a snet-aks.
3. Crear AKS privado con Azure CNI + Cilium
Yo desplegaría:
Private AKS+Azure CNI Overlay+Cilium eBPF+OIDC Issuer+Workload Identity+User Defined Routing
Ejemplo:
az aks create \ --resource-group rg-platform-prod \ --name aks-prod \ --enable-private-cluster \ --network-plugin azure \ --network-plugin-mode overlay \ --network-dataplane cilium \ --enable-oidc-issuer \ --enable-workload-identity \ --outbound-type userDefinedRouting \ --vnet-subnet-id $AKS_SUBNET_ID
Azure CNI Powered by Cilium es la dirección recomendada a largo plazo para networking en AKS y aporta eBPF, Network Policies y capacidades avanzadas de observabilidad. Microsoft Learn
4. Crear namespaces
apiVersion: v1kind: Namespacemetadata: name: apps---apiVersion: v1kind: Namespacemetadata: name: ingress
Aplicar:
kubectl apply -f namespace.yaml
5. Configurar Workload Identity
Primero obtenemos el OIDC issuer:
OIDC_ISSUER=$(az aks show \ -g rg-platform-prod \ -n aks-prod \ --query "oidcIssuerProfile.issuerUrl" \ -o tsv)
Después creamos una User Assigned Managed Identity:
az identity create \ --resource-group rg-platform-prod \ --name id-api-prod
Obtenemos su Client ID:
CLIENT_ID=$(az identity show \ -g rg-platform-prod \ -n id-api-prod \ --query clientId \ -o tsv)
Workload Identity permite que una Service Account de Kubernetes obtenga tokens de Microsoft Entra ID sin secretos permanentes. Microsoft Learn
6. Crear ServiceAccount
apiVersion: v1kind: ServiceAccountmetadata: name: api-sa namespace: apps annotations: azure.workload.identity/client-id: "<CLIENT-ID>"
7. Crear la Federated Identity Credential
az identity federated-credential create \ --name fic-api-prod \ --identity-name id-api-prod \ --resource-group rg-platform-prod \ --issuer "$OIDC_ISSUER" \ --subject system:serviceaccount:apps:api-sa \ --audiences api://AzureADTokenExchange
La relación lógica queda así:
ServiceAccount ↓OIDC Token ↓Microsoft Entra ID ↓Federated Identity Credential ↓Managed Identity ↓Access Token
8. Crear Key Vault
az keyvault create \ --name kv-api-prod \ --resource-group rg-platform-prod \ --location westeurope \ --enable-rbac-authorization true
Asignamos permiso:
az role assignment create \ --assignee "$CLIENT_ID" \ --role "Key Vault Secrets User" \ --scope "$KEYVAULT_ID"
9. Crear Private Endpoint de Key Vault
La idea es que el Pod no acceda a Key Vault por Internet:
Pod ↓Private DNS ↓Private Endpoint ↓Key Vault
Private DNS Zone:
privatelink.vaultcore.azure.net
Un Private Endpoint usa una IP privada de la VNet y mantiene el acceso al servicio PaaS dentro de Azure. Microsoft Learn
10. Crear el Deployment
apiVersion: apps/v1kind: Deploymentmetadata: name: api namespace: appsspec: replicas: 3 selector: matchLabels: app: api template: metadata: labels: app: api azure.workload.identity/use: "true" spec: serviceAccountName: api-sa containers: - name: api image: myregistry.azurecr.io/api:1.0 ports: - containerPort: 8080 env: - name: KEYVAULT_URL value: "https://kv-api-prod.vault.azure.net/"
11. Crear ClusterIP Service
apiVersion: v1kind: Servicemetadata: name: api-service namespace: appsspec: type: ClusterIP selector: app: api ports: - name: http port: 80 targetPort: 8080
Flujo:
Ingress ↓api-service:80 ↓Pods:8080
12. Crear Application Gateway v2 con frontend privado
Aquí está el cambio principal respecto al diseño anterior con Application Gateway for Containers.
El gateway tendría:
Application Gateway v2│├─ Private Frontend IP├─ HTTPS Listener├─ Backend Pool├─ Routing Rules├─ Health Probes└─ WAF_v2 opcional
Por ejemplo:
Private Frontend IP:10.10.20.10
Application Gateway puede utilizar private frontend IP para exponer el ingress únicamente dentro de la VNet. Microsoft Learn
13. Habilitar AGIC
AGIC se ejecuta como Pod dentro de AKS y observa los recursos Kubernetes Ingress. Luego traduce esa configuración a listeners, backend pools, reglas y probes en Application Gateway. Microsoft Learn
Puedes habilitarlo como add-on de AKS o instalarlo con Helm.
Conceptualmente:
Kubernetes Ingress ↓AGIC ↓Azure Resource Manager ↓Application Gateway v2
14. Crear Kubernetes Ingress
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: api-ingress namespace: apps annotations: kubernetes.io/ingress.class: azure/application-gateway appgw.ingress.kubernetes.io/use-private-ip: "true"spec: ingressClassName: azure-application-gateway rules: - host: api.company.com http: paths: - path: /api pathType: Prefix backend: service: name: api-service port: number: 80
La anotación:
appgw.ingress.kubernetes.io/use-private-ip: "true"
indica que AGIC debe utilizar la IP privada de Application Gateway. Microsoft Learn
15. Crear APIM Premium
APIM será la capa de gobierno de APIs:
API CatalogOAuth2 / JWTRate limitingQuotasVersioningTransformationsDeveloper PortalAnalyticsLogging
Como varios equipos y partners consumirán las APIs, APIM aporta gobierno centralizado y desacopla a los consumidores del backend AKS.
16. Crear Private Endpoint de APIM
Front Door Premium puede conectarse privadamente a APIM mediante Private Link. Microsoft Learn
Arquitectura:
Front Door Premium ↓Private Link ↓Private Endpoint ↓APIM Premium
Private DNS típico:
privatelink.azure-api.net
17. Configurar políticas APIM
Ejemplo:
<policies> <inbound> <base /> <validate-jwt header-name="Authorization" failed-validation-httpcode="401"> <openid-config url="https://login.microsoftonline.com/<TENANT-ID>/v2.0/.well-known/openid-configuration" /> </validate-jwt> <rate-limit-by-key calls="100" renewal-period="60" counter-key="@(context.Subscription.Id)" /> </inbound> <backend> <base /> </backend> <outbound> <base /> </outbound></policies>
18. Configurar backend APIM → Application Gateway privado
Este salto se realiza mediante conectividad privada en la VNet:
APIM ↓Private VNet connectivity ↓Application Gateway v2Private IP: 10.10.20.10
Backend URL conceptual:
https://10.10.20.10
o, preferiblemente, con DNS privado:
https://api-aks.internal.company.com
19. Crear Front Door Premium
La configuración conceptual:
Front Door Premium│├─ Endpoint│ └─ api.company.com│├─ Origin Group│ └─ APIM│├─ Route│ └─ /*│└─ WAF Policy
Front Door Premium soporta conectividad privada hacia APIM mediante Private Link. Microsoft Learn
20. Configurar WAF
En Front Door:
OWASP Managed RulesBot ProtectionRate LimitingGeo FilteringCustom RulesDDoS edge protection
Este es el punto de protección global de Internet.
21. Configurar DNS público
api.company.com ↓CNAME ↓Azure Front Door
Por tanto, ningún consumidor accede directamente a APIM ni a AKS.
22. Configurar Cilium Network Policies
El patrón recomendado:
Default deny+Explicit allow
Por ejemplo:
apiVersion: cilium.io/v2kind: CiliumNetworkPolicymetadata: name: api-policy namespace: appsspec: endpointSelector: matchLabels: app: api ingress: - fromEndpoints: - matchLabels: app: allowed-client toPorts: - ports: - port: "8080" protocol: TCP
Puedes ampliar con FQDN policies para controlar salida por dominio.
23. Configurar el egress del clúster
La secuencia es:
Pod ↓Node ↓UDR 0.0.0.0/0 ↓Azure Firewall ↓Internet
En Firewall crea:
Application RulesNetwork RulesFQDN rulesThreat IntelligenceLogging
y permite solamente destinos necesarios para:
AKSACRMicrosoft UpdateExternal APIsPartner APIs
Azure Firewall puede aplicar SNAT a los flujos outbound y centralizar la inspección del tráfico. Microsoft Learn
24. Mantener PaaS privado fuera del Firewall
Para recursos como:
Azure SQLStorageKey Vault
usa Private Endpoints:
Pod ↓Private DNS ↓Private Endpoint ↓Azure PaaS
Así el tráfico no tiene que salir a Internet.
25. Configurar Managed Prometheus
Flujo:
AKS ↓AMA Metrics ↓Azure Monitor Workspace ↓Managed Prometheus
26. Configurar Grafana
Managed Prometheus ↓Azure Managed Grafana ↓Dashboards
También puedes incluir:
Azure MonitorLog AnalyticsAlertsContainer Insights
27. Secuencia final de ingress
Para tu blog, esta es probablemente la parte más importante:
1. User ↓2. api.company.com ↓3. Azure Front Door Premium ↓4. WAF inspection ↓5. Private Link ↓6. APIM Premium Private Endpoint ↓7. APIM Policies ↓8. Application Gateway v2 Private Frontend ↓9. AGIC ↓10. Kubernetes Ingress ↓11. ClusterIP Service ↓12. Pods
28. Secuencia de identidad
1. Pod uses ServiceAccount ↓2. AKS generates OIDC token ↓3. Microsoft Entra ID validates federation ↓4. Entra ID issues Access Token ↓5. Pod accesses Key Vault ↓6. Key Vault returns Secret / Certificate
29. Secuencia de egress
1. Pod needs external access ↓2. Traffic reaches AKS subnet ↓3. UDR 0.0.0.0/0 ↓4. Azure Firewall ↓5. Firewall rules / SNAT ↓6. Internet / External API
30. Estructura recomendada del repositorio
platform/│├── terraform/│ ├── 01-network/│ ├── 02-firewall/│ ├── 03-aks/│ ├── 04-appgateway/│ ├── 05-apim/│ ├── 06-frontdoor/│ ├── 07-keyvault/│ ├── 08-private-endpoints/│ └── 09-monitoring/│└── kubernetes/ ├── 00-namespace.yaml ├── 01-serviceaccount.yaml ├── 02-deployment.yaml ├── 03-service.yaml ├── 04-ingress.yaml │ ├── security/ │ ├── cilium-networkpolicy.yaml │ └── secretproviderclass.yaml │ └── monitoring/ └── podmonitor.yaml
Resumen arquitectónico para el blog
El diseño separa claramente las responsabilidades:
EDGEFront Door Premium + WAFAPI GOVERNANCEAPIM PremiumPRIVATE L7 ROUTINGApplication Gateway v2 + AGICKUBERNETESIngress → Service → PodsNETWORK SECURITYCilium + Azure FirewallIDENTITYWorkload Identity + Entra IDSECRETSAzure Key Vault + Private EndpointOBSERVABILITYManaged Prometheus + Grafana + Azure Monitor
La ventaja principal de esta variante es que el tramo APIM → Application Gateway → AKS puede permanecer privado dentro de la VNet, mientras Front Door sigue siendo el único punto público de entrada y Azure Firewall controla exclusivamente el tráfico de salida. Microsoft Learn