Day 32: Initiating the Deployment of Your Kubernetes Cluster❄

Day 32: Initiating the Deployment of Your Kubernetes Cluster❄

Day#32 Of 90 Days Of DevOps

💥Introduction

Congratulations are in order as we stand at the culmination of an impressive 31-day learning journey with Kubernetes (K8s).

We've undoubtedly garnered a comprehensive grasp of the pivotal components constituting the Kubernetes ecosystem.

Today marks a significant juncture as we delve into the intricacies of Deployments in Kubernetes.

This discussion will unravel the pivotal role Deployments play in orchestrating applications, their features that foster seamless management, and a hands-on tutorial to reinforce your comprehension.

🌟Understanding Deployments in Kubernetes

At its essence, a Deployment in Kubernetes functions as a strategic conduit for overseeing the deployment, scalability, and updates of application instances.

It acts as a blueprint for maintaining the desired state of Pods and ReplicaSets housing your application containers.

This desired state encompasses scaling operations, update management, and guaranteeing unswerving high availability.

Bypassing the necessity of manual management of individual Pods or ReplicaSets, a Deployment introduces abstraction. This empowers you to channel your energies into refining application logic and defining the desired operational state. The linchpin of this process is the Deployment Controller, a foundational element of Kubernetes. This controller ensures alignment between the current operational state of your application and the envisioned state detailed within the Deployment manifesto.

Prime facets characterizing Deployments include:

  1. Declarative Evolution: Deployments enable you to articulate the preferred operational state of your application. The system then orchestrates the transition from the existing state to the stipulated state. This underpins predictability and consistency during updates.

  2. Rolling Iterations: With Deployments, transitioning from one version of your application to another employs a gradual, rolling methodology. This minimizes downtime and forestalls the risks accompanying sudden transformations.

  3. Scalability On-Demand: Adapting the count of replicas (instances) for your application is a seamless endeavor. Tweaking the Deployment manifest facilitates the smooth handling of fluctuating traffic volumes and workloads.

  4. Automated Restoration: Should a Pod falter, the Deployment Controller springs into action, promptly replacing the ailing Pod with a fresh counterpart. This sustains the stipulated replica count, sustaining the robustness of operations.

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

In this task, we will walk through the process of creating a Kubernetes Deployment for todo-app, leveraging the auto-healing and auto-scaling features.

First, the todo-app Docker image will be pushed to Docker Hub before deploying it to the Kubernetes cluster.

Prerequisites:

  • Docker Hub account

  • Docker image of the todo-app built and tagged

Step 1: Push the Docker Image to Docker Hub

Before deploying the Kubernetes Deployment, ensure that you have built the Docker image of the todo-app and pushed it to Docker Hub. This ensures that the Kubernetes cluster can access the image when creating the pods.

docker login   # Log in to your Docker Hub account
docker push vishalphadnis/todo-app

Step 2: Create a Deployment YAML File

Create a new YAML file named deployment.yml and add the following content to it. This YAML file defines the Deployment with auto-healing and auto-scaling features.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-app-deployment
spec:
  replicas: 3  # Initial number of replicas
  selector:
    matchLabels:
      app: todo-app
  template:
    metadata:
      labels:
        app: todo-app
    spec:
      containers:
        - name: todo-app
          image: vishalphadnis/todo-app
          ports:
            - containerPort: 8000

Explanation of deployment.yml

  • apiVersion: Specifies the Kubernetes API version to use.

  • kind: Defines the resource type as a Deployment.

  • metadata: Contains metadata about the Deployment, including its name.

  • spec.replicas: Specifies the desired number of replicas (pods) to maintain. This is the basis for auto-scaling.

  • spec.Selector: Defines how the Deployment selects which pods to manage based on labels.

  • spec.template: Specifies the pod template to be used for creating new pods.

  • spec.template.metadata.labels: Labels to be applied to the pods.

  • spec.template.spec.containers: Defines the containers within the pod, including the image and ports.

Step 3: Apply the Deployment to Kubernetes

Save the deployment.yml file and apply the Deployment to your Kubernetes cluster using the following command:

kubectl apply -f deployment.yml

Step 4: Testing Auto-Healing

To validate the functionality of the auto-healing feature, deliberately remove one of the pods.

Subsequently, Kubernetes will autonomously generate a new pod to substitute the removed instance.

kubectl delete pod <pod_name>

Step 5: On the worker node, verify whether the docker container working or not

docker ps
sudo docker exec -it <docker-container> bash #Get into the docker container
curl -L http://127.0.0.1:8000

Step 6: Delete the Deployment

If you need to remove the entire Deployment and its associated pods, use the following command:

kubectl delete -f deployment.yml

By following these steps, you've successfully created a Kubernetes Deployment for a sample todo-app with auto-healing and auto-scaling features. The Docker image was pushed to Docker Hub, allowing Kubernetes to fetch it during the deployment process.

✨Conclusion

This discourse explored Kubernetes Deployments comprehensively. It covered application management, declarative evolution, updates, scalability, and recovery. By deploying a prototype todo-app with auto-healing and scaling, you gained practical Kubernetes mastery.

Remember, hands-on practice and experimentation are vital for a holistic grasp of Kubernetes. Keep exploring various scenarios to enhance your command of this landscape. This knowledge empowers you to seamlessly manage applications and bolster resilience in Kubernetes.

Best of luck in your deployment journey!👍✌

🚀 Stay tuned for more insightful Kubernetes blogs in the days ahead! 🎉

Thank you for joining us on this exciting Day 32 of the 90 Days of DevOps challenge. I hope you found the information helpful and insightful.

So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on :

Hashnode: vishaltoyou.hashcode.dev

LinkedIn: linkedin.com/in/vishalphadnis