KubeVerse : Week-1.0 | Understanding Pods, Deployments, ReplicaSets
KubeVerse: Sailing Smoothly in the Sea of Containers
Introduction
Kubernetes, an open-source container orchestration platform, serves as a powerful tool for the management and scaling of containerized applications. At the core of Kubernetes architecture, we find "Pods," which act as fundamental components, each representing a singular running process within the cluster. In this blog post, we'll delve into essential Kubernetes concepts, namely Deployments, ReplicaSets, and Auto Healing for Pods. Furthermore, we'll accompany our exploration with practical code snippets to illustrate these concepts in action.
Pods
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
A Pod is like a group of containers that work together as a team. They share storage and network resources and follow a set of rules for how they should run. Think of a Pod as a single home for these containers, where they always stay together and operate in sync. It's like a special place where different parts of an application live and work closely together. In simpler terms, if you imagine applications running on the same computer, a Pod is like that computer for cloud-based applications.
Example:
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
In the above example, we can see that a pod named nginx is been created which has the image nginx:1.14.2
.
To run this pod save the above yaml code and enter the following command:
kubectl apply -f ./<name_of_the_file>.yaml
To check the status of the pod you can runkubectl get pods -n default
Replicaset
A ReplicaSet is like a guardian in Kubernetes. Its job is to make sure that there are always a certain number of identical copies of a Pod running. It's a way to ensure that you have the right amount of the same thing working at all times. This helps guarantee that your applications stay available and don't go offline unexpectedly.
Example:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# modify replicas according to your case
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
Here in this example, we can see that a pod named frontend is created which has three replicas.
Deployments
A Deployment provides declarative updates for Pods and ReplicaSets.
In a Deployment, you basically tell Kubernetes how you want things to be. The Deployment Controller then takes charge of making sure that your desired setup becomes a reality, but it does so in a careful and controlled manner. You can use Deployments to do a couple of things: create new groups of identical Pods, or replace existing ones with new sets while making sure everything transitions smoothly. It's all about maintaining control over the state of your applications.
Example
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.14.2
ports:
- containerPort: 80
The above code is an example of a Deployment in Kubernetes with name nginx-deployment
and image: nginx:1.14.2
.
Conclusion
In this blog post, we delved into the fundamental concepts of Kubernetes, focusing on Pods, Deployments, and ReplicaSets. Pods were introduced as the essential building blocks, and we learned how Deployments, ReplicaSets, and Pods work together to maintain the desired state of containerized applications.
Kubernetes offers a robust platform for orchestrating containers, allowing for effortless scaling, updating, and managing of containerized applications. By comprehending and harnessing the concepts discussed in this blog post, including Deployments, ReplicaSets, and Pods, you can efficiently deploy and manage your applications in your Kubernetes cluster, ensuring they run smoothly and reliably.
Resources:
@KodeKloud - Tutorial for Kubernetes for beginners