Skip to content
Related Articles
Open in App
Not now

Related Articles

Kubernetes – Deployments

Improve Article
Save Article
Like Article
  • Last Updated : 30 Mar, 2023
Improve Article
Save Article
Like Article

Pre-requisite: Kubernetes

Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called as container orchestration tool). It is written in Golang and has a huge community because it was first developed by Google and later donated to CNCF (Cloud Native Computing Foundation). Deployment is basically an abstraction layer over pods. It is like a blueprint for creating pods. 

file

 

It mainly consists of 3 components:

  1. metadata: It consists of the name and labels for the configuration file. The labels are used for establishing the connection between deployment and services.
  2. specification: It consists of information regarding the number of replicas, selector labels, and template that is the blueprint for pods. The template itself is like a configuration file for pods and consists of metadata and specification for pods that stores information regarding the containers to be used in the pod, the image to be used for building the container, and the name and ports of the container.
  3. status: This component is automatically generated and added by Kubernetes. This is the basis of the self-healing feature of Kubernetes. If the desired status and actual status of a deployment do not match Kubernetes fixes the pod and matches it with the desired status.

Creating an Nginx web-server deployment in Kubernetes:

In this tutorial, we will be using minikube for using Kubernetes on our local machine. The Deployment configuration file for Nginx will be:

nginx file

 

Now first open the directory where you have created nginx.yaml file in your terminal and create deployment using the command:

$ kubectl apply -f nginx.yaml
kubectl apply

 

Now check the status of your deployment if it is ready or not by running the command

$ kubectl get all
kubectl get command

 

Hence we have successfully deployed created a deployment for Nginx.

Updating Kubernetes Deployment:

To update a Kubernetes deployment we can simply update its config file using 2 methods:

Method 1: Using the kubectl edit command from the terminal

$ kubectl edit deployment deployment-name
edit deployment

 

Now you can edit the deployment configuration by pressing “i” for inserting and after editing it you can just press the escape key and then “:wq” to save your changes and exit.

file

 

Method 2: Updating Configuration Directly

You can open your config file in an IDE like VS Code and edit the config there and apply the config by using the command

$ kubectl apply -f deployment_config.yaml

Let’s say in this case we are updating the container port from 80 to 800.

nginx file

 

 

Benefits of Kubernetes Deployments:

  • Kubernetes Deployment helps in Container Orchestration that is managing the containers in pods.
  • Enhances microservice architecture.
  • Auto-scaling
  • Automated Rollouts and Rollbacks
  • Load Balancing

Use Cases of Kubernetes Deployments:

  • Rollout a ReplicaSet: A Kubernetes deployment generates a replica set a pod that contains information regarding the number of pos to be generated in the background.
  • Declaring a New State of Pods: On updating pod template spec a new replica set is created and deployment moves pods from the old replica set to the new replica set.
  • Scaling: Deployment can be configured to scale up to facilitate more load.
  • Status of Deployment: It can be used to check if the deployment is stuck somewhere by matching the current status with the desired status.
  • Cleaning up old Replica Sets that are no more required.
My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!