![[Pasted image 20250207033040.png]] ### ReplicaSet _ReplicaSet_ initialises $n$ number of pods. It enables us to have **replication**. Also, the `replicatoinController` make sure the desired state is met. ![[Pasted image 20250207033201.png]] ### Deployment _Deployment_ is the mature version of _ReplicaSet_. We often use it in _serverless_ models. It enables us to have _history_ and _rollbacks_. Under the hood, it uses _ReplicaSets_. ![[Pasted image 20250207033510.png|deployment-k8s]] The current status can be fetched by `kubectl rollout history` command. #### Strategy When we want to change the version of pods in deployments, we can do it in different ways. 1. **Recreate**: _all_ old pods will get down, then the new pods will be created. 2. **RollingUpdate**: one of old pods gets down, then one of the new ones will be created. Repeat. 3. **Blue/Green**: the new pod will get created, then the traffic will be redirected, then old one will be deleted. 4. **Canary**: a small part of the traffic will be redirected to the new pod, if approved, the rest will be redirected and then the old pod will be deleted. 5. **A/B testing**: like canary test, but users with specific properties will be redirected first. 6. **Shadow**: all the traffic will be passed from the new pod, but the old one will be answering. ![[Pasted image 20250207035025.png|deployment strategies k8s]] _Recreate_ is normally used in _stateful_ applications. _RollingUpdate_ is normally used in _serverless_ applications. ### StatefulSet _StatefulSet_ is suitable for _stateful_ applications. (e.g. databases, message-queues). ![[Pasted image 20250207035505.png]] As opposed to _deployment_ workloads, in _statefulSets_ pod names are sequential and its name can be predicted. In case of scale-up, the new pod will be **appended** to the cluster. In case of scale-down, the last pod will be popped and get down. ![[Pasted image 20250207040125.png]] In case of initialisation of multiple pods, all new pods will be created at the same time in _deployment_. However, in statefulSets, one pod will be created, when ready, the second pod will be cloned from the first one. StatefulSets use a _headless service_ and it does not load-balance between pods. In case of termination in pods, statefulSets does not guarantee the termination of the pods. ### DaemonSet Creates the pod in every available node. e.g If we have 7 nodes in our cluster, we would have 7 replicas of that pod in our cluster. Normally is used for _logging agents_ or _monitoring agents_ that needs to be available per node. DaemonSet is called _Global Service_ in Docker Swarm. Sometimes, DaemonSets are compared to [[Objects#Static Pods|static pods]]. ![[Pasted image 20250207041203.png]] ### Job Jobs are created when we want to create a pod, it does it work, then terminates. (e.g. every time a new video is uploaded, transcode it.) The _cronjob controller_ creates _jobs_ based on different scenarios. (just like Linux cronjob). Normally, it is used for getting backups or updating a field periodically. ![[Pasted image 20250207041537.png]]