ReplicaSet Manifest Structure
What You'll Learn
You'll learn how to write a complete ReplicaSet YAML specification, including the three essential components: replica count, selectors, and Pod templates.
The Core Structure
A ReplicaSet manifest follows a specific structure that tells Kubernetes how many Pods to run, which Pods to manage, and what those Pods should look like. Think of it as a recipe with three critical sections: the quantity you need, how to identify the dishes you're making, and the detailed instructions for each dish.
The Three Essential Components
1. Replica Count (spec.replicas)
This simple number tells Kubernetes how many identical Pods you want running at all times.
2. Selector (spec.selector)
This uses labels to identify which Pods belong to this ReplicaSet. The selector acts like a manager's attendance sheet—it must match the labels on the Pods exactly.
3. Pod Template (spec.template)
This is a complete Pod specification nested inside your ReplicaSet. It defines the containers, images, ports, and any other Pod configuration. The ReplicaSet uses this template to create new Pods when needed.
The Manifest Layout
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: my-replicaset
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx
image: nginx:1.20
Notice how selector.matchLabels must match template.metadata.labels—this connection is mandatory. The ReplicaSet won't work without this alignment.
Key Takeaway:
A ReplicaSet manifest requires three coordinated pieces: a replica count specifying quantity, a selector identifying managed Pods through labels, and a Pod template defining the exact Pod configuration to maintain.