Kubernetes Workloads (Deployments, Jobs, CronJobs, etc.)
Table of contents
Kubernetes Workloads
A Kubernetes Workloads is an application running in one or more Kubernetes (K8s) pods. Kubernetes Workloads refer to the different types of applications and services that can be deployed and managed on a Kubernetes cluster. Kubernetes Workloads provide a way to describe the desired state of an application or service, including the number of replicas, networking rules, resource requirements, and more.
Some common types of Kubernetes Workloads include Deployments, StatefulSets, DaemonSets, Jobs and CronJobs.
Deployments
Deployments manage the lifecycle of a set of replicated pods.
Deployments ensure that the desired number of replicas of a pod are running and can automatically handle scaling, rolling updates, and rollbacks.
Deployments are defined using a declarative YAML or JSON manifest that specifies the desired state of the deployment.
Deployments use ReplicaSets under the hood to ensure that the desired number of replicas are running.
A Deployment defines a desired state for a ReplicaSet and creates or updates the ReplicaSet accordingly.
Use Cases
Web servers that serve HTTP requests
Microservices that communicate with other services over a network
Stateless databases that store data in external storage systems
Here are the steps to deploy a Deployment in a Kubernetes cluster
- Create a namespace and then create a deployment.yml file
- Apply deployment.yml file by using
kubectl apply -f deployment.yml
command
- Check the running by pods by
kubectl get pods -A
command Orkubectl get pods -n=namespace_name
command
StatefulSets
StatefulSets manage the lifecycle of a set of stateful pods.
StatefulSets provide unique identities for each pod and ensure that pods are started and stopped in a consistent order.
StatefulSets are useful for stateful applications such as databases that require stable network identities and persistent storage.
StatefulSets use a Headless Service to provide stable network identities for each pod.
A StatefulSet guarantees that each pod in the set is created and started in a certain order.
Use Cases
Databases that require persistent storage and stable network identities
Distributed systems that require unique network identities for each node
Applications that require ordered startup and shutdown.
Here are the steps to deploy a Deployment in a Kubernetes cluster
- Create a
statefulset.yaml
file
Apply
statefulset.yaml
file by usingkubectl apply -f statefulset.yaml
commandCheck the status
DaemonSets
DaemonSets manage the lifecycle of a set of pods that run on every node in a Kubernetes cluster.
DaemonSets are useful for system daemons or other processes that need to run on every node in a cluster.
DaemonSets are defined using a declarative YAML or JSON manifest that specifies the desired state of the DaemonSet.
DaemonSets can be used for cluster-wide logging, monitoring, or other system-level tasks.
Use Cases
Logging agents that collect logs from all nodes in a cluster
Monitoring agents that collect metrics from all nodes in a cluster
Security agents that enforce security policies on all nodes in a cluster
Here are the steps to deploy a DaemonSet in a Kubernetes cluster
- Create a
daemonset.yaml
file
Apply daemonset.yaml file by using
kubectl apply -f daemonset.yaml
commandCheck created ds by using
kubectl get ds
command and check created pods
- Create one more node and see this pods is running on new node automatically, thats how daemonset works
Jobs
Jobs run a batch process to completion, such as running a one-time task or running a task on a schedule.
Jobs create one or more pods to run the task and ensure that the task is completed successfully.
Jobs are defined using a declarative YAML or JSON manifest that specifies the desired state of the job.
Jobs can be used for tasks such as batch processing, data migration, or backups.
Use Cases
Data processing tasks that run periodically
Backup tasks that run periodically
Indexing tasks that run periodically
Here are the steps to deploy a jobs in a Kubernetes cluster
- Create a
jobs.yaml
file
Apply
jobs.yaml
file by usingkubectl apply -f jobs.yaml
commandCheck the status
CronJobs
CronJobs run a batch process on a schedule, similar to a cron job in Linux.
CronJobs create one or more pods to run the task on a schedule and ensure that the task is completed successfully.
CronJobs are defined using a declarative YAML or JSON manifest that specifies the desired state of the CronJob.
CronJobs can be used for tasks such as scheduled backups, data processing, or log rotation.
Use Cases
Scheduled backups of databases or storage systems
Periodic data processing tasks
Log rotation tasks that run periodically
Here are the steps to deploy a cronjob in a Kubernetes cluster
- Create a
cronjobs.yaml
file
Apply
cronjobs.yaml
file by usingkubectl apply -f cronjobs.yaml
commandCheck the scheduled task is running every minute
Thank you for reading!!
Irfan