Day32 of #90DaysOfDevOps

Launching your Kubernetes Cluster with Deployment

What is a Deployment in Kubernetes?

In Kubernetes, a Deployment allows you to define a desired state for your pods and ReplicaSets. It’s a higher-level object that helps manage pods by ensuring they’re running correctly and can scale when necessary.

Key benefits of using a deployment:

  • Auto-healing: Automatically replaces failed or unhealthy pods.

  • Auto-scaling: Scales the number of pod replicas up or down based on load or resource usage.

Deployments ensure that your application is always running in the desired state. You can also use deployments for updates, rollbacks, and scaling your application to handle more traffic or users.


Task-01: Create a Kubernetes Deployment

Today’s task is to create a deployment file for a sample todo-app. This deployment will include auto-healing and auto-scaling features, which are essential for running production-grade applications on Kubernetes.

Step 1: Create a Deployment YAML File

We’ll create a deployment file called deployment.yml. This file defines the configuration for your application, including the number of replicas, the container image, and resource limits for scaling.

Here’s a sample deployment file for a todo-app:

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

Step 2: Apply the Deployment

Once you’ve created the deployment.yml file, you can apply it to your Minikube Kubernetes cluster. Here’s the command:

kubectl apply -f deployment.yaml

This command will create the deployment and start running the todo-app with 3 replicas (as specified in the file). The service exposes the application on port 5000 inside the cluster and port 30007 outside the cluster (on your Minikube instance).

  • Step 3: To verify that the deployment is running correctly, use the following command to get the status of the deployment:
kubectl get deployment
  • Step 4: Check the status of the pods created by the deployment using the following command:
kubectl get pods

Conclusion:

Today’s task introduced you to the concept of Kubernetes Deployments, a powerful tool for managing your applications. You also explored auto-healing and auto-scaling, essential features for production-grade applications that ensure reliability and flexibility under varying loads.