Day 32 : Launching Kubernetes Cluster with Deployment

Day 32 : Launching Kubernetes Cluster with Deployment

·

3 min read

What is Deployment in k8s

A Deployment in Kubernetes is a resource that manages the creation and updates of ReplicaSets. A Deployment provides a declarative definition of the desired state of your application, and the Deployment Controller works to ensure that the actual state of your application matches the desired state.

Deployments can be used to:

  • Deploy new applications.

  • Update existing applications.

  • Scale applications up or down.

  • Rollback to previous versions of applications.

Deployments are a powerful tool for managing Kubernetes applications, and they are one of the most commonly used resources in Kubernetes.

Here is a brief overview of how Deployments work:

  1. You create a Deployment object that defines the desired state of your application. This includes the number of replicas to create, the image to use, and any other relevant configuration.

  2. The Deployment Controller creates a new ReplicaSet with the desired configuration.

  3. The ReplicaSet creates the desired number of Pods.

  4. The Deployment Controller monitors the Pods and ensures that the desired number of Pods are running and healthy.

  5. If you update the Deployment object, the Deployment Controller creates a new ReplicaSet with the updated configuration.

  6. The Deployment Controller gradually scales down the old ReplicaSet and scales up the new ReplicaSet.

  7. Once the new ReplicaSet is fully scaled up, the Deployment Controller deletes the old ReplicaSet.

This process ensures that your application is always available and that updates are rolled out in a controlled manner.


Tasks

Create one Deployment file to deploy a sample todo-app on K8s using "Auto-healing" and "Auto-Scaling" feature

We will create this on minikube which we installed in the last blog on our instance.

Now we will create a sample Deployment file that deploys a sample nginx on our Kubernetes cluster.

A sample deployment file :

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

Note : Whenever doing or writing a piece of code rather than copy paste try to write it yourself and make mistakes. This will make you remember things more.

A YAML file is the same one that we studied and used in docker-compose.
(Human readable data serialization language)

In Kubernetes terminology, these files are called manifest files. And are used to perform almost all tasks like creating pods, creating deployments, creating services, creating volumes, etc.

Now we need to apply the deployment file using the command :
kubectl apply -f deployment.yaml

Now to check this let's enter the pod and see if the desired numbers of replicas has been created.

Here, even if we delete a pod another pod will be created at the same moment, which we term as auto healing.

We will get into auto-scaling in more detail in our upcoming blogs.
Also, stay tuned for another blog which includes assignments such as deployment of Microservices Deployment on k8s and the Deployment of the Reddit Clone application.

Thank you for following until here. See you in the next one.