Deployment Rings :👈 👉:Cloud-Services

Pods in Azure Kubernetes Service (AKS)

Pods in Azure Kubernetes Service (AKS)

1. What Is a Pod?

A Pod is the smallest deployable unit in Kubernetes.

In Azure Kubernetes Service (AKS), a Pod is used to run one or more containers that host your application.

For example, suppose you have developed an ASP.NET Core Web API application. You package your application into a Docker container and deploy it to AKS. Kubernetes runs that container inside a Pod.

In simple words:

  • Container: Runs your application in an isolated environment.
  • Pod: Kubernetes unit that runs one or more containers.
  • Node: Virtual machine that provides resources to run Pods.
  • Cluster: Collection of Kubernetes nodes.
  • AKS: Azure's managed Kubernetes service.

2. Understand Pods with a Real-World Example

Suppose you are developing an online shopping application.

Your application has three microservices:

  • User API
  • Product API
  • Order API

Each microservice can run inside its own Pod.

AZURE KUBERNETES SERVICE (AKS) Kubernetes User Pod Container User API Product Pod Container Product API Order Pod Container Order API

Each Pod runs independently and can be managed by Kubernetes.

3. What Is Inside a Pod?

A Pod can contain one or more containers.

Example 1: Single-Container Pod

This is the most common approach.

USER API POD Container ASP.NET Core Web API
  • One Pod contains one container.
  • The container runs your ASP.NET Core application.
  • Kubernetes manages the Pod.

Example 2: Multiple-Container Pod

Sometimes multiple containers need to work closely together.

APPLICATION POD Main Container Web API Sidecar Container Log Agent Shared Resources

For example:

  • Main container runs your application.
  • Sidecar container collects application logs.
  • Both containers can share network resources and configured storage volumes.

Important: Containers inside the same Pod share the same network namespace and IP address. They can communicate using localhost.

4. Relationship Between Pod, Container, Node and Cluster

These are the most important Kubernetes concepts.

Azure AKS Cluster Node 1 Node 2 Pod 1 Pod 2 Pod 3 Container User API Container Product API Container Order API
Component Meaning
Cluster Collection of Kubernetes nodes.
Node Virtual machine that runs Pods.
Pod Smallest deployable Kubernetes unit.
Container Runs your application.
Deployment Manages Pod replicas and updates.
Service Provides stable network access to Pods.

A node can run multiple Pods depending on its available resources and Kubernetes scheduling constraints.

5. What Is a Pod IP Address?

Every Pod receives its own IP address within the Kubernetes cluster network.

Example:

Pod Application Pod IP
Pod 1 User API 10.244.1.10
Pod 2 Product API 10.244.1.11
Pod 3 Order API 10.244.2.10

Suppose User API wants to communicate with Product API. It can communicate through the Kubernetes Service associated with Product API.

Important: Pod IP addresses are generally temporary. When a Pod is recreated, it can receive a different IP address.

That is why Kubernetes Services are used instead of depending directly on Pod IP addresses.

6. What Is a Deployment in Kubernetes?

A Deployment manages your Pods.

Suppose your application needs three running instances. Instead of manually creating three Pods, you create a Deployment with three replicas.

Example: Kubernetes Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: user-api
  template:
    metadata:
      labels:
        app: user-api
    spec:
      containers:
        - name: user-api
          image: myregistry.azurecr.io/user-api:v1
          ports:
            - containerPort: 8080

Explanation

Property Meaning
apiVersion Kubernetes API version.
kind Resource type; here it is Deployment.
metadata.name Deployment name.
replicas Number of desired Pod replicas.
selector Identifies Pods managed by the Deployment.
template Defines how Pods should be created.
containers Container configuration.
image Docker image location.
containerPort Application container port.

Here:

replicas: 3

Means Kubernetes should maintain three Pod replicas.

USER API DEPLOYMENT Replicas: 3 Pod 1 Pod 2 Pod 3 Container Container Container User API User API User API

If one Pod crashes, Kubernetes attempts to create another Pod to maintain the desired replica count.

7. What Happens When a Pod Crashes?

Suppose your application has three Pods.

1. Normal State (Desired Replicas = 3) USER API DEPLOYMENT Replicas: 3 Pod 1 Pod 2 Pod 3 Running Running Running 2. Pod 2 Crashes USER API DEPLOYMENT Replicas: 3 Pod 1 Pod 2 Pod 3 Running ✅ Failed ❌ Running ✅ Kubernetes creates replacement Pod 3. Self-Healing: New Pod Created Pod 1 Pod 4 Pod 3

Kubernetes detects that only two desired replicas are available. It attempts to create a replacement Pod.

Now three Pods are running again.

This is called self-healing.

Note: Kubernetes can recreate failed Pods, but it cannot automatically fix bugs in your application code.

8. Different Pod States

Kubernetes provides different Pod phases and container states.

State Meaning
Pending Pod has been accepted but is not yet fully running.
Running Pod is bound to a node and at least one container is running or starting.
Succeeded All containers completed successfully.
Failed All containers have terminated and at least one failed.
Unknown Kubernetes cannot determine the Pod state.

Common Container Statuses

Status Meaning
CrashLoopBackOff Container repeatedly crashes and Kubernetes is delaying restart attempts.
ImagePullBackOff Kubernetes cannot pull the container image.
ErrImagePull Container image download failed.
ContainerCreating Container is being created.
Terminating Pod is being deleted.
OOMKilled Container was terminated because it exceeded its memory limit.

9. How to Check Pods in Azure AKS?

You can check Pods using Azure Cloud Shell, your local terminal with kubectl, or the Kubernetes resources view in Azure Portal.

Step 1: Connect to Azure

az login

Step 2: Get AKS Credentials

az aks get-credentials \
  --resource-group MyResourceGroup \
  --name MyAKSCluster

Step 3: List All Pods

kubectl get pods

Example output:

NAME                       READY   STATUS    RESTARTS
user-api-7d8f9c6b5-x1abc   1/1     Running   0
user-api-7d8f9c6b5-x2def   1/1     Running   1
user-api-7d8f9c6b5-x3ghi   1/1     Running   0

Step 4: Get Pods from All Namespaces

kubectl get pods -A

Step 5: Get Detailed Pod Information

kubectl describe pod user-api-7d8f9c6b5-x1abc

This provides:

  • Pod IP address.
  • Node name.
  • Container details.
  • Restart count.
  • Events.
  • Resource information.
  • Health probe information.

Step 6: Check Pod Logs

kubectl logs user-api-7d8f9c6b5-x1abc

For a Pod containing multiple containers:

kubectl logs user-api-7d8f9c6b5-x1abc -c user-api

Step 7: Check Pod Resource Usage

kubectl top pods

This displays CPU and memory consumption. Metrics Server must be available for this command to work.

Step 8: Watch Pods Continuously

kubectl get pods -w

This continuously displays changes in Pod status.

10. How to Test Whether a Pod Is Working?

Just because a Pod shows Running does not necessarily mean your application is working correctly.

1. Check Pod Status

kubectl get pods

2. Check Container Readiness

kubectl get pods

For example:

READY
1/1

Means one out of one containers is ready.

3. Check Application Logs

kubectl logs <pod-name>

4. Check Health Probes

Kubernetes supports three important health probes:

  • Liveness Probe: Checks whether the container should be restarted.
  • Readiness Probe: Checks whether the Pod should receive traffic.
  • Startup Probe: Checks whether the application has completed startup.

Example:

livenessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 15
readinessProbe:
  httpGet:
    path: /health
    port: 8080
  periodSeconds: 10

The application must expose the /health endpoint for these HTTP probes to work.

5. Check Application Connectivity

kubectl port-forward pod/<pod-name> 8080:8080

Then test:

curl http://localhost:8080/health

This forwards your local port 8080 to the Pod's port 8080.

11. What Is the Difference Between Pod and Service?

A Pod can be recreated, and its IP address can change.

A Kubernetes Service provides a stable network endpoint to access a group of matching Pods.

USER API SERVICE 10.0.0.100 Pod 1 Pod 2 Pod 3 User API User API User API Service load-balances traffic across all healthy User API pods

If Pod 2 crashes and a new Pod is created, the Service can automatically route traffic to available matching Pods.

12. Pod vs ReplicaSet vs Deployment vs Service

Component Responsibility
Pod Runs containers.
ReplicaSet Maintains the desired number of Pod replicas.
Deployment Manages ReplicaSets and application updates.
Service Provides stable networking and load balancing to matching Pods.

Typical relationship:

DEPLOYMENT REPLICASET POD 1 POD 2 POD 3 Container Container Container SERVICE Routes Traffic to Pods Service selects Pods using labels and load-balances traffic across healthy instances

13. Best Practices for Pods in AKS

  1. Use Deployments instead of manually creating application Pods.
  2. Configure CPU and memory requests and limits appropriately.
  3. Configure readiness, liveness and startup probes.
  4. Use multiple replicas for application availability where appropriate.
  5. Avoid storing important application data inside the temporary Pod filesystem.
  6. Use Azure Key Vault with appropriate workload identity integration for secrets.
  7. Monitor Pod logs, CPU, memory and restart counts.
  8. Use namespaces to logically separate application resources.
  9. Configure Pod Disruption Budgets where appropriate.
  10. Use rolling updates or progressive deployment strategies to reduce deployment risks.

14. Final Summary

Term Simple Explanation
AKS Managed Kubernetes service in Azure.
Cluster Collection of Kubernetes nodes.
Node Virtual machine running Pods.
Pod Smallest deployable unit in Kubernetes.
Container Runs your application.
Deployment Manages Pods and updates.
ReplicaSet Maintains the desired number of Pods.
Service Provides stable access to Pods.
Namespace Logical separation of Kubernetes resources.

Remember: Your application runs inside a container, the container runs inside a Pod, and the Pod runs on a Kubernetes Node. AKS manages the Kubernetes cluster and helps maintain the desired application state.

🔙
Deployment Rings :👈 👉:Cloud-Services