Kubernetes- Workload
Table of contents
Deployment
This is a manifest file in YAML format that enhances the containers inside the pod, similar to how Tony Stark is empowered by the Iron Man suit. It includes features like replicas, rolling updates, autoscaling, and auto-healing.
Replicas - Specifies how many pods need to be created.
Rolling update – Updates occur one container at a time within the pod. For example, if I update a container's image, not all containers will be updated simultaneously; instead, they will be updated one by one. This prevents downtime and keeps the application running during updates.
Autoscaling - Increases the number of containers if needed.
Autohealing - Restarts or creates a new container if one stops working.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment # name of deployment
namespace: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-cont
image: nginx:latest
ports:
- containerPort: 80
ReplicaSets
Similar to Deployments, which help replicate pods, ReplicaSets work on the same principle but lack the additional features of Deployments, like rolling updates.
Thus, there isn't a significant difference in the manifest file, except for the kind and some other details.
kind: ReplicaSet
apiVersion: apps/v1
metadata:
name: nginx-replica-sets
namespace: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx-rep-pod
template:
metadata:
labels:
app: nginx-rep-pod
spec:
containers:
- name: nginx-cont
image: nginx:latest
ports:
- containerPort: 80
DaemonSet
A DaemonSet is like a Deployment in managing workloads, but the main difference is that a DaemonSet makes sure at least one pod runs on every worker node in the cluster without exception. The manifest file is mostly the same, except for the type of resource. For example, in a DaemonSet manifest file, you won't see a replicas field for the pods.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-daemonset
namespace: nginx
spec:
selector:
matchLabels:
app: nginx-daemon-pod
template:
metadata:
labels:
app: nginx-daemon-pod
spec:
containers:
- name: nginx-cont
image: nginx:latest
ports:
- containerPort: 80
In conclusion, this document gave an overview of Deployments, ReplicaSets, and DaemonSets, along with their YAML manifest files. It highlighted their roles, features, and key differences in managing workloads in Kubernetes.