Launching your Kubernetes Cluster with Deployment

ยท

2 min read

Launching your Kubernetes Cluster with Deployment

What is Deployment in k8s?

A Deployment in Kubernetes (often referred to as a "K8s Deployment") is a resource object that helps manage the deployment and scaling of containerized applications. It provides a declarative way to ensure that a specified number of identical pods are running and maintained, even when the application needs to be updated, scaled, or rolled back.

In simple terms, a deployment in Kubernetes is like a smart manager for your apps. You tell it how many copies (pods) of your app you want to run, and it makes sure that number is always running, even if some crash. When you update your app, it smoothly replaces the old version with the new one, so users don't notice. It's great for making sure your app stays up and can handle more users if needed.

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

  • add a deployment.yml file

  • apply the deployment to your k8s (minikube) cluster by command kubectl apply -f deployment.yml

Pushing my image into docker hub so that it can be accessed by Kubernetes from anywhere.

Create a new YAML file named deployment.yaml.

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

replicas: Specifies the initial number of replicas. This is the basis for auto-scaling.

selector: This defines the labels used to identify the pods associated with this Deployment.

template: Describes the pod template used for each replica.

Save the file as deployment.yml and execute it by using kubectl apply -f deployment.yml

kubectl apply -f deployment.yml

Let's check auto healing, if we delete any pod it will create a new pod

Now, if we need to delete the deployment we can use the below command.

kubectl delete -f deployment.yml

"Thank you for enjoying my DevOps blog! Your positive response fuels my passion to dive deeper into technology and innovation.

Stay tuned for more captivating DevOps articles, where we'll explore this dynamic field together. Follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/som-shanker-pandey/ for the latest updates and discussions.

Did you find this article valuable?

Support Som Pandey's blog by becoming a sponsor. Any amount is appreciated!

ย