Guía para Desplegar .NET 8 en AKS

Guía para desplegar una API .NET 8 en Azure con Docker y Kubernetes (AKS) usando CI/CD con GitHub Actions. Contenerización, health checks y prácticas recomendadas.

19 sept 2025 • 5 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Guía para desplegar una aplicación .NET 8 en la nube usando Docker y Kubernetes pensada para principiantes. Este artículo te lleva paso a paso desde la creación de una API Web mínima en .NET 8 hasta su empaquetado en Docker, el despliegue en Azure Kubernetes Service AKS y la automatización del proceso con GitHub Actions para que cada push actualice tu aplicación en la nube.

Qué aprenderás: construir una API Web .NET 8, contenerizar la aplicación con Docker, desplegar contenedores en Kubernetes en la nube, y configurar despliegues automáticos con GitHub Actions.

Requisitos básicos en tu equipo: editor como Visual Studio Code, .NET 8 SDK instalado, Docker Desktop en ejecución, Azure CLI, kubectl, Git y opcionalmente GitHub CLI. Comprueba las instalaciones con dotnet --version, docker --version, az --version, kubectl version --client, git --version y gh --version.

Paso 1 Crear la aplicación .NET 8: crea una carpeta de proyecto, inicializa una plantilla minimal Web API con dotnet new webapi -minimal, añade health checks y Swagger con los paquetes Microsoft.Extensions.Diagnostics.HealthChecks y Swashbuckle.AspNetCore. Configura Kestrel para escuchar en el puerto 8080 y expón endpoints como raiz slash, slash weather y slash health. Ejecuta la app con dotnet run y pruébala en https://localhost:8080.

Paso 2 Contenerizar la aplicación: crea un Dockerfile con multi stage build usando mcr.microsoft.com/dotnet/aspnet:8.0 para runtime y mcr.microsoft.com/dotnet/sdk:8.0 para build. Expón el puerto 8080 y usa Entrypoint dotnet NombreDeTuApp.dll. Añade un archivo .dockerignore para excluir bin, obj, .git y archivos de IDE. Construye la imagen con docker build -t weather-app:local . y pruébala con docker run -d -p 8080:8080 --name weather-test weather-app:local.

Paso 3 Infraestructura en Azure: autentícate con az login, selecciona la suscripción con az account set, crea un resource group con az group create. Crea un Azure Container Registry ACR con az acr create y usa az acr build --registry NombreACR --image weather-app:latest . para construir y subir la imagen desde Azure. Crea un clúster AKS con az aks create --resource-group RG --name NombreAKS --node-count 1 --attach-acr NombreACR --enable-managed-identity --generate-ssh-keys. Obtén credenciales para kubectl con az aks get-credentials.

Paso 4 Manifiestos Kubernetes: en una carpeta k8s crea deployment.yaml que defina replicas, requests y limits, y probes de liveness, readiness y startup apuntando a /health en el puerto 8080. Crea service.yaml tipo LoadBalancer que exponga el puerto 80 y haga target al 8080. Aplica los manifiestos con kubectl apply -f deployment.yaml y kubectl apply -f service.yaml y comprueba estado con kubectl get deployments, kubectl get pods, kubectl get services.

Paso 5 CI CD con GitHub Actions: inicializa un repositorio git, crea un service principal en Azure con az ad sp create-for-rbac --name NombreSP --role contributor --scopes /subscriptions/ID/subresourceGroups/RG --sdk-auth y copia el JSON resultante. Crea un repositorio en GitHub, añade los secretos AZURE_CREDENTIALS con el JSON, ACR_NAME, RESOURCE_GROUP y CLUSTER_NAME en GitHub Secrets. Crea un workflow que haga checkout, configure .NET 8, compile y pruebe, haga login en Azure, construya y suba la imagen con az acr build y actualice el deployment en AKS con kubectl set image deployment/weather-app weather-app=NombreACR.azurecr.io/weather-app:SHA. Asegúrate de que el workflow se active en pushes a la rama main.

Paso 6 Accede a la aplicación desplegada: recupera la IP externa del servicio con kubectl get service weather-app-service y, una vez asignada, prueba endpoints como slash, slash weather y slash health desde el navegador o curl.

Paso 7 Prueba despliegue continuo: realiza un cambio pequeño en Program.cs, commitea y push a main. Observa en la pestaña Actions de GitHub cómo se construye la imagen, se sube a ACR y se actualiza el deployment en AKS. Verifica que el nuevo mensaje aparece en la IP externa.

Consejos de resolución de problemas: ante ImagePullBackOff comprueba que la imagen existe en ACR y que AKS tiene permisos AcrPull. Usa kubectl describe pod, kubectl logs, az acr repository show-tags y kubectl rollout restart deployment/weather-app para depurar. Si kubectl no se encuentra, instala la CLI oficial. Si el demonio Docker no responde, inicia Docker Desktop.

Limpieza de recursos: cuando termines elimina recursos individuales con az aks delete, az acr delete o borra todo el resource group con az group delete --name RG --yes --no-wait para evitar costes continuos.

Buenas prácticas incluidas en la guía: uso de probes para fiabilidad, límites de recursos para eficiencia, multi stage Docker builds para imágenes ligeras, testing local antes de subir imágenes y despliegues con rolling updates para cero downtime.

En Q2BSTUDIO somos especialistas en desarrollo de software y aplicaciones a medida. Ofrecemos servicios integrales que incluyen desarrollo de software a medida, soluciones cloud y modernización de aplicaciones. Si buscas soporte para desplegar tu plataforma en Azure o AWS podemos ayudarte con arquitectura, automatización y seguridad; conoce nuestros servicios cloud. Además diseñamos soluciones de inteligencia artificial y agentes IA para empresas que integran modelos avanzados en procesos productivos, consulta nuestras propuestas de inteligencia artificial.

Palabras clave integradas para SEO: aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA, power bi. Si necesitas soporte profesional, auditoría de seguridad o integración con Power BI para inteligencia de negocio, en Q2BSTUDIO ofrecemos servicios completos y acompañamiento desde la idea hasta la operación.

Resumen final: siguiendo estos pasos tendrás una API .NET 8 lista para producción en AKS con imágenes en ACR y despliegue automatizado con GitHub Actions. Esta guía cubre conceptos clave de Docker, Kubernetes y Azure y te deja la base para añadir bases de datos, observabilidad con Application Insights, autoscaling, Ingress y prácticas de seguridad como autenticación con Azure AD. Si quieres llevarlo al siguiente nivel, desde Q2BSTUDIO podemos ayudarte a implementar soluciones avanzadas de ciberseguridad, automatización de procesos e inteligencia de negocio con Power BI.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.