ReplicaSets
A ReplicaSet ensures that a specified number of Pod replicas are running at any given time.
- If a Pod fails or is deleted, the ReplicaSet creates a new one to maintain the desired count
- Uses label selectors to identify which Pods it manages
- Typically managed by a Deployment rather than created directly
Exampleโ
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-replicaset
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ReplicaSet vs Deploymentโ
- A Deployment creates and manages ReplicaSets automatically
- Deployments provide rolling updates and rollbacks; ReplicaSets do not
- It is recommended to use Deployments instead of creating ReplicaSets directly