Kubernetes gives you two ways to run multiple identical Pods: ReplicaSets and Deployments.
A ReplicaSet keeps a fixed number of Pods running. A Deployment adds intelligence on top with rolling updates, rollbacks, and version history. The only difference we need to do in its yaml is change the kind.
The difference between a replicaset and deployment is here but 99 % of time we will use deployment only.
| Feature | Deployment (Smart Controller) | ReplicaSet (Pod Counter) |
| Rolling updates | Yes | No |
| Rollbacks | Yes | No |
| Version history | Yes | No |
| Behaviour on template change | Creates a new ReplicaSet | Kills all pods and recreates |
| Downtime | Zero downtime | Possible downtime |
| Purpose | Full lifecycle management | Maintain N identical pods |
1. Creating the Namespace
kubectl create namespace replica
kubectl config set-context --current --namespace=replica2. Applying the ReplicaSet
The only change in replicaset vs deployment is we change the kind from deployment to replicaset
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: my-rep
labels:
app: my-rep
spec:
replicas: 2
selector:
matchLabels:
app: my-rep
template:
metadata:
labels:
app: my-rep
spec:
containers:
- name: httpd
image: httpd3. Verifying the ReplicaSet
kubectl get rs
kubectl describe rs my-rep
kubectl get pods -o wide
4. Scaling the ReplicaSet by Imperative means
ie : testing
kubectl scale replicaset my-rep --replicas=55. Self-Healing Demo
kubectl delete pod <pod-name>
kubectl get pods -o wide

6. Declarative
We will just edit the yaml file and add replicas =3 as usual by editing the deploy file and then YAML becomes the source of truth
kubectl apply -f deploy.yml
7. Update the deployment
We will just edit the yaml file and add a new image as nginx:19.1
kubectl set image deployment/app nginx=nginx:19.1
8. Status of the deployment
kubectl roll out status deployment/app
9. History of the deployment
kubectl roll out history deployment/app
10. Und the deployment
kubectl roll undo deployment/app




