Deployment Spec Structure
What you'll learn: You'll understand how a Kubernetes Deployment manifest is organized and how its key sections work together to define your application's desired state.
The Blueprint of a Deployment
A Deployment manifest is a YAML file that tells Kubernetes exactly how to run and manage your application. Think of it as an architect's blueprint—every section has a specific purpose and they all connect to create the complete picture.
The Four Essential Sections
metadata: This is the Deployment's identity card. It contains the name, namespace, labels, and annotations that identify and describe the Deployment itself.
spec: This is where you define what you want. The spec contains the deployment's desired state, including how many replicas you want and the deployment strategy.
selector: This section uses label selectors to identify which Pods belong to this Deployment. It's the glue that connects the Deployment to the Pods it manages. The labels here must match the labels in the Pod template.
template: Nested inside the spec, this is essentially a Pod specification. It defines the actual containers, volumes, and configuration for the Pods that will be created. The template has its own metadata (with labels) and spec (describing containers).
How They Relate
The relationship works like this: The Deployment (defined by its metadata and spec) uses the selector to find its Pods, and creates those Pods based on the template. The selector's matchLabels must align with the template's metadata.labels—this is how Kubernetes knows which Pods are part of which Deployment.
Key Takeaway: A Deployment manifest has four interconnected parts: metadata identifies the Deployment, spec defines desired state and replica count, selector links to Pods via labels, and template describes the Pod blueprint—with selector labels matching template labels to maintain the relationship.