Skip to main content

Lesson 5 of 9

Kubernetes Deployment - AKS

AKS (Azure Kubernetes Service) runs your containerized API at scale: multiple pods handle traffic, HPA scales pods up/down based on CPU/memory, PodDisruptionBudget ensures availability during deployments, and Ingress routes external traffic. ConfigMaps and Secrets provide non-sensitive and sensitive configuration.

25 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Kubernetes Manifests for Production

Kubernetes Manifests for Production
# ━━ Deployment - runs API pods ━━
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-api
  namespace: prod
  labels:
    app: myapp-api
    version: v1.0.0
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp-api
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0    # never take pods down during update (zero downtime)
      maxSurge: 1          # temporarily run one extra pod during update
  template:
    spec:
      containers:
        - name: api
          image: myappregistry.azurecr.io/myapp-api:sha-abc123
          ports:
            - containerPort: 8080
          resources:
            requests:
              memory: "256Mi"
              cpu: "250m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          env:
            - name: ASPNETCORE_ENVIRONMENT
              value: Production
            - name: ConnectionStrings__DefaultConnection
              valueFrom:
                secretKeyRef:
                  name: myapp-secrets
                  key: db-connection-string
          envFrom:
            - configMapRef:
                name: myapp-config       # non-sensitive config
          livenessProbe:
            httpGet:
              path: /health/live
              port: 8080
            initialDelaySeconds: 15
            periodSeconds: 30
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health/ready
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 10
            failureThreshold: 3       # remove from load balancer after 3 failures

---
# ━━ HPA - scale on CPU ━━
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-api-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp-api
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70    # scale up when avg CPU > 70%

---
# ━━ PodDisruptionBudget - ensure availability during node drain ━━
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: myapp-api-pdb
spec:
  minAvailable: 2          # at least 2 pods must always be running
  selector:
    matchLabels:
      app: myapp-api

Tip

Tip

Practice Kubernetes Deployment AKS in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

.NET provides a unified platform for building various application types

Practice Task

Note

Practice Task - (1) Write a working example of Kubernetes Deployment AKS from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Kubernetes Deployment AKS is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready dotnet code.

Topics in This Module

0/9 done