Launching your Kubernetes Cluster with Deployment

Launching your Kubernetes Cluster with Deployment

What is Deployment in Kubernetes?

Deployment is a resource object that manages creating and updating Pods, the basic deployment units in Kubernetes. Deployments provide a declarative way to describe how you want your application to run on a Kubernetes cluster. Deployment means that you don't have to manually manage your Pods' creation, scaling, or updating. Instead, you define the desired state of your application in a Deployment, and the Kubernetes controller will ensure that the actual state of your application matches the desired state.

Some of the benefits of using Deployments in Kubernetes

  • Declarative updates: Deployments provide a declarative way to update your application. You don't have to write complex scripts to update your application. Instead, you define the desired state of your application in a Deployment, and the Kubernetes controller will take care of the rest.

  • Self-healing: Deployments are self-healing. If a Pod crash or is terminated, the Deployment controller will automatically create a new Pod to replace it.

  • Scaling applications: Deployments can be used to scale applications up or down. This can be done in response to changes in traffic or load.

  • Rolling Updates and Rollbacks: Deployments can be used to update existing applications that are running on a Kubernetes cluster. Kubernetes will gradually replace instances of the old version with the new one. If you encounter any problems with the latest version, you can effortlessly roll back to a prior version.

Task: 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
apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-app
  labels:
    app: todo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: todo
  template:
    metadata:
      labels:
        app: todo
    spec:
      containers:
      - name: todo
        image: rishikeshops/todo-app
        ports:
        - containerPort: 3000

Apply the deployment to your minikube cluster by running this command

kubectl apply -f deployment.yml

To get the status of the deployment

kubectl get deployments

To list the Pods created by the deployment

kubectl get pods

To see the self-healing feature of Deployment, let's delete a pod out of the two created pods.

We can see that a new pod was created.

That's it for the Day-32 task. Thank you.