Middle
What is a replica set and deployment?
sobes.tech AI
Answer from AI
ReplicaSet ensures a specified number of identical pods running in a cluster. It monitors the state of pods and automatically replaces those that have failed or stopped.
Deployment is built on top of ReplicaSet. It manages application updates and rollbacks, maintaining a deployment version history. It allows updates using strategies like rolling update or recreate.
# Example Deployment manifest
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3 # Defines the desired number of pods (via ReplicaSet)
selector:
matchLabels:
app: nginx
strategy:
type: RollingUpdate # Update strategy
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2 # Image version to be updated
ports:
- containerPort: 80
In this example, Deployment creates a ReplicaSet that maintains 3 pods with the image nginx:1.14.2. When the image version in the Deployment manifest is changed, it creates a new ReplicaSet for the new version and gradually shifts traffic to it, removing old pods according to the rolling update strategy.
Comparison table:
| Feature | ReplicaSet | Deployment |
|---|---|---|
| Guarantees number of pods | ✅ | ✅ |
| Application updates | ❌ | ✅ |
| Version rollback | ❌ | ✅ |
| Manages deployment history | ❌ | ✅ |