YouTip LogoYouTip

Kubernetes Pods and Deployments

Introduction

Pods are the atomic units of Kubernetes, and Deployments manage their lifecycle. Understanding these resources is fundamental to running applications on Kubernetes.

Pod Definition

# pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp
    image: nginx:1.25
    ports:
    - containerPort: 80
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

Deployment

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: nginx:1.25
        ports:
        - containerPort: 80

Managing Deployments

# Apply configuration
kubectl apply -f deployment.yaml

# Check status
kubectl get deployments
kubectl get pods

# View detailed info
kubectl describe deployment myapp-deployment

# Update image
kubectl set image deployment/myapp-deployment myapp=nginx:1.26

# Rollback
kubectl rollout undo deployment/myapp-deployment

Summary

Deployments manage pods declaratively. Define desired state in YAML, apply with kubectl, and use rollout commands for updates and rollbacks.

← Kubernetes Services and IngresKubernetes Tutorial - Getting β†’