Azure Kubernetes Service (AKS) Documentation

Manage Applications Effectively

Managing Applications in Azure Kubernetes Service (AKS)

Once your applications are deployed to Azure Kubernetes Service (AKS), you'll need effective strategies for managing their lifecycle, monitoring their health, and ensuring they run optimally. This guide covers key aspects of application management in AKS.

Monitoring Application Health and Performance

Monitoring is crucial for understanding how your applications are performing and for detecting issues early. AKS integrates with Azure Monitor to provide comprehensive monitoring capabilities.

  • Container Insights: Collects, analyzes, and presents logs and performance metrics from your AKS cluster. It provides visualizations of CPU/memory usage, application performance, and network traffic.
  • Azure Monitor Alerts: Set up alerts based on predefined or custom metrics to notify you of critical events, such as high error rates, resource exhaustion, or application downtime.
  • Application Performance Management (APM): Integrate APM tools like Application Insights for deep insights into application code execution, dependencies, and end-user experience.

Updating and Rolling Back Applications

Deploying new versions of your applications or rolling back to a previous version is a common task. Kubernetes provides robust deployment strategies.

  • Rolling Updates: Gradually update your application by replacing old pods with new ones. This ensures zero downtime during updates.
  • Deployment Strategies: Kubernetes Deployments allow you to define update strategies like `RollingUpdate` (default) or `Recreate`.
  • Rollbacks: If an update causes issues, you can easily roll back to a previous stable version of your deployment. Kubernetes keeps a history of revisions.

To perform a rolling update:


kubectl set image deployment/ =
                

To view deployment history and roll back:


kubectl rollout history deployment/
kubectl rollout undo deployment/ --to-revision=
                

Managing Application Configuration

Externalizing configuration from your application code is a best practice. Kubernetes offers several resources for managing configuration.

  • ConfigMaps: Store non-sensitive configuration data as key-value pairs. These can be mounted as volumes or used as environment variables.
  • Secrets: Store sensitive information like passwords, API keys, and tokens. Secrets are base64 encoded (though not encrypted by default at rest, they are managed more securely than ConfigMaps).

Example of creating a ConfigMap:


apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  app.properties: |
    database.url=jdbc:postgresql://localhost:5432/mydatabase
    api.endpoint=https://api.example.com
                

Handling Application Logs

Centralized logging is essential for debugging and auditing. AKS can be configured to collect logs from your containers and send them to a central logging solution.

  • stdout/stderr: Applications running in containers should log to standard output (stdout) and standard error (stderr).
  • Log Aggregation: AKS can integrate with solutions like Azure Monitor Logs (Log Analytics workspace) or other third-party logging platforms to collect and analyze logs from all your cluster nodes and pods.

Implementing Health Checks

Kubernetes uses health probes to determine the health of your application pods and to manage their lifecycle effectively.

  • Liveness Probes: Kubernetes restarts a container if it fails its liveness probe.
  • Readiness Probes: Kubernetes will not send traffic to a pod until it passes its readiness probe.
  • Startup Probes: For slow-starting applications, startup probes can prevent liveness and readiness probes from failing prematurely.

Example of a Deployment with liveness and readiness probes:


apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: app-container
        image: my-docker-repo/my-app:v1.0
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /healthz
            port: 80
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /ready
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 10