Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

kubernetes-session-5--Daemonset-statefulset

 Ref: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/

Deployment: Suitable software regular applications

Daemonset: suitable for apps which must run a pod in everynode presernt in k8 cluster ex: logs & monitoring

Staatefullset: suitable for database applications such as mysql and elasticsearch it has ordinal sequential index like 0,1,2.. in case of pod delete or re created it will have same name where as in deployment and statefulset the name will change for pod whenever the it will update the pod name will change 

A Deamonset is a Kubernetes resource that ensures that a copy of a specific pod runs on each node in a cluster. Unlike a Deployment, which ensures a specified number of replicas running across the entire cluster, a Deamonset runs exactly one instance of a pod on each node. This makes Deamonset suitable for tasks that need to run on every node, such as log collection, monitoring agents, or network-related tasks.


Here are some key characteristics and use cases for DaemonSets:


One Pod Per Node: The primary purpose of a DaemonSet is to run a single instance of a pod on each node in the cluster. As nodes are added or removed, the DaemonSet automatically adjusts to maintain the desired state.


Infrastructure Tasks: DaemonSets are commonly used for running infrastructure-related tasks on each node, such as log collection agents (e.g., Fluentd or Filebeat), monitoring agents (e.g., Prometheus Node Exporter), or network-related components (e.g., CNI plugins).


Node-Level Operations: Some applications or services need to perform node-specific operations. DaemonSets are well-suited for such scenarios, as they ensure that each node has an instance of the pod running.


Kubelet-Level Operations: If you need to perform operations at the Kubelet level (the component on each node responsible for managing containers), a DaemonSet can be used to deploy a pod that interacts with the Kubelet directly.

Daemon set it will ensure the pod will run per node always event you drain traffic to node while performing patching activities where as deployment if you delete pod it will delete it

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nginx-daemonset
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

when we delete the pod is part of daemonset it recreated again in same node.



-----------------------------------------statefulset-------------------------------------------------------
A StatefulSet is another type of controller in Kubernetes, designed for managing stateful applications. Unlike a Deployment or DaemonSet, which are suitable for stateless applications, a StatefulSet maintains a stable network identity and persistent storage for each pod it manages. This makes StatefulSets particularly useful for applications that require unique network identities, stable hostnames, or persistent storage, such as databases.

Here are some key characteristics and use cases for StatefulSets:

Stable Hostnames: StatefulSets assign stable and unique hostnames to each pod they manage. This allows for predictable DNS names and network identities, making it easier to reference and communicate with individual instances.

Ordered Deployment and Scaling: Pods in a StatefulSet are deployed and scaled in a predictable order. Each pod has a unique ordinal index, and scaling operations occur in a sequential manner. This is important for applications that rely on a specific order during startup or shutdown.

Persistent Storage: StatefulSets can manage stateful applications that require persistent storage. Each pod in a StatefulSet can be associated with a Persistent Volume (PV), providing data persistence even if the pod is rescheduled to a different node.

Headless Service: StatefulSets automatically create a Headless Service to enable network identity and DNS for individual pods. This allows applications to discover and connect to each other using their stable hostnames.

Here's a simple example of a StatefulSet managing a stateful application, such as a web server with persistent storage:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web-statefulset
spec:
  serviceName: "web"
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web-container
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: web-storage
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: web-storage
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: "standard"
      resources:
        requests:
          storage: 1Gi






Post a Comment

0 Comments

Ad Code

Responsive Advertisement