Concepts

![[images/截屏2026-03-24 11.44.48.png]]

A ReplicaSets is a declarative way to manage Pods.

A Deployment is a declarative way to manage Pods using a ReplicaSet.

  • Deployments are a higher-level resource that define one or more Pod templates.
  • Deployments and ReplicaSets ensure Pods stay running and can be used to scale Pods.

ReplicaSets

ReplicaSets act as a Pod controller

  • Self-healing mechanism
  • Ensure the requested number of Pods are available
  • Provide fault-tolerance
  • Can be used to scale Pods
  • Relies on a Pod template
  • No need to create Pods directly
  • Used by Deployments

Deployment

A Deployment manages Pods:

  • Pods are managed using RelicaSets
  • Scales ReplicaSets, which scale Pods
  • Supports zero-downtime updates by creating and destroying ReplicaSets
  • Provides rollback functionality
  • Creates a unique label that is assigned to the ReplicaSet and generated Pods
  • YAML is very similar to a ReplicaSet

Creating A Deployment

![[images/截屏2026-03-24 13.27.22.png]]

![[images/截屏2026-03-24 13.29.22.png]]

![[images/截屏2026-03-24 13.31.01.png]]

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: my-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-nginx
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
      - name: frontend
        image: nginx:alpine
        ports:
        - containerPort: 80
        resources:
          requests:
            memory: "64Mi"
            cpu: "100m" #100
          limits:
            memory: "128Mi"
            cpu: "250m"

kubectl

Create

# Create a Deployment with --filename or -f
kubectl create -f [yaml_name.yaml]
# Create or apply changes to a Deployment
kubectl apply -f [yaml_name.yaml]
# Want to use kubectl apply in the future
kubectl create -f [yaml_name.yaml] --save-config

kubectl apply is more common but kubectl create can avoid overriding the existing resource.

Get

kubectl get deployment
# Show labels
kubectl get deployment --show-labels
# Get Deployments with a specific label
kubectl get deployment -l app=[label_name]

Delete

kubectl delete deployment [deployment_name]

Scale

kubectl scale deployment [deployment_name] --replicas=[number]
# with YAML file
kubectl scale -f [yaml_name.yaml] --replicas=[number]

Or write replicas in the YAML

spec:
	replicas: 3
	selector:
		tier: frontend

Zero Downtime Deployment

Zero downtime deployments allow software updates to be deployed to production without impacting end users.

Options

  • Rolling updates
  • Blue-green deployments
  • Canary deployments
  • Rollbacks

Rolling Deployments

![[images/截屏2026-03-24 14.29.08.png]]

When update Pods, the old Pod will be delete one by one and rollout the version Pod.

![[images/截屏2026-03-24 14.30.49.png]]