Launching your Kubernetes Cluster with Deployment

Unnati GuptaUnnati Gupta
3 min read

#90daysofdevopschallenge

#day32

Previous_Blog: https://devunnatig.hashnode.dev/launching-your-first-kubernetes-cluster-with-nginx-running

What is Deployment in k8s?

A Deployment provides a configuration for updates for Pods and ReplicaSets.

You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new replicas for scaling or to remove existing Deployments and adopt all their resources with new Deployments.

Why do we require deployments in Kubernetes?

Let's take a scenario, you have a web application that is already deployed on the production environment, and now you need to make some changes to upgrade your application. so if you upgrade your application one by one that process is called Rolling updates.

Suppose one of the upgrades you are performing resulted in an unexpected error and you want to undo the recent change. You would like to be able to roll back the changes that were recently carried out.

Another Scenario is that you don't want to apply all the changes immediately after the command is run. Instead, you would apply a pause to your environment and make the changes after that resume so that all the changes are rolled out together.

So, all the above scenarios are covered in Kubernetes deployment.

Features Provided By K8S deployment:

a) Versioning and History: Deployments keep a revision history of changes, allowing you to track and manage different versions of your application.

b) Pause and Resume: Deployments can be paused and resumed, allowing you to temporarily halt the deployment process. This can be useful for troubleshooting or making manual adjustments.

c) Pod Template Updates: You can modify the pod template in a Deployment to apply changes to the environment in which your application runs. This includes changes to the container image, environment variables, and other pod specifications.

d) Scaling: Deployments make it easy to scale your application by adjusting the number of replicas. You can scale up to handle increased load or scale down during periods of lower demand.

Kubernetes Deployments Command:

a) Create a Deployment:

kubectl create deployment <deployment-name> --image=<container-image>

b) Get Deployments:

kubectl get deployments

c) Describe a Deployment:

kubectl describe deployment <deployment-name>

d) Update a Deployment (Rolling Update):

kubectl set image deployment/<deployment-name> <container-name>=<new-container-image>

e) Rollback a Deployment:

kubectl rollout undo deployment/<deployment-name>

f) Scale a Deployment:

kubectl scale deployment <deployment-name> --replicas=<new-replica-count>

g) Pause/Resume a Deployment:

kubectl rollout pause deployment/<deployment-name> 
kubectl rollout resume deployment/<deployment-name>

h) Rolling Restart (Force Restart):

kubectl rollout restart deployment/<deployment-name>

i) Delete a Deployment:

kubectl delete deployment <deployment-name>

j) Exposing a Deployment via a Service:

kubectl expose deployment <deployment-name> --type=NodePort --port=<port>

โ„Tasks:

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

By Using Command:

kubectl create deployment todoapp --image=<image-name>
kubectl get deployments
kubectl get pods

By Using yaml file:

Step 1: Create deployment.yaml file.

vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
 name: todoapp
spec:
 replicas: 2
 selector:
   matchLabels:
     app: todo
 template:
   metadata:
     name: todoapp
     labels:
       app: todo
   spec:
    containers:
      - name: todoapp
        image: chanchal8765/django-docker

Step 2: Apply and Verify that deployment is created successfully.

kubectl apply -f deployment.yaml
kubectl get deployments
kubectl get pods

Congratulations! Successfully created your first deployment on Kubernetes Cluster.

In the Next Article, we will go deep down in K8S Namespace.......

Thank you for giving your precious time to read this blog/article and if any suggestions or improvements are required on my blogs feel free to connect on LinkedIn Unnati Gupta. Happy Learning !!!

0
Subscribe to my newsletter

Read articles from Unnati Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Unnati Gupta
Unnati Gupta

๐Ÿ‘จโ€๐Ÿ’ป DevOps Engineer at 6D Technology Passionate about bridging the gap between development and operations, I'm a dedicated DevOps Engineer at 6D Technology. With a strong belief in the power of automation, continuous integration, and continuous delivery, I thrive in optimizing software development pipelines for efficiency and reliability. ๐Ÿš€ Exploring the DevOps Universe In my articles, I delve into the fascinating world of DevOps, where I share insights, best practices, and real-world experiences. From containerization and orchestration to CI/CD pipelines and infrastructure as code, I'm here to demystify the complex and empower fellow developers and ops enthusiasts. ๐Ÿ“ Blogging for Knowledge Sharing As a tech enthusiast and a lifelong learner, I'm committed to sharing knowledge. My articles aim to simplify complex concepts and provide practical tips that help teams and individuals streamline their software delivery processes. ๐ŸŒ Connect with Me Let's connect and explore the ever-evolving landscape of DevOps together. Feel free to reach out, comment, or share your thoughts on my articles. Together, we can foster a culture of collaboration and innovation in the DevOps community. ๐Ÿ”— Social Links LinkedIn: https://www.linkedin.com/in/unnati-gupta-%F0%9F%87%AE%F0%9F%87%B3-a62563183/ GitHub: https://github.com/DevUnnati ๐Ÿ“ฉ Contact Have questions or looking to collaborate? You can reach me at unnatigupta527@gmail.com Happy Learning!!