Day 08/40 Days of K8s: Understanding Deployment, RPS, and Replication Controllers
While pods run containers, the real power of Kubernetes lies in features like self-healing and High availability.These are achieved using Deployments.
Pod: Abstraction of containers
Deployment: Abstraction of pods
In real-world scenarios, we typically create Deployments rather than individual pods.
Challenges with pod?🤔
1. High Load: How does a pod handle numerous requests?
2. Pod Crashes: What happens when a pod fails (given the ephemeral nature of containers)?
Solution: SELF-HEALING, HIGH AVAILABILITY🛠️🚀
Replication Controller and ReplicaSet
Replication Controller and ReplicaSet are used to maintain pod availability at any given time. The Replication Controller, a legacy object implements control loop mechanism, ensures a specified number of pod replicas are always running, creating new identical pods before existing ones terminate.
ReplicaSet, a latest version not only manages pods across nodes but can also create new nodes if existing ones lack resources. Both compare the desired and actual state of the cluster, with ReplicaSet offering enhanced pod selection capabilities.
ReplicaSet vs Replication Controller
Replication Controller: Only manages pods created as part of that replication controller
ReplicaSet: Can manage existing pods not originally part of the ReplicaSet using selectors and match labels.
Deployment
Additional functionality to ReplicaSet, all the version upgrades rollout to pods at the same time which intern causes downtime. Deployment does the rollout a version in a rolling update fashion. In case of issues with the new version rollout we can still rollback to previous version with deployment.
Remember: Deployments manage ReplicaSets, which in turn manage pods.
Let's get into Hands on......
1️⃣ TASK: 1
✅ Create a new Replicaset based on the nginx image with 3 replicas
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-replicaset
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
- ✅ Update the replicas to 4 from the YAML
- ✅ Update the replicas to 6 from the command line
2️⃣ TASK 2
- ✅ Create a Deployment named
nginx
with 3 replicas. The Pods should use thenginx:1.23.0
image and the namenginx
. The Deployment uses the labeltier=backend
. The Pod template should use the labelapp=v1
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
tier: backend
spec:
replicas: 3
selector:
matchLabels:
app: v1
template:
metadata:
labels:
app: v1
spec:
containers:
- name: nginx
image: nginx:1.23.0
ports:
- containerPort: 80
- ✅ List the Deployment and ensure the correct number of replicas is running.
- ✅ Update the image to
nginx:1.23.4
- ✅ Verify that the change has been rolled out to all replicas.
- ✅ Assign the change cause "Pick up patch version" to the revision
kubectl annotate deployment/nginx kubernetes.io/change-cause="Pick up patch version"
deployment.apps/nginx annotated
- ✅ Scale the Deployment to 5 replicas, Have a look at the Deployment rollout history.
kubectl scale deploy/nginx --replicas=5
deployment.apps/nginx scaled
kubectl rollout history deploy/nginx
deployment.apps/nginx
REVISION CHANGE-CAUSE
1 <none>
2 Pick up patch version
- ✅ Revert the Deployment to revision 1.
kubectl rollout undo deploy/nginx
deployment.apps/nginx rolled back
✅ Ensure that the Pods use the image
nginx:1.23.0
#Kubernetes #ReplicaSet #ReplicationController #Deployment #Yaml #40DaysofKubernetes #CKASeries
Subscribe to my newsletter
Read articles from Gopi Vivek Manne directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gopi Vivek Manne
Gopi Vivek Manne
I'm Gopi Vivek Manne, a passionate DevOps Cloud Engineer with a strong focus on AWS cloud migrations. I have expertise in a range of technologies, including AWS, Linux, Jenkins, Bitbucket, GitHub Actions, Terraform, Docker, Kubernetes, Ansible, SonarQube, JUnit, AppScan, Prometheus, Grafana, Zabbix, and container orchestration. I'm constantly learning and exploring new ways to optimize and automate workflows, and I enjoy sharing my experiences and knowledge with others in the tech community. Follow me for insights, tips, and best practices on all things DevOps and cloud engineering!