Una vez tenemos los manifiestos de deployments y services, se envían al cluster con kubectl apply. K8s se encarga del resto.
Deploy con kubectl apply
El comando kubectl apply es la herramienta principal para hacer despliegues a AKS.
# Code fragment - focus on kubectl apply commands
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
# Or deploy both in one command:
kubectl apply -f deployment.yaml -f service.yaml
# Or deploy all YAML files in a directory:
kubectl apply -f .
El comando es asíncrono. Devuelve al instante pero puede tardar unos momentos en hacer los cambios
Verificar deployment status
Una vez hemos hecho el deployment, podemos verificar que funciona todo
# Code fragment - focus on verifying deployment status
# Check Pod status
kubectl get pods
# Output:
# NAME READY STATUS RESTARTS AGE
# inference-api-7d8b4f9c6-abc12 1/1 Running 0 2m
# inference-api-7d8b4f9c6-xyz78 1/1 Running 0 2m
# Check Deployment status
kubectl get deployment
# Output:
# NAME READY UP-TO-DATE AVAILABLE AGE
# inference-api 2/2 2 2 2m
kubectl get svc
# Output:
# NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
# inference-api-service LoadBalancer 10.0.12.45 40.89.123.45 80:30523/TCP
Ver logs para diagnosticar fallos
# Code fragment - focus on checking logs
# View logs from a specific Pod
kubectl logs inference-api-7d8b4f9c6-abc12
# View logs from the last 10 minutes
kubectl logs inference-api-7d8b4f9c6-abc12 --since=10m
# View logs from all Pods in the Deployment
kubectl logs -l app=inference-api
Comprobar conectividad
Verificar que la app responde a las requests
ClusterIP services (internal only)
Ejecutar un test pod y llamar al service DNS directo
# Code fragment - focus on testing internal services
# Run a test Pod
kubectl run -it --rm debug --image=alpine:latest --restart=Never -- sh
# Inside the debug Pod, test the service
wget http://inference-api-service:80
LoadBalancer services (external)
Usar la IP pública para testear
# Code fragment - focus on testing external services
# Get the external IP
kubectl get svc inference-api-service
# Test with curl
curl http://40.89.123.45
# Or test a specific endpoint
curl http://40.89.123.45/predict -X POST -d '{"input": "test"}'
Troubleshooting common issues
ImagePullBackOff
Kubernetes no puede hacer pull de la imagen del contenedor en el registro.
CrashLookBackOff
La aplicación no funciona o se crashea en el startup
Pending pods
K8s no puede asignar pods - recursos insuficientes o issues de nodo
Service no tiene endpoints
El selector está mal. No hace match con ningún Pod.
Additional resources
Best Practices for Azure Kubernetes Service (AKS) - Azure Kubernetes Service
Debug Pods