☑️Day 36: Understanding Regenerate Strategy, Resource Requests, and Resource Limits in Kubernetes🚀

☑️Day 36: Understanding Regenerate Strategy, Resource Requests, and Resource Limits in Kubernetes🚀

🔹Table of Contents :

  • Introduction

  • Regenerate Strategy in Kubernetes

  • Resource Requests in Kubernetes

  • Resource Limits in Kubernetes

  • Real-World Scenario

  • Summary


✅1. Regenerate Strategy in Kubernetes

What is Regenerate Strategy?

  • The Regenerate Strategy is part of the update strategy for a Deployment or StatefulSet. It defines how Kubernetes regenerates Pods during a deployment, update, or upgrade. There are mainly two strategies:

    • Rolling Update: Gradually replaces old Pods with new ones without downtime.

    • Recreate: Deletes all the existing Pods and recreates them from scratch. This may cause downtime but ensures a complete restart.

Example Use Case:

  • If you're updating a web application and want zero downtime, you can use Rolling Update. But for stateful applications like databases, sometimes a full Recreate strategy is needed to ensure proper restart and initialization.

Example YAML for Rolling Update:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx-deployment
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest

Example YAML for Recreate:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-app
spec:
  replicas: 3
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web-app
        image: web-app:1.0

Commands:

  • Deploy your YAML configuration.

      kubectl apply -f <deployment-file>.yaml
    
  • Check the status of the update.

      kubectl rollout status deployment <deployment-name>
    

✅2. Resource Requests in Kubernetes

What is Resource Request?

  • Resource Request specifies the minimum amount of CPU and memory that a container requires to run. Kubernetes uses this value to schedule the Pod on a Node that has at least this much capacity available.

Example Use Case:

  • If you're running a microservice that requires at least 100m of CPU (10% of a CPU core) and 200Mi of memory, you can specify these as resource requests. This ensures that the Pod will always have enough resources to operate, avoiding performance issues.

Example YAML for Resource Requests:

apiVersion: v1
kind: Pod
metadata:
  name: resource-pod
spec:
  containers:
  - name: app-container
    image: nginx:latest
    resources:
      requests:
        memory: "200Mi"
        cpu: "100m"

Commands:

  • Check resource requests and limits of a running pod.

      kubectl describe pod <pod-name>
    

✅3. Resource Limits in Kubernetes

What is Resource Limit?

  • Resource Limits define the maximum amount of CPU and memory that a container can use. If the container tries to exceed this limit, Kubernetes will either throttle the CPU or terminate the Pod if it exceeds the memory limit.

Example Use Case:

  • If you’re running a containerized application in a shared cluster, you want to make sure it doesn’t consume too many resources and affect other applications. By setting a resource limit, you cap the resources any Pod can use.

Example YAML for Resource Limits:

apiVersion: v1
kind: Pod
metadata:
  name: limit-pod
spec:
  containers:
  - name: app-container
    image: nginx:latest
    resources:
      limits:
        memory: "500Mi"
        cpu: "500m"

Commands:

  • View the detailed YAML including resource requests and limits.

      kubectl get pod <pod-name> -o yaml
    

✅Real-World Scenario

Imagine you're running a production-grade e-commerce application with multiple services like a web frontend, payment gateway, and order management system.

  • Regenerate Strategy: You use a Rolling Update strategy to update your web frontend to the latest version without causing any downtime for users.

  • Resource Requests: You allocate specific CPU and memory resources to the payment gateway to ensure that it always has enough capacity to handle peak loads.

  • Resource Limits: You set a resource limit on the order management system so that during high traffic, it doesn't overuse resources and slow down other critical services.


✅Summary

  • Regenerate Strategy: Defines how Pods are updated during a deployment (Rolling Update vs. Recreate).

  • Resource Requests: The minimum CPU and memory a container needs to run.

  • Resource Limits: The maximum CPU and memory a container can use.

By setting the right resource requests and limits, you can ensure optimal resource utilization, prevent performance issues, and keep your Kubernetes cluster running smoothly.


✅Final Commands Overview:

  • Apply YAML configurations.

      kubectl apply -f <file>.yaml
    
  • View Pod information.

      kubectl get pod <pod-name>
    
  • Check detailed Pod resource details.

      kubectl describe pod <pod-name>
    
  • Monitor deployment updates.

      kubectl rollout status
    

🚀Thanks for joining me on Day 36! Let’s keep learning and growing together!

Happy Learning! 😊

#90DaysOfDevOps

💡
Follow for more updates on LinkedIn , Github and Twitter(X)