Kubernetes Deployments

Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
Search for a command to run...

Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
No comments yet. Be the first to comment.
1. Difference between Docker and Kubernetes Docker → Builds and runs containers.Kubernetes → Orchestrates containers across multiple nodes. Key points: Docker = container runtime. Kubernetes = container orchestration tool. Kubernetes provides auto...
In this session, we learn how to monitor a Kubernetes cluster using Prometheus and Grafana.This is not just theory — there is a GitHub repository containing all installation commands and demo steps.The repo will also be enhanced later with advanced K...
1. What is a ConfigMap in Kubernetes? A ConfigMap is used to store non-sensitive configuration data that your application needs — such as: Database port Connection type Any general configuration values In normal applications (non-Kubernetes), de...
Kubernetes normally supports built-in resources like: Deployment Service Pod ConfigMap Secret Ingress These are called native resources. Sometimes companies (Istio, ArgoCD, Prometheus Operator, Kyverno, etc.) want to add new features that Kub...
1. Why Kubernetes Services Are Needed When a Pod is created in Kubernetes, it receives a dynamic IP address.If the Pod dies and restarts, its IP changes.So other Pods (like checkout → payments) cannot rely on Pod IP because it changes, creating issue...
A Kubernetes Deployment is a crucial resource object that provides a declarative approach to managing application updates, rollbacks, and scaling. Deployments allow you to define an application's lifecycle, ensuring your desired state is always maintained by controlling the creation and replacement of Pods.
Step 1: Creating Your First Deployment
Let’s begin by setting up a simple Deployment that runs an Nginx web server.
First, create a YAML file named deployment.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.17
ports:
- containerPort: 80

To create the Deployment, run:
kubectl apply -f deployment.yaml

Once applied, you can verify the status of your Deployment, ReplicaSets, and Pods:
kubectl get deploy
kubectl get rs
kubectl get pod



To check the current Nginx version running in a specific Pod, use:
kubectl describe pod <podname>

Step 2 : Updating the Deployment
With your Deployment up and running, let's update the Nginx version from nginx:1.17 to nginx:1.18.
Open the deployment.yaml file and update the Nginx image tag:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.18
ports:
- containerPort: 80

Apply the updated Deployment:
kubectl apply -f deployment.yaml

Verify the updated Deployment and Pods:
kubectl get deploy
kubectl get pod


To confirm the Nginx version has been updated:
kubectl describe pod <podname>

Step 3 : Rolling Back the Deployment
Kubernetes makes it easy to roll back to a previous version of your Deployment.
Identify the ReplicaSet associated with the version you want to roll back to:
kubectl get rs

To roll back to the previous version:
kubectl rollout undo deployment/my-deployment

Verify the rollback by checking the ReplicaSets and Pods:
kubectl get rs
kubectl get pod


Check the Nginx version to ensure the rollback was successful:
kubectl describe pod <podname>
Now, Check the nginx version,

Step 4 : Clean up
Once you're done, you can clean up the resources:
kubectl delete deploy nginx-deployment

Kubernetes Deployments provide a powerful way to manage the lifecycle of your applications. With the ability to easily update, roll back, and scale your applications, Deployments are an essential tool for any Kubernetes user