0
0
KubernetesConceptBeginner · 3 min read

What is Deployment in Kubernetes: Explained with Example

A Deployment in Kubernetes is a resource that manages a set of identical pods, ensuring the desired number of pods are running and updated. It automates updates and rollbacks for your application containers.
⚙️

How It Works

Think of a Deployment as a manager who keeps a team of workers (pods) ready and working. If a worker stops or crashes, the manager quickly replaces it to keep the team size steady. This way, your application stays available and reliable.

When you want to update your app, the deployment manager carefully replaces old workers with new ones, one by one or in batches, so the work never stops. If something goes wrong, it can roll back to the previous version automatically.

💻

Example

This example shows a simple deployment that runs three copies of an NGINX web server. Kubernetes will keep these three pods running and replace any that fail.

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.23.3
        ports:
        - containerPort: 80
Output
deployment.apps/nginx-deployment created
🎯

When to Use

Use a Deployment when you want to run and manage multiple copies of your application reliably. It is perfect for web servers, APIs, or any service that needs to stay online and handle updates smoothly.

For example, if you have a website that must be available 24/7, a deployment ensures your site keeps running even if some servers fail or when you update the site to a new version.

Key Points

  • Deployment manages pods and ensures the desired number are running.
  • It automates updates and rollbacks for your app containers.
  • It uses labels to select which pods to manage.
  • It helps keep your app available and scalable.

Key Takeaways

A Kubernetes deployment manages and maintains a set number of pods running your app.
It automates rolling updates and rollbacks to keep your app stable during changes.
Deployments use labels to identify and control pods.
Use deployments to ensure your app stays available and scales easily.
Deployments simplify managing containerized applications in Kubernetes.