Day 32 Task: Launching your Kubernetes Cluster with Deployment

Gopal GautamGopal Gautam
3 min read

🔹What is Deployment in k8s

In Kubernetes (K8s), a Deployment is a resource object that provides declarative updates to applications. It allows you to describe an application's life cycle, such as which images to use for the app, the number of replicas, and how to update them, in a declarative way. Deployments are part of the Kubernetes "Apps" API group and serve as a higher-level abstraction over pods.

Here are some key characteristics and features of Deployments:

  1. Declarative Configuration: You define the desired state of your application in a Deployment manifest (usually a YAML file) rather than specifying a sequence of commands.

  2. Replica Sets: Deployments manage Replica Sets, which in turn manage the actual pods running your application. This ensures that the desired number of replicas (instances) are always available.

  3. Scaling: You can easily scale your application up or down by changing the number of desired replicas in the Deployment manifest. Kubernetes will automatically adjust the number of pods accordingly.

  4. Rolling Updates: Deployments support rolling updates, which allow you to update your application without downtime. You specify a new version of the app in the manifest, and Kubernetes will incrementally replace the old pods with new ones.

  5. Rollback: If a new version of your application causes issues, you can roll back to a previous version by simply updating the Deployment manifest with the desired image version.

  6. Health Checks: Deployments can perform readiness and liveness checks on pods using probes. This ensures that pods are healthy and ready to serve traffic before being included in the load balancing.

  7. Rolling Restarts: You can perform rolling restarts of your application to apply configuration changes or perform maintenance tasks.

  8. History and Revision Tracking: Deployments maintain a history of all revisions, making it easy to track changes and rollbacks.

🔹Task-1:

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

step1: Create a deploy.yml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-app-deployment
spec:
  replicas: 3  # Number of desired replicas
  selector:
    matchLabels:
      app: todo-app
  template:
    metadata:
      labels:
        app: todo-app
    spec:
      containers:
        - name: todo-app
          image: your-todo-app-image:latest  # Replace with your actual todo-app image
          ports:
            - containerPort: 8000

step2: Create the deployment

kubectl apply -f deploy.yml

step3: To set the CPU utilization target for auto-scaling in a Kubernetes Deployment, you can use the kubectl autoscale command. Here's how you can do it:

kubectl autoscale deployment todo-app-deployment --cpu-percent=50 --min=2 --max=5
kubectl get hpa

This command will enable auto-scaling for your Deployment based on CPU utilization, with the specified parameters.

step4: To update the autoscaling settings, you can run the kubectl autoscale command with the new values, just like you did when initially setting it up. For example:

kubectl edit hpa todo-app-deployment

step5: To remove auto-scaling completely, you can delete the HPA resource associated with your Deployment:

kubectl delete hpa todo-app-deployment
0
Subscribe to my newsletter

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

Written by

Gopal Gautam
Gopal Gautam

Hii I am a backend/DevOps engineer.I have a experience with development and automation.I mostly work with Python, django, Cloud based technologies.