Kubeweek Day-3 :

Kubeweek Day-3 :

Stateful sets:

StatefulSets are a type of workload in Kubernetes that are used to manage stateful applications, such as databases or other stateful services. They provide guarantees around ordering and uniqueness of Pods, as well as stable network identities and persistent storage.

Unlike Deployments or ReplicationControllers, which are used for stateless applications, StatefulSets are designed to manage stateful applications that require unique network identities, stable hostnames, and persistent storage. This is important for applications like databases, where data must be stored persistently and reliably.

Example- MYSQL, Elasticsearch,MongoDB which have their own database, that store data to keep track.

It deploy not with deploymet.yml file but with Stateful sets

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-statefulset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-image:latest

Jobs:

In Kubernetes, a Job is a workload that is used to run a specific task to completion, such as a batch job or a data processing task. Jobs are useful for running one-off or periodic tasks in a cluster.

A Job creates one or more Pods and ensures that they complete their tasks successfully before terminating. If a Pod fails or is terminated, the Job automatically creates a new Pod to replace it. Jobs can be run once or scheduled to run periodically using a CronJob.

here are some benefits of using Jobs in Kubernetes:

  • Ability to run one-off or periodic tasks in the cluster

  • Ensures that the task completes successfully before terminating

  • Automatically creates a new Pod if a Pod fails or is terminated

  • Supports parallelism by allowing multiple Pods to be created to run the same task simultaneously

  • Can be used with CronJobs to schedule tasks to run at specific times or intervals

  • Supports retries by allowing you to specify a backoff limit and retry interval for failed tasks

  • Provides easy management and scaling of jobs through Kubernetes' built-in APIs and tools

apiVersion: batch/v1
kind: Job
metadata:
  name: my-job
spec:
  template:
    spec:
      containers:
      - name: my-container
        image: my-image:latest
        command: ["my-command"]

CronJobs:

n Kubernetes, a CronJob is a type of workload that is used to schedule tasks to run at specific times or intervals. CronJobs are useful for running periodic tasks, such as backups, data processing, or data retrieval tasks.

CronJobs work by creating Jobs based on a Cron-like syntax, which specifies the schedule for running the task. The Cron syntax consists of five fields: minute, hour, day of month, month, and day of week. You can use wildcards, ranges, and lists to specify multiple values for each field.

When a CronJob is created, Kubernetes creates a Job based on the schedule specified in the CronJob. The Job runs a container with the specified command and image, and the task is executed according to the schedule.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: my-cronjob
spec:
  schedule: "0 0 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: my-container
            image: my-image:latest
            command: ["my-command"]