codegurukool.com · Free coding tutorials & online compiler

Home › Kubernetes Tutorial › Deployments

Deployments

Keep several identical Pods running.

You rarely create bare Pods. A Deployment manages a set of identical Pods through a ReplicaSet. If a Pod dies, a new one is created. The selector must match the labels in the Pod template. Deployments also give you rolling updates and rollbacks.

Example code

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: nginx
          image: nginx:1.27
          ports:
            - containerPort: 80

Run this code in the online editor

← Inspect Pods: get, describe, logsScaling and rolling updates →