Day-36: Understanding Deployment and Kubernetes Resource Requests and Resource Limits in DevOps

Greetings! 👋 I'm Priyadarshi Ranjan, a dedicated DevOps Engineer embarking on an enriching journey. Join me as I delve into the dynamic realms of cloud computing and DevOps through insightful blogs and updates. 🛠️ My focus? Harnessing AWS services, optimizing CI/CD pipelines, and mastering infrastructure as code. Whether you're peers, interns, or curious learners, let's thrive together in the vibrant DevOps ecosystem. 🌐 Connect with me for engaging discussions, shared insights, and mutual growth opportunities. Let's embrace the learning curve and excel in the dynamic realm of AWS and DevOps technology!
What is Deployment?
Deployment in DevOps refers to the process of delivering software applications, updates, or services to the end-users or production environment. It’s the final stage in the software development lifecycle where the code is transferred from a development or testing environment to live production.
Components of Deployment:
Source Code Repository: Where the code resides, like GitHub or GitLab.
CI/CD Pipeline: Automates the building, testing, and deployment of code.
Containers: Packaging the application and its dependencies into a container (e.g., Docker).
Orchestration Tools: Tools like Kubernetes manage and automate the deployment of containers.
Monitoring & Logging: Tools that track performance and issues post-deployment.
Load Balancer: Distributes incoming network traffic across multiple servers to ensure reliability.
Function of Deployment:
Automating Processes: Reduces manual errors by automating the steps involved in deploying software.
Scaling Applications: Ensures applications can handle increased load by automatically scaling resources.
Versioning: Helps in managing different versions of software in production.
Rollback: Provides the ability to revert to a previous stable version in case of issues.
Benefits of Deployment:
Faster Time to Market: Automated deployment speeds up the release process.
Consistency: Ensures consistent environments through automation.
Reduced Risk: Automated testing and validation reduce the risk of errors.
Scalability: Easily scale applications based on demand.
Continuous Feedback: Monitoring tools provide feedback on application performance.
Manifest File for Simple Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 4
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: my1st-deplyment
image: nginx:latest
ports:
- containerPort: 80
Rolling Out Features
What is Rolling Out a Feature?
Rolling out a feature means gradually deploying a new feature to a subset of users before making it available to everyone. This approach allows developers to monitor the feature's impact and address any issues before a full release.
Why Use Rolling Out in Deployment?
Controlled Release: Gradually introduce new features to avoid widespread issues.
A/B Testing: Test new features with a specific group of users to gauge effectiveness.
Feedback Gathering: Collect user feedback before a broader release.
Risk Mitigation: Identify and resolve issues in a smaller environment.
Manifest File for Feature Rollout:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hotstar
labels:
app: ipl
annotations:
kubernetes.io/change-cause: "version1"
spec:
replicas: 8
minReadySeconds: 20
strategy:
rollingUpdate:
maxSurge: 2
maxUnavailable: 0
type: RollingUpdate
selector:
matchLabels:
app: ipl
template:
metadata:
labels:
app: ipl
spec:
containers:
- name: sports
image: docker9447/apache:v1
ports:
- containerPort: 80
Comparing v1 to v2:
v1 Deployment:
Stable version running across multiple replicas.
Minimal risk but no new features.
v2 Deployment:
New feature version deployed to a single replica for testing.
High monitoring focus to catch any issues.
Recreate Strategy
What is Recreate Strategy?
The recreate strategy in Kubernetes deployment is when all existing pods are terminated before new ones are created. This ensures that no old version pods run alongside new ones during the deployment.
Components of Recreate Strategy:
Termination of Old Pods: Old pods are terminated before new ones start.
Sequential Deployment: New pods are only created after old pods are completely terminated.
Downtime: There may be a brief downtime during the transition.
Manifest File for Recreate Strategy:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hotstar
labels:
app: ipl
annotations:
kubernetes.io/change-cause: "version1"
spec:
replicas: 9
minReadySeconds: 20
strategy:
type: Recreate
selector:
matchLabels:
app: ipl
template:
metadata:
labels:
app: ipl
spec:
containers:
- name: sports
image: nginx:1.23
ports:
- containerPort: 80
Kubernetes Resource Requests and Resource Limits

What is a Resource Request?
A resource request is the amount of CPU and memory that a container is guaranteed to have. Kubernetes uses these requests to schedule pods on nodes that have sufficient resources.
What is a Resource Limit?
A resource limit is the maximum amount of CPU and memory a container can use. If the container exceeds this limit, it may be throttled or killed.

Example Manifest for Resource Requests and Limits:
apiVersion: v1
kind: Pod
metadata:
name: pod1
labels: # Corrected indentation and spelling from "lables" to "labels"
env: prod
spec:
containers:
- name: my1stcontainer
image: nginx:latest # Corrected the image tag from "lates" to "latest"
resources: # Corrected spelling from "resourses" to "resources"
requests:
memory: "250Mi" # Corrected from "250mi" to "250Mi" (case-sensitive)
cpu: "250m"
limits:
memory: "500Mi" # Added resource limits
cpu: "500m"
Commands to Run Manifest Files and Comparison
Running the Manifest Files:
Apply a manifest file:
kubectl apply -f deployment.yamlCheck the deployment status:
kubectl get deploymentsView pod details:
kubectl get podsCompare different versions:
kubectl rollout status deployment/my-app-deployment kubectl describe deployment my-app-deployment
Conclusion
Deployment is a critical aspect of DevOps that ensures your application is available to users. Whether using rolling updates, recreate strategy, or managing resources, each method has its use case. By understanding these strategies and tools, you can deploy applications more effectively and efficiently, ensuring they meet user needs while minimizing risks.
Connect and Follow Me on Socials




