🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: Create a Deployment

A Deployment manifest is a YAML file that describes a Deployment. It names the image, the replica count and the labels that link it to its Pods.

Write the manifest

The selector says app web. The Pod template labels say app web too. That match is what links them.

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

Create the Deployment

apply creates the Deployment. The Deployment then creates three Pods.

kubectl apply -f web-deployment.yaml

Check the ready count

3/3 means all three copies are ready. The Deployment is doing its job.

kubectl get deployments

See the three Pods

Each Pod name starts with web. The shared start shows they belong to one Deployment.

kubectl get pods

Example

kubectl apply -f web-deployment.yaml
kubectl get deployments
kubectl get pods

Key points

  • Use kubectl apply -f to create a Deployment from a manifest file.
  • A Deployment manifest needs apiVersion apps/v1 and kind Deployment.
  • A Deployment spec needs replicas, a selector and a Pod template.
  • The selector matchLabels must match the Pod template labels exactly.
  • Use kubectl get deployments to check the ready count.
  • Use kubectl get pods to see the Pods the Deployment created.

In this example, apply creates a Deployment with three replicas. get deployments shows 3/3 ready. get pods shows the three Pods. The selector labels match the Pod template labels exactly, so the Deployment finds its Pods.

Note

Change the image or the replica count in the file, then apply it again to update the Deployment.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which two parts of a Deployment manifest must match exactly?