Course contentsShow
← Cloud and Infrastructure
Lesson 1161 of 2,98923. Kubernetes WorkloadsFree lesson

Creating Your First Deployment

Create a basic Deployment using kubectl and YAML, specifying container image, replicas, and labels.

Creating Your First Deployment

You'll learn how to create a Kubernetes Deployment using kubectl and YAML, defining replicas, container images, and labels.

What Is a Deployment Creation?

Now that you understand what Deployments are and their benefits, it's time to create one. A Deployment is typically defined in a YAML file that describes your desired application state: which container image to run, how many replicas you want, and metadata like labels that help you organize and select resources.

Think of creating a Deployment like ordering a fleet of identical delivery trucks—you specify the truck model (container image), how many you need (replicas), and their license plates (labels).

Creating a Deployment with YAML

Here's a basic Deployment manifest:

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

Apply this Deployment using kubectl:

kubectl apply -f deployment.yaml

Or create it directly via command line:

kubectl create deployment nginx-deployment --image=nginx:1.21 --replicas=3

Key Components

  • replicas: Number of Pod copies (3 in this case)
  • selector.matchLabels: How the Deployment finds its Pods
  • template.metadata.labels: Labels assigned to each Pod
  • containers.image: The container image to run

The Deployment creates a ReplicaSet, which then creates the specified number of Pods running your container.

Key Takeaway: Creating a Deployment involves defining your container image, replica count, and labels in a YAML manifest, then applying it with kubectl to establish your desired application state.